Skip to content
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

Feature Request : Have cider-eval-last-sexp prompt for context #2113

Closed
l0st3d opened this issue Nov 14, 2017 · 8 comments
Closed

Feature Request : Have cider-eval-last-sexp prompt for context #2113

l0st3d opened this issue Nov 14, 2017 · 8 comments

Comments

@l0st3d
Copy link

l0st3d commented Nov 14, 2017

It might be nice if, when trying to eval an sexp from the middle of a function, there was some way to inject some form of context. I'm imagining something like wrapping the form in a let before trying to eval it. Ideally CIDER would prompt me for each of the undefined forms either by analysing the code before evaluation, and remember my previous input, but I'd be happy with just being prompted for a let-binding form to insert, which could default to an empty vector. The idea is to not have to pollute the namespace I'm working in with temporary vars that I need to remember to remove and undefine later.

@xiongtx
Copy link
Member

xiongtx commented Nov 14, 2017

I don't think that's a good idea. cider-eval-last-sexp should do what it says--eval the last sexp. If you want a let-binding, include it as part of the sexp you want to eval.

@ChrisBlom
Copy link

I thinks its a good idea, it would be useful to quickly test a sexp without needing to adding temporary changes to the buffer. Maybe not as default behaviour for cider-eval-last-sexp though, but as a separate command or with a prefix key.

@bbatsov
Copy link
Member

bbatsov commented Dec 9, 2017

That should definitely not be the default behaviour.

The debugger already has similar functionality, so I'm guessing it can be leveraged for this as well. Whether this is easy or not I do not know - maybe @Malabarba can shed some light on this.

@jpmonettas
Copy link
Contributor

@bbatsov
Copy link
Member

bbatsov commented Jan 14, 2018

Btw, I know it's not the same, but some of you might find useful the new cider-eval-defun-to-point. It runs the current top-level expression up to the cursor's position, which is something like a contextual evaluation (depending on your perspective).

@bbatsov
Copy link
Member

bbatsov commented Jan 14, 2018

Reading again @l0st3d's simple idea about just asking the user to supply some let-bindings and remembering those across invocations I decided to implement it. Parsing an expression for locals and prompting just for those would be fancy and is not a rocket science, but I simply don't have time to work on it, so let's just leave it to the user to provide whatever bindings they want.

@viesti
Copy link

viesti commented May 21, 2020

I just found this cool feature! :) I ran into it while looking if there would be a way to define a dynamic var around a form in the middle of a clojure.test test.

I've been writing tests so that I have a fixture/*test-system* dynamically bound to an integrant or component system and then I run the test code against a live system at the repl too. Now I've been copying the test form into repl, wrapped in with:

(binding [fixture/*test-system* reloaded.repl/system]
  (is 42 (get-answer-from-api)))

cider-eval-last-sexp-in-context is eerily close to this idea 😅Edit: Might even work if one could choose between let and binding :)

@viesti
Copy link

viesti commented May 21, 2020

So I remembered that this is Emacs: replaced the let with binding, did eval, and voilà, got what I wanted :) Didn't yet have enough energy to look how this could be a thing in cider though :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants