From 4ba4608b941efd071abdcc5fb1fd8e0b26f7d8b9 Mon Sep 17 00:00:00 2001 From: expez Date: Fri, 1 May 2015 20:42:11 +0200 Subject: [PATCH] [Fix #1061] Add cider-find-ns Provide a completing read of available namespaces and jump to the file containing its definition. --- CHANGELOG.md | 1 + cider-interaction.el | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f83d6fdb3..1b1849582 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New features +* [#1061](https://github.com/clojure-emacs/cider/issues/1061) New command `cider-find-ns` which prompts for an ns and jumps to the corresponding source file. * [#1019](https://github.com/clojure-emacs/cider/pull/1019): New file, cider-debug.el. Provides a new command, `cider-debug-defun-at-point`, bound to C-u C-M-x. Interactively debug top-level clojure forms. diff --git a/cider-interaction.el b/cider-interaction.el index b3db14017..b02b1fb76 100644 --- a/cider-interaction.el +++ b/cider-interaction.el @@ -214,7 +214,7 @@ if the candidate is not namespace-qualified." (defvar cider-required-nrepl-ops '("apropos" "classpath" "complete" "eldoc" "format-code" "format-edn" "info" "inspect-pop" "inspect-push" "inspect-refresh" - "macroexpand" "ns-list" "ns-vars" "refresh" + "macroexpand" "ns-list" "ns-vars" "ns-to-path" "refresh" "resource" "stacktrace" "toggle-trace-var" "toggle-trace-ns" "undef") "A list of nREPL ops required by CIDER to function properly. @@ -924,6 +924,32 @@ thing at point." #'cider--find-var-other-window #'cider--find-var)))) +(defun cider-sync-request:ns-path (ns) + "Toggle namespace tracing for NS." + (cider-ensure-op-supported "ns-path") + (-> (list "op" "ns-to-path" + "ns" ns) + nrepl-send-sync-request + (nrepl-dict-get "path"))) + +(defun cider--find-ns (ns &optional other-window) + (-if-let (path (cider-sync-request:ns-path ns)) + (cider-jump-to (cider-find-file path) nil other-window) + (error "Can't find %s" ns))) + +(defun cider-find-ns (&optional arg ns) + "Find the file containing NS. + +A prefix of `-` or a double prefix argument causes +the results to be displayed in a different window." + (interactive "P") + (cider-ensure-op-supported "ns-path") + (if ns + (cider--find-ns ns) + (let* ((namespaces (cider-sync-request:ns-list)) + (ns (completing-read "Namespace: " namespaces))) + (cider--find-ns ns (cider--open-other-window-p arg))))) + (define-obsolete-function-alias 'cider-jump-to-resource 'cider-find-resource "0.9.0") (define-obsolete-function-alias 'cider-jump-to-var 'cider-find-var "0.9.0") (defalias 'cider-jump-back 'pop-tag-mark)