Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Kernel and Kernel.SpecialForms function jump to defintions #82

Merged
merged 2 commits into from
May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

* [Goto] Support jumping to `Kernel` and `Kernel.Specialforms` functions
* [Project] `alchemist-project-open-tests-for-current-file` needs to be an interactive function
and `alchemist--project-open-tests-for-current-file` not (it's a private function)
* [Keybindings] Add customizable keybinding prefix (default: `C-c a`)
Expand Down
28 changes: 27 additions & 1 deletion alchemist-goto.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
(defun alchemist-goto--open-definition (expr)
(let* ((module (alchemist-goto--extract-module expr))
(module (alchemist-goto--get-full-path-of-alias module))
(module (if module module "AlchemistGoto"))
(module (if module module "nil"))
(function (alchemist-goto--extract-function expr))
(function (if function function "\"\""))
(file (alchemist-goto--get-module-source module function)))
Expand Down Expand Up @@ -182,12 +182,26 @@
(defun alchemist-goto--get-module-source-code (module function)
(format "
defmodule Source do

def find(nil, function) do
cond do
List.keymember?(get_module_funs(Kernel), function, 0) ->
IO.puts source(Kernel)
List.keymember?(get_module_funs(Kernel.SpecialForms), function, 0) ->
IO.puts source(Kernel.SpecialForms)
true ->
IO.puts \"\"
end
end

def find(module, function) do
cond do
Code.ensure_loaded?(module) ->
IO.puts source(module)
List.keymember?(Kernel.module_info[:exports], function, 0) ->
IO.puts source(Kernel)
List.keymember?(Kernel.SpecialForms.module_info[:exports], function, 0) ->
IO.puts source(Kernel.SpecialForms)
true ->
IO.puts \"\"
end
Expand All @@ -201,6 +215,18 @@ defmodule Source do
source -> \"source-file-path:\" <> List.to_string(source)
end
end

defp get_module_funs(mod) do
if function_exported?(mod, :__info__, 1) do
if docs = Code.get_docs(mod, :docs) do
for {tuple, _line, _kind, _sign, doc} <- docs, doc != false, do: tuple
else
(mod.__info__(:functions) -- [__info__: 1]) ++ mod.__info__(:macros)
end
else
mod.module_info(:exports)
end
end
end

Source.find(%s, :%s)" module function))
Expand Down