Cider: implement cider-eval-enclosing-form

Created on 7 Sep 2020  Â·  5Comments  Â·  Source: clojure-emacs/cider

Is your feature request related to a problem? Please describe.

I'm often with the cursor inside a form I'd like to evaluate. Typically in rich comments I edit an argument and want to try reevaluating the wrapping form. If it's in the middle of the (comment) block I need to go to the beginning of the next line (evil/vim curse, can't put cursor past last character) and run cider-eval-last-sexp.

Describe the solution you'd like

Ideally I'd want to stay where I am with the cursor and run the parenthesized expression that encloses it. Finding the enclosing paren is done by searching for the first opening paren to the left. The function could be easily enriched by searching for the second highest enclosing paren via universal-argument.

Describe alternatives you've considered

I've looked through all cider-eval-* functions and found none that meet my needs. Maybe I'm just blind though :)

Another option that would cover 80-90% of my use cases would be if cider-eval-defun-at-point would treat (comment) blocks as special and thought of each inner form as a separate toplevel form.

Additional context

feature request good first issue

Most helpful comment

@xificurC did you (setq clojure-toplevel-inside-comment-form t) ?

All 5 comments

Another option that would cover 80-90% of my use cases would be if cider-eval-defun-at-point would treat (comment) blocks as special and thought of each inner form as a separate toplevel form.

I thought @dpsutton already implemented something like this a while ago.

Ideally I'd want to stay where I am with the cursor and run the parenthesized expression that encloses it.

cider-eval-sexp-at-point doesn't work for you?

Let | be the cursor. Then for

(comment (+ 2| 3))

cider-eval-defun-at-point returns nil

cider-eval-sexp-at-point returns 2

I want to evaluate the (+ 2 3) part and get 5 as the result.

@xificurC did you (setq clojure-toplevel-inside-comment-form t) ?

Hi @dakra , no, since I didn't know of that variable. Surprisingly (to me at least) it's in clojure and not cider.

I'd still consider the original suggestion, but I'll play around with this and see it fills my use cases. Thanks!

Surprisingly (to me at least) it's in clojure and not cider.

Because the logic for sexp boundaries lives in clojure-mode.

Was this page helpful?
0 / 5 - 0 ratings