Skip to content

Commit 87506dc

Browse files
malltbbatsov
authored andcommitted
[Fix #1646] Add option to control apropos actions (#1791)
1 parent d005eaa commit 87506dc

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [#1572](https://github.com/clojure-emacs/cider/issues/1572): Add support for variables in eldoc.
2222
* [#1736](https://github.com/clojure-emacs/cider/issues/1736): Show "See Also" links for functions/variables in documentation buffers.
2323
* [#1767](https://github.com/clojure-emacs/cider/issues/1767): Add a command `cider-read-and-eval-defun-at-point` to insert the defun at point into the minibuffer for evaluation (bound to `C-c C-v .`).
24+
* [#1646](https://github.com/clojure-emacs/cider/issues/1646): Add an option `cider-apropos-actions` to control the list of actions to be applied on the symbol found by an apropos search.
2425

2526
### Changes
2627

cider-apropos.el

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141

4242
(push cider-apropos-buffer cider-ancillary-buffers)
4343

44+
(defcustom cider-apropos-actions '(("display-doc" . cider-doc-lookup)
45+
("find-def" . cider--find-var)
46+
("lookup-on-grimoire" . cider-grimoire-lookup))
47+
"Controls the actions to be applied on the symbol found by an apropos search.
48+
The first action key in the list will be selected as default. If the list
49+
contains only one action key, the associated action function will be
50+
applied automatically. An action function can be any function that receives
51+
the symbol found by the apropos search as argument."
52+
:type '(alist :key-type string :value-type function)
53+
:group 'cider)
54+
4455
(defun cider-apropos-doc (button)
4556
"Display documentation for the symbol represented at BUTTON."
4657
(cider-doc-lookup (button-get button 'apropos-symbol)))
@@ -139,17 +150,15 @@ optionally search doc strings (based on DOCS-P), include private vars
139150

140151
(defun cider-apropos-act-on-symbol (symbol)
141152
"Apply selected action on SYMBOL."
142-
(let ((action (completing-read (format "Choose action to apply to `%s`: " symbol)
143-
'("display-doc"
144-
"find-def"
145-
"lookup-on-grimoire"
146-
"quit"))))
147-
(pcase action
148-
("display-doc" (cider-doc-lookup symbol))
149-
("find-def" (cider--find-var symbol))
150-
("lookup-on-grimoire" (cider-grimoire-lookup symbol))
151-
("quit" nil)
152-
(_ (user-error "Unknown action `%s`" action)))))
153+
(let* ((first-action-key (car (car cider-apropos-actions)))
154+
(action-key (if (= 1 (length cider-apropos-actions))
155+
first-action-key
156+
(completing-read (format "Choose action to apply to `%s`: " symbol)
157+
cider-apropos-actions nil nil nil nil first-action-key)))
158+
(action-fn (cdr (assoc action-key cider-apropos-actions))))
159+
(if action-fn
160+
(funcall action-fn symbol)
161+
(user-error "Unknown action `%s`" action-key))))
153162

154163
;;;###autoload
155164
(defun cider-apropos-select (query &optional ns docs-p privates-p case-sensitive-p)

0 commit comments

Comments
 (0)