Skip to content

Commit f980344

Browse files
malltbbatsov
authored andcommitted
[Fix #1767] Read and eval defun at point (#1774)
1 parent af2ec9c commit f980344

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [#1725](https://github.com/clojure-emacs/cider/issues/1725): Display class names in eldoc for interop forms.
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.
23+
* [#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 .`).
2324

2425
### Changes
2526

cider-interaction.el

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,11 @@ otherwise it's evaluated interactively."
12231223
(cider-nrepl-sync-request:eval (cider-defun-at-point)))
12241224
(cider-eval-defun-at-point)))))
12251225

1226-
(defun cider-read-and-eval ()
1227-
"Read a sexp from the minibuffer and output its result to the echo area."
1226+
(defun cider-read-and-eval (&optional value)
1227+
"Read a sexp from the minibuffer and output its result to the echo area.
1228+
If VALUE is non-nil, it is inserted into the minibuffer as initial input."
12281229
(interactive)
1229-
(let* ((form (cider-read-from-minibuffer "Clojure Eval: "))
1230+
(let* ((form (cider-read-from-minibuffer "Clojure Eval: " value))
12301231
(override cider-interactive-eval-override)
12311232
(ns-form (if (cider-ns-form-p form) "" (format "(ns %s)" (cider-current-ns)))))
12321233
(with-current-buffer (get-buffer-create cider-read-eval-buffer)
@@ -1238,6 +1239,15 @@ otherwise it's evaluated interactively."
12381239
(let ((cider-interactive-eval-override override))
12391240
(cider-interactive-eval form)))))
12401241

1242+
(defun cider-read-and-eval-defun-at-point ()
1243+
"Insert the toplevel form at point in the minibuffer and output its result.
1244+
The point is placed next to the function name in the minibuffer to allow
1245+
passing arguments."
1246+
(interactive)
1247+
(let* ((fn-name (cadr (split-string (cider-defun-at-point))))
1248+
(form (concat "(" fn-name ")")))
1249+
(cider-read-and-eval (cons form (length form)))))
1250+
12411251

12421252
;; Connection and REPL
12431253

cider-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
291291
(define-key map (kbd "C-c C-v r") #'cider-eval-region)
292292
(define-key map (kbd "C-c C-v n") #'cider-eval-ns-form)
293293
(define-key map (kbd "C-c C-v v") #'cider-eval-sexp-at-point)
294+
(define-key map (kbd "C-c C-v .") #'cider-read-and-eval-defun-at-point)
294295
(define-key map (kbd "C-c M-;") #'cider-eval-defun-to-comment)
295296
(define-key map (kbd "C-c M-e") #'cider-eval-last-sexp-to-repl)
296297
(define-key map (kbd "C-c M-p") #'cider-insert-last-sexp-in-repl)

doc/miscellaneous_features.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ something.
77

88
You can evaluate Clojure code in the minibuffer from pretty much everywhere by
99
using <kbd>M-x</kbd> `cider-read-and-eval` (bound in `cider-mode` buffers to
10-
<kbd>C-c C-:</kbd>). <kbd>TAB</kbd> completion will work in the minibuffer,
10+
<kbd>C-c M-:</kbd>). <kbd>TAB</kbd> completion will work in the minibuffer,
1111
just as in a REPL/source buffer.
1212

13+
Pressing <kbd>C-c C-v .</kbd> in a Clojure buffer will insert the defun
14+
at point into the minibuffer for evaluation. This way you can pass arguments
15+
to the function and evaluate it and see the result in the minibuffer.
16+
1317
You can also enable `eldoc-mode` in the minibuffer by adding the following to your
1418
config:
1519

0 commit comments

Comments
 (0)