Skip to content

Commit

Permalink
Merge pull request #1093 from clojure-emacs/cider-find-ns
Browse files Browse the repository at this point in the history
[Fix #1061] Add cider-find-ns
  • Loading branch information
bbatsov committed May 2, 2015
2 parents b6c7cd7 + e64dfda commit c520772
Show file tree
Hide file tree
Showing 5 changed files with 31 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`, bound to <kbd>c-c c-.</kbd>, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ Keyboard shortcut | Description
<kbd>C-c C-t</kbd> | Show the test report buffer.
<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.
<kbd>C-c M-.</kbd> | Jump to the resource referenced by the string at point.
<kbd>C-c C-.</kbd> | Jump to some namespace on the classpath.
<kbd>M-,</kbd> | Return to your pre-jump location.
<kbd>M-TAB</kbd> | Complete the symbol at point.
<kbd>C-c C-d g</kbd> | Lookup symbol in Grimoire.
Expand Down Expand Up @@ -793,6 +794,7 @@ Keyboard shortcut | Description
<kbd>C-c C-z</kbd> | Switch to the previous Clojure buffer. This complements <kbd>C-c C-z</kbd> used in cider-mode.
<kbd>C-c M-i</kbd> | Inspect expression. Will act on expression at point if present.
<kbd>C-c M-n</kbd> | Select a namespace and switch to it.
<kbd>C-c C-.</kbd> | Jump to some namespace on the classpath.
<kbd>C-c M-t v</kbd> | Toggle var tracing.
<kbd>C-c M-t n</kbd> | Toggle namespace tracing.

Expand Down
27 changes: 26 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-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,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)
Expand Down
1 change: 1 addition & 0 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ entirely."
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-d") #'cider-doc-map)
(define-key map (kbd "M-.") #'cider-find-var)
(define-key map (kbd "C-c C-.") #'cider-find-ns)
(define-key map (kbd "M-,") #'cider-jump-back)
(define-key map (kbd "C-c M-.") #'cider-find-resource)
(define-key map (kbd "M-TAB") #'complete-symbol)
Expand Down
1 change: 1 addition & 0 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ constructs."
(set-keymap-parent map clojure-mode-map)
(define-key map (kbd "C-c C-d") 'cider-doc-map)
(define-key map (kbd "M-.") 'cider-find-var)
(define-key map (kbd "C-c C-.") #'cider-find-ns)
(define-key map (kbd "M-,") 'cider-jump-back)
(define-key map (kbd "C-c M-.") 'cider-find-resource)
(define-key map (kbd "RET") 'cider-repl-return)
Expand Down

0 comments on commit c520772

Please sign in to comment.