Skip to content

Commit

Permalink
[#1032] Combine jump-to-var and jump-to-resource into one function
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGebhart committed Mar 23, 2015
1 parent a3083cb commit af47844
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* [#958](https://github.com/clojure-emacs/cider/pull/958) Reuse existing repl
buffers with dead processes. Users are now informed about existing zombie repl
buffers and are offered the choice to reuse those for new connections.
* [#1032](https://github.com/clojure-emacs/cider/issues/1032) New function jump-to-resource-or-var
combines the functionality of jump-to-var and jump-to-resource.

### Changes

Expand Down
36 changes: 28 additions & 8 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,34 @@ window."
(when pos
(goto-char pos)))))

(defun cider-jump-to-resource-or-var (symbol-file)
"Try to jump to the variable at point.
If variable is not found, try to jump to resource of the same name.
When called interactively, A prompt is given with a default value of
thing at point. If a prefix is given then the result is opened in 'other-window'. "
(interactive
(list (read-string "Jump to: " (thing-at-point 'filename)
nil (thing-at-point 'filename))))
(-if-let (info (if (not (string-match "\\(\\.\\)" symbol-file))
(cider-var-info symbol-file)
nil))
(cider--jump-to-loc-from-info info current-prefix-arg)
(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 current-prefix-arg)
(message "Resource or variable %s not resolved" symbol-file)))))

(defun cider-jump-to-resource-or-var-other-window ()
"jump to var or resource at point, place results in other window."
(interactive)
(let ((current-prefix-arg '(4)))
(call-interactively 'cider-jump-to-resource-or-var)))

(defun cider-jump-to-resource (path)
"Jump to the resource at the resource-relative PATH.
When called interactively, this operates on point."
(interactive (list (thing-at-point 'filename)))
(cider-ensure-op-supported "resource")
(-if-let* ((resource (cider-sync-request:resource path))
(buffer (cider-find-file resource)))
Expand Down Expand Up @@ -793,14 +817,10 @@ OTHER-WINDOW is passed to `cider-jamp-to'."
(cider--jump-to-loc-from-info info))
(message "Symbol %s not resolved" var)))

(defun cider-jump-to-var (&optional var line)
"Jump to the definition of VAR, optionally at a specific LINE.
When called interactively, prompts with symbol at point."
(interactive)
(defun cider-jump-to-var (var line)
"Jump to the definition of VAR, optionally at a specific LINE."
(cider-ensure-op-supported "info")
(if var
(cider--jump-to-var var line)
(cider-read-symbol-name "Symbol: " #'cider--jump-to-var)))
(cider--jump-to-var var line))

(define-obsolete-function-alias 'cider-jump 'cider-jump-to-var "0.7.0")
(defalias 'cider-jump-back 'pop-tag-mark)
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-jump-to-resource-or-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-jump-to-resource-or-var)
(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-jump-to-resource-or-var]
["Jump to resource" cider-jump-to-resource-or-var]
["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-jump-to-resource-or-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-jump-to-resource-or-var)
(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-jump-to-resource-or-var]
["Jump to resource" cider-jump-to-resource-or-var]
["Jump back" cider-jump-back]
["Switch to Clojure buffer" cider-switch-to-last-clojure-buffer]
"--"
Expand Down
2 changes: 1 addition & 1 deletion cider-stacktrace.el
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ it wraps to 0."
(let ((button (button-at (point))))
(if (and button (button-get button 'line))
(cider-stacktrace-navigate button)
(call-interactively 'cider-jump-to-var))))
(call-interactively 'cider-jump-to-resource-or-var))))


;; Rendering
Expand Down
2 changes: 1 addition & 1 deletion cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
(line (get-text-property (point) 'line)))
(if (and ns var)
(cider-jump-to-var (concat ns "/" var) line)
(call-interactively 'cider-jump-to-var))))
(call-interactively 'cider-jump-to-resource-or-var))))


;;; 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-jump-to-resource-or-var}
\key{C-c M-.}{cider-jump-to-resource-or-var}

\subgroup{Evaluation}

Expand Down

0 comments on commit af47844

Please sign in to comment.