Multiple lines in the cider repl with paredit on

Is it possible to use the cider-repl in emacs with paredit turned on?
Whenever I hit return (to drop a line) in the cider-repl I get error messages because the closing parentheses from paredit are registering, rather than dropping a line, indenting, and letting me continue.

Yes, try M-j (default-indent-new-line) instead of Enter.

That works, but it’s so counterproductive and unnatural. You would think that someone would have solved this by now. There’s a great Common Lisp IDE called Portacle (uses emacs) and paredit works fine in the CL repl.

You’re welcome.

Evaluation via the source code buffer is far more effective and simpler than writing and evaluating code in the REPL buffer.

See the video at Practicalli Spacemacs - Practicalli Spacemacs

A (comment ) form is used in the source code buffer to separate experiments code or to call functions with specific data to establish specific behaviour. Cider can evaluate expressions in the comment as if they were top level forms.

The issue mentioned in this thread does not exist when using the source code buffer.

Many choose to hide or minimise the repl buffer as it is used far less, or not at all.

I tend to only use the repl prompt directly when calling functions from a custom user namespace, e.g starting or restarting system components

1 Like

Aha, yes, you are absolutely right! I initially went to try out the OP’s request in the REPL and I asked myself “How do I normally do this?” It took me a while to figure out the solution (which by the way you can also achieve using C-j), and that’s simply because I don’t “normally” do it that way at all. Evaluation in the buffer is by far the cleanest way to do it, and as you say, the issue raised here vanishes if you do.

You can swap the behavior and use return for what you want, the below then uses C-RET for evaluating:

(define-key cider-repl-mode-map (kbd "RET") #'cider-repl-newline-and-indent)
(define-key cider-repl-mode-map (kbd "C-<return>") #'cider-repl-return)

I know this is the common view, Rich has even called typing directly in the REPL “nails in a chalkboard”.

But CIDER is in emacs so you have the full editing power of emacs and its modes (including paredit) in the repl. You can even configure it to go on load directly to a repl namespace that has all your commonly used requires and aliases for a project loaded up (which may not be the case in an arbitrary project namespace, especially if you have a decent number of them). CIDER also has a nice history function.

I find myself typing directly in the repl a lot. I have tried doing it the other way and end up with pointlessly cluttered source files or an unwieldy long scratch.clj file. For little to no benefit (that I care about, maybe I’m missing something here). Once I have something worth keeping in the repl it goes right into an ns file, either the code proper or a test.

Obviously if I’m writing a whole new function I intend to keep I don’t do that in the repl usually. But I’ll typically call it for the first time from there.And I’ll play with code chunks in the repl to make sure they are working the way I expect, edit if needed, put back in the source buffer in whatever fn it came from.

I guess everyone has their preferences but I haven’t yet found buffer to be automatically a huge win over repl.

Maybe it comes down to whether you like to have little comment blocks with mini tests near the function in question. Personally I used to do that but quickly moved to putting those in distinct test files.

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