Paredit provides barf and slurp commands. I can see when I would use slurp commands but I am not sure when I should use barf commands.
When I have this code:
(foo num)
(bar num)
I would write this:
(let ((numb blah)))
(foo num)
(bar num)
and then slurp twice to get this:
(let ((numb blah))
(foo num)
(bar num))
I thought at first that the opposite of that task might require use of barf, but for that, I can just move point to start of (foo num)
and then press <M-up>
which runs the command paredit-splice-sexp-killing-backward and I get back this:
(foo num)
(bar num)
What are some scenarios where using the barf command would be handy?
Note: When you repeat the slurp command too many times than necessary, you can invoke the undo command to cancel some of it.
It is a universally accepted truth by the all members of Paredit community that slurpage and barfage are inseparable from the mode. Write some lisp code with Paredit and the need for these will arise. This is more due to the nature of structural editing and Paredit's hate for unbalanced parentheses than any other factor.
When not using Paredit this can be done by navigating with the cursor (or perhaps with the mouse) while adding and removing the parentheses. Paredit does not allow its users to violate its parentheses in such an undesirable manner, thus the natural conclusion is that Paredit users must barf and slurp.
An example:
A block of code is created, an if statement.
(when (|so bar fuux baz)
(foo suux duux))
Instead of testing one condition, this block needs to test two using the and
logical operator. M-(
can be used to wrap, but it will not wrap the juicy bar fuux baz
symbols.
(when ((|so) bar fuux baz)
(foo suux duux))
Slurp
(when ((|so bar fuux baz))
(foo suux duux))
A mistake has been made. Baz
belongs in the second condition block. barf.
(when ((|so bar fuux) baz)
(foo suux duux))
The rest does not include the use of slurpage or barfage.
(when (and (|so bar fuux) baz)
(foo suux duux))