Skip to content

Commit

Permalink
Merge pull request #82 from tonini/kernel-function-goto-fix
Browse files Browse the repository at this point in the history
support Kernel and Kernel.SpecialForms function jump to defintions
  • Loading branch information
tonini committed May 28, 2015
2 parents 7b73097 + e5d21a3 commit 3c15d1d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit 3c15d1d

Please sign in to comment.