Search code examples
vimclojures-expressionparedit

Slurpage and barfage in Clojure


I am using vim-sexp and vim-sexp-mappings-for-regular-people plugins for editing Clojure files. I don't quite understand what slurp and barf commands do exactly.

I tried playing with them, and it seems that they insert/remove forms at the beginning/end of an adjacent form. Is that correct? If not, what is the proper definition for slurp and barf?


Solution

  • slurping and barfing are the essential operations/concepts to use one of the modern structural code editors. after getting used to them I'm completely incapable of editing code without these. Of the ~20 people that sit with me writing clojure all day all of them use these all the time. so saying that they are "helpful for lisp coders" is a very tactful and polite understatement.

    slurp: (verb)

    "to include the item to one side of the expression surrounding the point into the expression"

    barf: (verb)

    "to exclude either the left most or right most item in the expression surrounding the point from the expression"

    and some examples.

    1 2 (3 4) 5 6
    

    slurp right:

    1 2 (3 4 5) 6
    

    barf right:

    1 2 (3 4) 5 6
    

    slurp left:

    1 (2 3 4) 5 6
    

    barf left:

    1 2 (3 4) 5 6
    

    and we're back where we started.

    When I give talks/presentations introducing paredit I generally leave students/attendees with just these two concepts because I feel they are enough to start getting the benefit of structural editing without being overwhelming. Once you are comfortable with these then move on to structual navigation by learning to move forward/backward and up/down by expression rather than by character.

    even though it list emacs keybindings I still highly recommend the animated guide to paredit that Peter Rincker mentions in his answer.