cider icon indicating copy to clipboard operation
cider copied to clipboard

Add more commands to cider-eval-dwim

Open samhedin opened this issue 2 years ago • 2 comments

Creating this issue to come up with more ideas for cider-eval-dwim. Right now, it's very close to covering all my eval-needs in one nice command.

Currently, it runs cider-eval-region and cider-eval-defun-at-point depending on whether a region is active. It would be cool if it could run cider-eval-defun-to-comment.

But how to support this intuitively is not clear to me. I considered prefix args, but that's already taken for cider-eval-defun-at-point. Suggestions welcome for both how to add cider-eval-defun-to-comment, and other commands to include.

samhedin avatar Oct 07 '23 07:10 samhedin

You can do this with more complex prefix args, but I guess that won't fit very well the dwim semantics. Perhaps it can detect the presence a comment placeholder after the line in question (e.g. ;; => ).

bbatsov avatar Oct 07 '23 07:10 bbatsov

that won't fit very well the dwim semantics

I agree - it would be very hard/risky to guess that the user possibly wants a "comment" output.

There's nothing wrong to have multiple commands.


An unrelated possible point for expanding "dwim semantics" is guessing what sexpr we want to eval depending on where POINT (|) is:

|()

;; or:

()|
  • If it's at beggining of line, and at the beginning of the top-level sexpr, very likely we want to eval the next sexpr.
  • If it's at the end of line, and at the end of the top-level sexpr, very likely we want to eval the previous sexpr.

Now, say that point is here:

(defn foo []
   ;; here:
  |(+ 3 2))

Do we mean to eval (+ 3 2) or the whole defn?

A reasonable criterion is: if we're in a defn (or deftest, etc), eval the whole defn, if we're in a comment, only eval (+ 3 2).

And perhaps in certain cases, ask the user (completing-read makes this fairly low-friction).

vemv avatar Oct 07 '23 13:10 vemv