Skip to content

Add feature to evaluate list around point #2881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
14 changes: 14 additions & 0 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down