From ada3d708cba44f5689aada960b19bf806a628dba Mon Sep 17 00:00:00 2001 From: Samuel Tonini Date: Thu, 28 May 2015 09:54:47 +0200 Subject: [PATCH 1/2] support Kernel and Kernel.SpecialForms function jump to defintions --- alchemist-goto.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/alchemist-goto.el b/alchemist-goto.el index 84522116..e84400fd 100644 --- a/alchemist-goto.el +++ b/alchemist-goto.el @@ -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))) @@ -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 @@ -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)) From e5d21a3ec7329c0dfbe3f9010db8e976c56e5433 Mon Sep 17 00:00:00 2001 From: Samuel Tonini Date: Thu, 28 May 2015 09:59:45 +0200 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 977696ac..1ad95d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`)