Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 814
siphiuel Avatar asked May 11 '15 21:05

siphiuel


2 Answers

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.

like image 174
Arthur Ulfeldt Avatar answered Oct 23 '22 00:10

Arthur Ulfeldt


I am not an expert on: lisps, emacs, paredit, vim-sexp, or vim-sexp-mappings-for-regular-people. (Why am I posting right?!)

However I know that slurp and barf come form Emac's paredit mode. This Emacs mode is supposedly very helpful for lisp coders. I am sure you can find a nice helpful article on these subjects if you search for paredit. As a matter a fact I found a nice article for you: The Animated Guide to Paredit. From what I can tell you are right in your guesses about slurp and barf.

like image 38
Peter Rincker Avatar answered Oct 23 '22 01:10

Peter Rincker