Paredit is a package that help you write lisp-like language. It helps you keep the parentheses balanced in writing code, that is said, you can not delete the )
without delete the paired (
in front. When enable it’s hard to mess your code with only unbalanced S-exp, so it is a very helpful tool for writing lisp-like code.
paredit vs smartparens
Smartparens is a newer package that provides more function than paredit, it works more like a modern code editor. and there are more activities in development, but both package are very stable, and the function is limited, so it is okay they are not developed for a period of time. The major reason I choose paredit is that it is a very small package and provides the most useful function to help me in writing lisp. It follows the UNIX philosophy: Do one thing and do it well. The smartparens is much bigger than paredit, it aims to provide more usage in other coding languages, somehow I find it useless even in coding lisp in the end.
Most usefull command
I change some most often used keybinding in my config.
Splice sexp
: M-<up>
binding to paredit-splice-sexp
which original binded to M-s
.
(foo (bar| baz) quux)
--->
(foo bar| baz quux)
Wrap sexp
: M-<down>
binding to paredit-wrap-round
which original binded to M-(
.
(foo |bar baz)
--->
(foo (|bar) baz)
Barfage && Slurpage
: They are two paired action, one group working forward, one group working backward. but group by direction always confused me when editing, so I change the binding and group them in action. C
for slurage, and C-M
for barfage. and my intuition of the action movement is base on the position changes of )
or (
, so the
Slurpage forward
: C-<right>
binding to paredit-forward-slurp-sexp
.
(foo (bar |baz) quux zot)
--->
(foo (bar |baz quux) zot)
(a b ((c| d)) e f)
--->
(a b ((c| d) e) f)
Slurpage backward
: C-<left>
binding to paredit-backward-slurp-sexp
which original binded to C-M-<left>
.
(foo bar (baz| quux) zot)
--->
(foo (bar baz| quux) zot)
(a b ((c| d)) e f)
--->
(a (b (c| d)) e f)
Barfage forward
: M-<right>
binding to paredit-forward-barf-sexp
, notice: the movement of )
is reversed to the fuction name, it move backward, the same as pressed arrow key. Original binded to C-<left>
.
(foo (bar |baz quux) zot)
--->
(foo (bar |baz) quux zot)
Barfage backward
: M-<left>
binding to paredit-backward-barf-sexp
.
(foo (bar baz |quux) zot)
--->
(foo bar (baz |quux) zot)