This is an Emacs question, but there are so many Clojure Emacs users, I am asking here as I’ve been amazed at how knowledgeable and helpful people have been.
I’m using Cider in Emacs. Historically, I’ve tended to just reload the file and then type directly into the REPL. I’ve recently noticed another style of writing/testing from within a (comment. . .) block. I really like this style, but it’s not quite working seamlessly for me. (I understand this works well within JSCode, but I can’t retrain my fingers . . .)
There are two command that appear to be most useful for evaluating code from a source file to the REPL:
My problem with cider-eval-sexp-at-point, is that the results are sent to the Messages buffer, not to the REPL
The problem with cider-eval-last-sexp-to-repl is that it does though it send the results of evaluation to the REPL buffer, it does so at wherever the cursor is, not at the end of the REPL. Also, it does not execute a “return”, so the cursor is not ready for another evaluation. Ideally, I would like to evaluate another chunk of code and have it end with a fresh cursor.
Perhaps there is a way to do this already, which would be ideal. Otherwise, I was thinking of writing a new Emacs command to effect this functionality.
As a longtime user of Emacs (currently Doom Emacs), I’ve written a handful of basic functions, but this is more complicated than I’ve tried before. So any advice would be appreciated. (I may also post this on an Emacs site as well.)
Here then would be the basic function:
1) Start in a Clojure file, with the point at the end of an sexp.
2) Execute the function.
3) The sexp is evaluated.
4) In REPL buffer, the current point would move to the end of the REPL, refreshing the cursor if needed.
5) The evaluated results would then be printed (at end of the REPL).
6) A “return” would then be sent to the REPL, so there would be a fresh cursor.
7) The original point within the Clojure file would not have moved.
8) This function could then be repeated from within the Clojure file without having to move to and from the REPL.
This is almost the functionality of cider-eval-last-sexp-to-repl. As mentioned above, it doesn’t first go to the end of the REPL and it also does not send a “return”.
Any advice would be appreciated.