summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2017-12-19 20:27:19 +0200
committerBozhidar Batsov <bozhidar@batsov.com>2017-12-19 20:27:19 +0200
commit677ec20a6c300e33686526175325dc7dafee7953 (patch)
treed31db023d543633ee3747ec333b19a1440b9b337
parent0eaeaf40e358686011b4502eeca7c4a768d93aa3 (diff)
[Fix #2112] Add a new interactive command cider-find-keyword
It basically finds the first usage of the namespace-qualified keywords. For `::other.namespace/foo` this command would go to `other.namespace` and then find the first mention of `:foo` in it.
-rw-r--r--CHANGELOG.md1
-rw-r--r--cider-interaction.el33
-rw-r--r--cider-mode.el2
-rw-r--r--cider-repl.el3
4 files changed, 39 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a04db2a6..651e9d2c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
* [#2082](https://github.com/clojure-emacs/cider/pull/2082), [cider-nrepl#440](https://github.com/clojure-emacs/cider-nrepl/pull/440): Add specialized stacktraces for clojure.spec assertions.
* [#2111](https://github.com/clojure-emacs/cider/pull/2111): Add `cider-pprint-eval-last-sexp-to-comment` and `cider-pprint-eval-defun-to-comment`.
* Add a REPL shortcut for `cider-repl-require-repl-utils` (this makes it easy to require common functions like `doc`, `source`, etc. in REPL buffers).
+* [#2112](https://github.com/clojure-emacs/cider/issues/2112): Add a new interactive command `cider-find-keyword` (bound to `C-c C-:`).
### Changes
diff --git a/cider-interaction.el b/cider-interaction.el
index 88678348..c8ac4f54 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -504,6 +504,39 @@ the results to be displayed in a different window."
(ns (completing-read "Find namespace: " namespaces)))
(cider--find-ns ns (cider--open-other-window-p arg)))))
+(defun cider-find-keyword (&optional arg)
+ "Find the namespace of the keyword at point and its first occurrence there.
+
+For instance - if the keyword at point is \":cider.demo/keyword\", this command
+would find the namespace \"cider.demo\" and afterwards find the first mention
+of \"::keyword\" there.
+
+Prompt according to prefix ARG and `cider-prompt-for-symbol'.
+A single or double prefix argument inverts the meaning of
+`cider-prompt-for-symbol'. A prefix of `-` or a double prefix argument causes
+the results to be displayed in a different window. The default value is
+thing at point."
+ (interactive "P")
+ (cider-ensure-connected)
+ (let* ((kw (let ((kw-at-point (cider-symbol-at-point 'look-back)))
+ (if (or cider-prompt-for-symbol arg)
+ (read-string
+ (format "Keyword (default %s): " kw-at-point)
+ nil nil kw-at-point)
+ kw-at-point)))
+ (ns-qualifier (and
+ (string-match "^:+\\(.+\\)/.+$" kw)
+ (match-string 1 kw)))
+ (kw-ns (if ns-qualifier
+ (cider-resolve-alias (cider-current-ns) ns-qualifier)
+ (cider-current-ns)))
+ (kw-to-find (concat "::" (replace-regexp-in-string "^:+\\(.+/\\)?" "" kw))))
+
+ (when (and ns-qualifier (string= kw-ns (cider-current-ns)))
+ (error "Could not resolve alias `%s' in `%s'" ns-qualifier (cider-current-ns)))
+ (cider--find-ns kw-ns arg)
+ (search-forward-regexp kw-to-find nil 'noerror)))
+
(defvar cider-completion-last-context nil)
(defun cider-completion-symbol-start-pos ()
diff --git a/cider-mode.el b/cider-mode.el
index b8ec032a..d01970a5 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -269,6 +269,7 @@ Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your b
("Find (jump to)"
["Find definition" cider-find-var]
["Find resource" cider-find-resource]
+ ["Find keyword" cider-find-keyword]
["Go back" cider-pop-back])
("Macroexpand"
["Macroexpand-1" cider-macroexpand-1]
@@ -301,6 +302,7 @@ Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your b
(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 "C-c C-:") #'cider-find-keyword)
(define-key map (kbd "M-,") #'cider-pop-back)
(define-key map (kbd "C-c M-.") #'cider-find-resource)
(define-key map (kbd "M-TAB") #'complete-symbol)
diff --git a/cider-repl.el b/cider-repl.el
index ed8b033a..a2445ffe 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -1431,6 +1431,7 @@ constructs."
(declare-function cider-find-resource "cider-interaction")
(declare-function cider-restart "cider-interaction")
(declare-function cider-find-ns "cider-interaction")
+(declare-function cider-find-keyword "cider-interaction")
(declare-function cider-switch-to-last-clojure-buffer "cider-mode")
(defvar cider-repl-mode-map
@@ -1440,6 +1441,7 @@ constructs."
(define-key map (kbd "C-c C-t") 'cider-test-commands-map)
(define-key map (kbd "M-.") #'cider-find-var)
(define-key map (kbd "C-c C-.") #'cider-find-ns)
+ (define-key map (kbd "C-c C-:") #'cider-find-keyword)
(define-key map (kbd "M-,") #'cider-pop-back)
(define-key map (kbd "C-c M-.") #'cider-find-resource)
(define-key map (kbd "RET") #'cider-repl-return)
@@ -1486,6 +1488,7 @@ constructs."
("Find"
["Find definition" cider-find-var]
["Find resource" cider-find-resource]
+ ["Find keyword" cider-find-keyword]
["Go back" cider-pop-back])
"--"
["Switch to Clojure buffer" cider-switch-to-last-clojure-buffer]