summaryrefslogtreecommitdiff
path: root/cider-interaction.el
diff options
context:
space:
mode:
authorexpez <expez@expez.com>2015-05-01 20:42:11 +0200
committerLars Andersen <expez@expez.com>2015-05-02 12:10:28 +0200
commite64dfdabea2da5effe4f32e713b31c87909c8804 (patch)
treee167cd86476b23be6a19536d784522377d33f652 /cider-interaction.el
parentb6c7cd7a9ecaf2d2446960eac06e521d62157d2e (diff)
[Fix #1061] Add cider-find-ns
Provide a completing read of available namespaces and jump to the file containing its definition.
Diffstat (limited to 'cider-interaction.el')
-rw-r--r--cider-interaction.el27
1 files changed, 26 insertions, 1 deletions
diff --git a/cider-interaction.el b/cider-interaction.el
index b3db1401..b4e92522 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-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,31 @@ thing at point."
#'cider--find-var-other-window
#'cider--find-var))))
+(defun cider-sync-request:ns-path (ns)
+ "Get the path to the file containing NS."
+ (-> (list "op" "ns-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 "Find 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)