Skip to content

Commit 52945c2

Browse files
gveresbbatsov
andauthored
Add a command to evaluate list around point (#2881)
Co-authored-by: Bozhidar Batsov <[email protected]>
1 parent 2ba3e1c commit 52945c2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Add support for nREPL 0.8's `lookup` op.
99
* Add support for nREPL 0.7's sideloading functionality (experimental).
1010
* Add support for nREPL 0.8's `ls-middleware` op.
11+
* Add feature to evaluate list around point.
1112
* [#2861](https://github.com/clojure-emacs/cider/pull/2861): Add support for the Krell REPL.
1213

1314
### Changes

cider-eval.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,16 @@ buffer."
806806
nil
807807
(cider--nrepl-pr-request-map))))
808808

809+
(defun cider-eval-list-at-point (&optional output-to-current-buffer)
810+
"Evaluate the list (eg. a function call, surrounded by parens) around point.
811+
If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer.
812+
Special cases such as deref-ing a function call's results is also executed,
813+
like in @(fn-that-returns-an-atom x)"
814+
(interactive "P")
815+
(save-excursion
816+
(goto-char (cadr (cider-list-at-point 'bounds)))
817+
(cider-eval-last-sexp output-to-current-buffer)))
818+
809819
(defun cider-eval-sexp-at-point (&optional output-to-current-buffer)
810820
"Evaluate the expression around point.
811821
If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer."

cider-util.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ instead."
170170
(funcall (if bounds #'list #'buffer-substring-no-properties)
171171
(car b) (cdr b))))
172172

173+
(defun cider-list-at-point (&optional bounds)
174+
"Return the list (compound form) at point as a string, otherwise nil.
175+
If BOUNDS is non-nil, return a list of its starting and ending position
176+
instead."
177+
(when-let* ((b (or (and (equal (char-after) ?\()
178+
(member (char-before) '(?\' ?\, ?\@))
179+
;; hide stuff before ( to avoid quirks with '( etc.
180+
(save-restriction
181+
(narrow-to-region (point) (point-max))
182+
(bounds-of-thing-at-point 'list)))
183+
(bounds-of-thing-at-point 'list))))
184+
(funcall (if bounds #'list #'buffer-substring-no-properties)
185+
(car b) (cdr b))))
186+
173187
(defun cider-last-sexp (&optional bounds)
174188
"Return the sexp preceding the point.
175189
If BOUNDS is non-nil, return a list of its starting and ending position

0 commit comments

Comments
 (0)