Cider eval to repl + new prompt

Is cider-eval-last-sexp-to-repl meant to create a new prompt after evaluating a piece of code?

Evaluating the following twice:
Screenshot 2021-06-26 at 15.34.01

Results in:
Screenshot 2021-06-26 at 15.34.11

I would expect:

Screenshot 2021-06-26 at 17.21.47

Is this behaviour expected? Seems odd

cider-eval-last-sexp-to-repl is intended to help you “type in” an expression by evaluating another expression, which most likely is not in the REPL buffer but rather in another buffer. Therefore it puts the result “at the point” in the REPL, as if you had typed it in (not as if it were stdout or a normal expression result); and therefore when you hit Enter in the REPL it gets evaluated.

In short, I think this is not the command you intended to use!

2 Likes

Thanks. Is there anything in Cider which does this? Cursive has this send code to the REPL to be evaluated semantics and I prefer it over typing into the REPL.

A REPL is a Read-Evaluate-Print-Loop process, so there will always be a new prompt after an expression is read, evaluated and result printed. This is normal.
If a new prompt doesn’t appear then its either a long running process or something bad has happened.

To send code from an editor window to a REPL buffer without that buffer sending the code to the REPL, then try something like cider-insert-last-sexp-in-repl - or just copy(yank) / paste as that is all that is happening I believe.

From the Cider source code

(defun cider-insert-last-sexp-in-repl (&optional arg)
  "Insert the expression preceding point in the REPL buffer.
If invoked with a prefix ARG eval the expression after inserting it."
  (interactive "P")
  (cider-insert-in-repl (cider-last-sexp) arg))

I don’t understand the value sending code to the REPL buffer, as the REPL buffer is not as feature rich as the editor buffer. The editor buffer is far more effective way to evaluate code in the REPL and doesn’t require a separate buffer or changing of namespace in said buffer.

See the video on Introduction · Clojure development with Spacemacs & Cider for a small example of evaluating in the code buffer

If this is for a longer running process, then it is more effective to run a REPL process in an external terminal session and connect to that process using cider-connect. Typically there would be a user namespace defined in the project with convenience functions to call, e.g:
https://practical.li/clojure/clojure-tools/projects/configure-repl-startup.html

1 Like

Hum, ya I think there is a way to do that.

Try this: Anyone else gets annoyed with Cider? - #5 by dpsutton

I’m not 100% sure it’s what you want, but it sounds similar.

Also seems like you don’t know about cider-eval-last-sexp ( C-x C-e ) ? That’s really the one you should be using by default, it’ll evaluate the form inline with the code, no REPL buffer needed.

1 Like

Answered by @dpsutton on Clojurians Slack

Add these Cider config options:

(setq cider-invert-insert-eval-p t)
(setq cider-switch-to-repl-on-insert nil)
(setq clojure-toplevel-inside-comment-form t)

You can then use C-c C-j, C-c C-j d and C-c C-j e keybindings

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.