diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb0a5c37..c9221eb81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Add support for nREPL 0.8's `lookup` op. * Add support for nREPL 0.7's sideloading functionality (experimental). * Add support for nREPL 0.8's `ls-middleware` op. +* Add feature to evaluate list around point. * [#2861](https://github.com/clojure-emacs/cider/pull/2861): Add support for the Krell REPL. ### Changes diff --git a/cider-eval.el b/cider-eval.el index 99497aebd..e936eb134 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -806,6 +806,16 @@ buffer." nil (cider--nrepl-pr-request-map)))) +(defun cider-eval-list-at-point (&optional output-to-current-buffer) + "Evaluate the list (eg. a function call, surrounded by parens) around point. +If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer. +Special cases such as deref-ing a function call's results is also executed, +like in @(fn-that-returns-an-atom x)" + (interactive "P") + (save-excursion + (goto-char (cadr (cider-list-at-point 'bounds))) + (cider-eval-last-sexp output-to-current-buffer))) + (defun cider-eval-sexp-at-point (&optional output-to-current-buffer) "Evaluate the expression around point. If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer." diff --git a/cider-util.el b/cider-util.el index e4d71be1f..b2387c305 100644 --- a/cider-util.el +++ b/cider-util.el @@ -170,6 +170,20 @@ instead." (funcall (if bounds #'list #'buffer-substring-no-properties) (car b) (cdr b)))) +(defun cider-list-at-point (&optional bounds) + "Return the list (compound form) at point as a string, otherwise nil. +If BOUNDS is non-nil, return a list of its starting and ending position +instead." + (when-let* ((b (or (and (equal (char-after) ?\() + (member (char-before) '(?\' ?\, ?\@)) + ;; hide stuff before ( to avoid quirks with '( etc. + (save-restriction + (narrow-to-region (point) (point-max)) + (bounds-of-thing-at-point 'list))) + (bounds-of-thing-at-point 'list)))) + (funcall (if bounds #'list #'buffer-substring-no-properties) + (car b) (cdr b)))) + (defun cider-last-sexp (&optional bounds) "Return the sexp preceding the point. If BOUNDS is non-nil, return a list of its starting and ending position