Skip to content

Commit

Permalink
[Fix #1061] Add cider-find-ns
Browse files Browse the repository at this point in the history
Provide a completing read of available namespaces and jump to the file
containing its definition.
  • Loading branch information
expez committed May 2, 2015
1 parent b6c7cd7 commit 4ba4608
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 @@

### 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 <kbd>C-u C-M-x</kbd>.
Interactively debug top-level clojure forms.
Expand Down
28 changes: 27 additions & 1 deletion cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4ba4608

Please sign in to comment.