Skip to content

Commit e64dfda

Browse files
committed
[Fix #1061] Add cider-find-ns
Provide a completing read of available namespaces and jump to the file containing its definition.
1 parent b6c7cd7 commit e64dfda

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features
66

7+
* [#1061](https://github.com/clojure-emacs/cider/issues/1061) New command `cider-find-ns`, bound to <kbd>c-c c-.</kbd>, which prompts for an ns and jumps to the corresponding source file.
78
* [#1019](https://github.com/clojure-emacs/cider/pull/1019): New file, cider-debug.el.
89
Provides a new command, `cider-debug-defun-at-point`, bound to <kbd>C-u C-M-x</kbd>.
910
Interactively debug top-level clojure forms.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ Keyboard shortcut | Description
763763
<kbd>C-c C-t</kbd> | Show the test report buffer.
764764
<kbd>M-.</kbd> | Jump to the definition of a symbol. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
765765
<kbd>C-c M-.</kbd> | Jump to the resource referenced by the string at point.
766+
<kbd>C-c C-.</kbd> | Jump to some namespace on the classpath.
766767
<kbd>M-,</kbd> | Return to your pre-jump location.
767768
<kbd>M-TAB</kbd> | Complete the symbol at point.
768769
<kbd>C-c C-d g</kbd> | Lookup symbol in Grimoire.
@@ -793,6 +794,7 @@ Keyboard shortcut | Description
793794
<kbd>C-c C-z</kbd> | Switch to the previous Clojure buffer. This complements <kbd>C-c C-z</kbd> used in cider-mode.
794795
<kbd>C-c M-i</kbd> | Inspect expression. Will act on expression at point if present.
795796
<kbd>C-c M-n</kbd> | Select a namespace and switch to it.
797+
<kbd>C-c C-.</kbd> | Jump to some namespace on the classpath.
796798
<kbd>C-c M-t v</kbd> | Toggle var tracing.
797799
<kbd>C-c M-t n</kbd> | Toggle namespace tracing.
798800

cider-interaction.el

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ if the candidate is not namespace-qualified."
214214
(defvar cider-required-nrepl-ops
215215
'("apropos" "classpath" "complete" "eldoc" "format-code" "format-edn" "info"
216216
"inspect-pop" "inspect-push" "inspect-refresh"
217-
"macroexpand" "ns-list" "ns-vars" "refresh"
217+
"macroexpand" "ns-list" "ns-vars" "ns-path" "refresh"
218218
"resource" "stacktrace" "toggle-trace-var" "toggle-trace-ns" "undef")
219219
"A list of nREPL ops required by CIDER to function properly.
220220
@@ -924,6 +924,31 @@ thing at point."
924924
#'cider--find-var-other-window
925925
#'cider--find-var))))
926926

927+
(defun cider-sync-request:ns-path (ns)
928+
"Get the path to the file containing NS."
929+
(-> (list "op" "ns-path"
930+
"ns" ns)
931+
nrepl-send-sync-request
932+
(nrepl-dict-get "path")))
933+
934+
(defun cider--find-ns (ns &optional other-window)
935+
(-if-let (path (cider-sync-request:ns-path ns))
936+
(cider-jump-to (cider-find-file path) nil other-window)
937+
(error "Can't find %s" ns)))
938+
939+
(defun cider-find-ns (&optional arg ns)
940+
"Find the file containing NS.
941+
942+
A prefix of `-` or a double prefix argument causes
943+
the results to be displayed in a different window."
944+
(interactive "P")
945+
(cider-ensure-op-supported "ns-path")
946+
(if ns
947+
(cider--find-ns ns)
948+
(let* ((namespaces (cider-sync-request:ns-list))
949+
(ns (completing-read "Find namespace: " namespaces)))
950+
(cider--find-ns ns (cider--open-other-window-p arg)))))
951+
927952
(define-obsolete-function-alias 'cider-jump-to-resource 'cider-find-resource "0.9.0")
928953
(define-obsolete-function-alias 'cider-jump-to-var 'cider-find-var "0.9.0")
929954
(defalias 'cider-jump-back 'pop-tag-mark)

cider-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ entirely."
5555
(let ((map (make-sparse-keymap)))
5656
(define-key map (kbd "C-c C-d") #'cider-doc-map)
5757
(define-key map (kbd "M-.") #'cider-find-var)
58+
(define-key map (kbd "C-c C-.") #'cider-find-ns)
5859
(define-key map (kbd "M-,") #'cider-jump-back)
5960
(define-key map (kbd "C-c M-.") #'cider-find-resource)
6061
(define-key map (kbd "M-TAB") #'complete-symbol)

cider-repl.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ constructs."
10031003
(set-keymap-parent map clojure-mode-map)
10041004
(define-key map (kbd "C-c C-d") 'cider-doc-map)
10051005
(define-key map (kbd "M-.") 'cider-find-var)
1006+
(define-key map (kbd "C-c C-.") #'cider-find-ns)
10061007
(define-key map (kbd "M-,") 'cider-jump-back)
10071008
(define-key map (kbd "C-c M-.") 'cider-find-resource)
10081009
(define-key map (kbd "RET") 'cider-repl-return)

0 commit comments

Comments
 (0)