I was lurking in a Twitter conversation between Jean-Philippe Paradis and Xah Lee and learned something new and useful. If you’re using Paredit mode, as you should be, there is a difference between 【Return】 and 【Ctrl+j】. I have 【Return】 set to newline-and-indent
which is probably what most people use. If you type 【Ctrl+j】 instead, you get paredit-newline
which behaves pretty much the same but instead of just indenting the new line it also indents any S-expression following the point. That’s a win and in keeping with the Paredit philosophy of working on the syntax tree rather than just text.
Here’s the example from the paredit-newline
help page. First, we type 【Return】
(let ((n (frobbotz))) |(display (+ n 1) port)) → (let ((n (frobbotz))) |(display (+ n 1) port))
and then 【Ctrl+j】
(let ((n (frobbotz))) |(display (+ n 1) port)) → (let ((n (frobbotz))) |(display (+ n 1) port))
Paradis says that it’s just as easy to type 【Ctrl+j】 as it is to type 【Return】 and that’s what he does. I’m not sure I’m trainable enough to start doing that but I could just add
(define-key lisp-mode-shared-map (kbd "RET") 'paredit-newline)
to my init.el
to get the desired result. I suppose I could also remap 【Ctrl+j】 to newline-and-indent
so that I could have the old behavior if I needed it.
What are the rest of you doing? If you know about paredit-newline
, are you typing 【Ctrl+j】 or have you remapped it? I really like this functionality so I’m interested in how others are invoking it.