From af47844846183870abf8a23a7126c9c19adbde7f Mon Sep 17 00:00:00 2001 From: EricGebhart Date: Fri, 20 Mar 2015 12:27:32 -0400 Subject: [PATCH] [#1032] Combine jump-to-var and jump-to-resource into one function --- CHANGELOG.md | 2 ++ cider-interaction.el | 36 ++++++++++++++++++++++++++++-------- cider-mode.el | 8 ++++---- cider-repl.el | 8 ++++---- cider-stacktrace.el | 2 +- cider-test.el | 2 +- doc/cider-refcard.tex | 4 ++-- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237a9fa32..06b646789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cider-interaction.el b/cider-interaction.el index b9f7099ad..af4d71a50 100644 --- a/cider-interaction.el +++ b/cider-interaction.el @@ -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))) @@ -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) diff --git a/cider-mode.el b/cider-mode.el index 7e68c2c45..c8824159e 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -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) @@ -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] diff --git a/cider-repl.el b/cider-repl.el index 6a8c2a528..8687a8def 100644 --- a/cider-repl.el +++ b/cider-repl.el @@ -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-") 'cider-repl-closing-return) @@ -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] "--" diff --git a/cider-stacktrace.el b/cider-stacktrace.el index 513a43802..fa14d6313 100644 --- a/cider-stacktrace.el +++ b/cider-stacktrace.el @@ -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 diff --git a/cider-test.el b/cider-test.el index 6ce527fee..dc935425a 100644 --- a/cider-test.el +++ b/cider-test.el @@ -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 diff --git a/doc/cider-refcard.tex b/doc/cider-refcard.tex index f4db14588..49edd9000 100644 --- a/doc/cider-refcard.tex +++ b/doc/cider-refcard.tex @@ -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}