Skip to content

Commit

Permalink
Merge pull request #1036 from EricGebhart/jump-to
Browse files Browse the repository at this point in the history
[#1032] Combine jump-to-var and jump-to-resource into one function.
  • Loading branch information
bbatsov committed Apr 2, 2015
2 parents 1255837 + 5528f1e commit ceb2d7d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 23 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
* New defcustom, `cider-prompt-for-symbol`. Controls whether to prompt for
symbol when interactive commands require one. Defaults to t, which always
prompts. Currently applies to all documentation and source lookup commands.
* [#1032](https://github.com/clojure-emacs/cider/issues/1032) New functions, `cider-find-dwim` and
`cider-find-dwim-other-window`. These functions combine the functionality of `cider-jump-to-var` and
`cider-jump-to-resource`. Which are now renamed to `cider-find-var` and `cider-find-resource` respectively.


### Changes

Expand All @@ -51,7 +55,7 @@
* [#953](https://github.com/clojure-emacs/cider/pull/953) Use `sshx` instead of `ssh` in `cider-select-endpoint`
* [#956](https://github.com/clojure-emacs/cider/pull/956) Eval full ns form only when needed.
* Enable annotated completion candidates by default.
* [#1031] (https://github.com/clojure-emacs/cider/pull/1031) Interactive functions prompt with
* [#1031](https://github.com/clojure-emacs/cider/pull/1031) Interactive functions prompt with
symbol at point as a default value.

### Bugs fixed
Expand Down
46 changes: 42 additions & 4 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,44 @@ window."
(when pos
(goto-char pos)))))

(defun cider-jump-to-resource (path)
(defun cider-find-dwim-other-window (symbol-file)
"Jump to SYMBOL-FILE at point, place results in other window."
(interactive (cider--find-dwim-interactive "Jump to: "))
(cider--find-dwim symbol-file 'cider-find-dwim-other-window t))

(defun cider-find-dwim (symbol-file)
"Try to jump to the SYMBOL-FILE at point. If thing at point is empty dired
on project. If var is not found, try to jump to resource of the same name.
When called interactively, A prompt is given according to the variable
cider-prompt-for-symbol. A prefix inverts the meaning. A default value of
thing at point is given when prompted."
(interactive (cider--find-dwim-interactive "Jump to: "))
(cider--find-dwim symbol-file 'cider-find-dwim))

(defun cider--find-dwim (symbol-file callback &optional other-window)
"Try to jump to the SYMBOL-FILE at point, show results in OTHER-WINDOW as indicated.
CALLBACK upon failure to invoke prompt if not prompted previously.
If thing at point is empty dired on project."
(-if-let (info (cider-var-info symbol-file))
(cider--jump-to-loc-from-info info other-window)
(progn
(cider-ensure-op-supported "resource")
(-if-let* ((resource (cider-sync-request:resource symbol-file))
(buffer (cider-find-file resource)))
(cider-jump-to buffer 0 other-window)
(if (cider--should-prompt-for-symbol current-prefix-arg)
(error "Resource or var %s not resolved" symbol-file)
(let ((current-prefix-arg (if current-prefix-arg nil '(4))))
(call-interactively callback)))))))

(defun cider--find-dwim-interactive (prompt)
"Get interactive arguments for jump-to functions using PROMPT as needed."
(if (cider--should-prompt-for-symbol current-prefix-arg)
(list
(cider-read-from-minibuffer prompt (thing-at-point 'filename)))
(list (or (thing-at-point 'filename) "")))) ; No prompt.

(defun cider-find-resource (path)
"Jump to the resource at the resource-relative PATH.
When called interactively, this operates on point."
(interactive (list (thing-at-point 'filename)))
Expand All @@ -798,17 +835,16 @@ OTHER-WINDOW is passed to `cider-jamp-to'."
(cider-jump-to buffer (cons line nil) other-window)
(error "No source location"))))

(defun cider--jump-to-var (var &optional line)
(defun cider--find-var (var &optional line)
"Jump to the definition of VAR, optionally at a specific LINE."
(-if-let (info (cider-var-info var))
(progn
(if line (setq info (nrepl-dict-put info "line" line)))
(cider--jump-to-loc-from-info info))
(error "Symbol %s not resolved" var)))

(defun cider-jump-to-var (&optional arg var line)
(defun cider-find-var (&optional arg var line)
"Jump to the definition of VAR, optionally at a specific LINE.
Prompts for the symbol to use, or uses the symbol at point, depending on
the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
opposite of what that option dictates."
Expand All @@ -820,6 +856,8 @@ opposite of what that option dictates."
"Symbol: "
#'cider--jump-to-var)))

(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")
(define-obsolete-function-alias 'cider-jump 'cider-jump-to-var "0.7.0")
(defalias 'cider-jump-back 'pop-tag-mark)

Expand Down
4 changes: 2 additions & 2 deletions cider-macroexpansion.el
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ and point is placed after the expanded form."
(define-key map (kbd "q") 'cider-popup-buffer-quit-function)
(define-key map (kbd "d") 'cider-doc)
(define-key map (kbd "j") 'cider-javadoc)
(define-key map (kbd ".") 'cider-jump-to-var)
(define-key map (kbd ".") 'cider-find-var)
(easy-menu-define cider-macroexpansion-mode-menu map
"Menu for CIDER's doc mode"
'("Macroexpansion"
["Restart expansion" cider-macroexpand-again]
["Macroexpand-1" cider-macroexpand-1-inplace]
["Macroexpand-all" cider-macroexpand-all-inplace]
["Go to source" cider-jump-to-var]
["Go to source" cider-find-var]
["Go to doc" cider-doc]
["Go to Javadoc" cider-docview-javadoc]
["Quit" cider-popup-buffer-quit-function]))
Expand Down
8 changes: 4 additions & 4 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ entirely."
(defvar cider-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-d") #'cider-doc-map)
(define-key map (kbd "M-.") #'cider-jump-to-var)
(define-key map (kbd "M-.") #'cider-find-var)
(define-key map (kbd "M-,") #'cider-jump-back)
(define-key map (kbd "C-c M-.") #'cider-jump-to-resource)
(define-key map (kbd "C-c M-.") #'cider-find-resource)
(define-key map (kbd "M-TAB") #'complete-symbol)
(define-key map (kbd "C-M-x") #'cider-eval-defun-at-point)
(define-key map (kbd "C-c C-c") #'cider-eval-defun-at-point)
Expand Down Expand Up @@ -113,8 +113,8 @@ entirely."
["Macroexpand-1" cider-macroexpand-1]
["Macroexpand-all" cider-macroexpand-all]
"--"
["Jump to source" cider-jump-to-var]
["Jump to resource" cider-jump-to-resource]
["Jump to source" cider-find-var]
["Jump to resource" cider-find-resource]
["Jump back" cider-jump-back]
"--"
["Run test" cider-test-run-test]
Expand Down
8 changes: 4 additions & 4 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,9 @@ constructs."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map clojure-mode-map)
(define-key map (kbd "C-c C-d") 'cider-doc-map)
(define-key map (kbd "M-.") 'cider-jump-to-var)
(define-key map (kbd "M-.") 'cider-find-var)
(define-key map (kbd "M-,") 'cider-jump-back)
(define-key map (kbd "C-c M-.") 'cider-jump-to-resource)
(define-key map (kbd "C-c M-.") 'cider-find-resource)
(define-key map (kbd "RET") 'cider-repl-return)
(define-key map (kbd "TAB") 'cider-repl-tab)
(define-key map (kbd "C-<return>") 'cider-repl-closing-return)
Expand Down Expand Up @@ -1045,8 +1045,8 @@ constructs."
"--"
,cider-doc-menu
"--"
["Jump to source" cider-jump-to-var]
["Jump to resource" cider-jump-to-resource]
["Jump to source" cider-find-var]
["Jump to resource" cider-find-resource]
["Jump back" cider-jump-back]
["Switch to Clojure buffer" cider-switch-to-last-clojure-buffer]
"--"
Expand Down
4 changes: 2 additions & 2 deletions cider-stacktrace.el
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ it wraps to 0."
(cider--jump-to-loc-from-info info t)))

(defun cider-stacktrace-jump (&optional arg)
"Like `cider-jump-to-var', but uses the stack frame source at point, if available."
"Like `cider-find-var', but uses the stack frame source at point, if available."
(interactive "P")
(let ((button (button-at (point))))
(if (and button (button-get button 'line))
(cider-stacktrace-navigate button)
(cider-jump-to-var arg))))
(cider-find-var arg))))


;; Rendering
Expand Down
7 changes: 3 additions & 4 deletions cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,14 @@
(goto-char pos))))

(defun cider-test-jump (&optional arg)
"Like `cider-jump-to-var', but uses the test at point's definition, if available."
"Like `cider-find-var', but uses the test at point's definition, if available."
(interactive "P")
(let ((ns (get-text-property (point) 'ns))
(var (get-text-property (point) 'var))
(line (get-text-property (point) 'line)))
(if (and ns var)
(cider-jump-to-var arg (concat ns "/" var) line)
(cider-jump-to-var arg))))

(cider-find-var arg (concat ns "/" var) line)
(cider-find-var arg))))

;;; Error stacktraces

Expand Down
4 changes: 2 additions & 2 deletions doc/cider-refcard.tex
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
\subgroup{Navigation}

\key{M-,}{cider-jump-back}
\key{M-.}{cider-jump-to-var}
\key{C-c M-.}{cider-jump-to-resource}
\key{M-.}{cider-find-var}
\key{C-c M-.}{cider-find-resource}

\subgroup{Evaluation}

Expand Down

0 comments on commit ceb2d7d

Please sign in to comment.