Fork me on GitHub
#cider
<
2024-04-20
>
yuhan19:04:29

Thoughts on extending Cider's defun-at-point to include unwrapped top-level expressions? I often find myself wanting to eval/inspect/tap the value stored in a var v, but simply typing out the symbol and C-c C-c 'skips' backward over it to eval the preceding form that's wrapped in a list/vector/map. Then I'd either have to move point to EOL and recall the key binding for the corresponding (less frequently used) **-last-sexp command , or wrap it in a useless [v] / (identity v) - often the easier route.

yuhan19:04:52

For a more realistic example take the syntax for @app-state , it feels that something like cider-inspect-defun-at-point should 'morally' treat this as a valid top-level call to (deref ..) - admittedly a tiny amount of friction but one that I'm still frequently tripped up by

yuhan19:04:33

(I realise the 'defun' naming and behaviour was inherited from Common / Emacs Lisp at some early point in CIDER's history, just debating if it would be better to nudge its semantics towards Clojure's more general notion of 'top level forms' in a file – especially as other tools like Calva don't follow this arbitrary distinction of wrapped / unwrapped forms)

vemv22:04:13

If you don't get an answer more interesting that mine, I'd suggest to create a GH issue. We could use a self-contained example, and your own analysis of the possible tradeoffs. Thanks!

oyakushev08:04:59

Even though I subjectively don't think that eval-last-sexp is less frequently used (to the point that I view it as a more fundamental command than defun-at-point), I have to agree that the behavior where C-c C-c walks back and evaluates code unrelated to the code under the cursor is not very intuitive. Perhaps, it makes sense when the cursor is at the whitespace or the comment, but not when it's other code.

bozhidar06:04:36

I agree. I had actually forgotten it doesn't operate on any top-level form, as the name is a bit of an misnomer - it's not supposed to evaluate the definition at point, but rather the top-level form at point.

bozhidar06:04:28

But like @U06PNK4HG I use more eval-last-sexp, so that's why I probably forgot about this. 😄

yuhan13:04:51

Oh yes, I was definitely talking about my own subjective usage of the commands, should've phrased that better 😅 Also what I had in mind were the more specialized families of commands like eval-and-pprint, eval-and-tap etc, for which I prefer to only commit one keybinding to memory and M-x the rest of the time. And usually that ends up being the defun-at-point variant

yuhan13:04:48

Will open a github issue and try to put together a fix myself - one separate concern was whether such a change would warrant yet another opt-in defcustom

👍 1