Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping braces around text?

Tags:

paredit

When using paredit how do you wrap braces around text? I've used paredit several times however I get frustrated because it stops me from doing what I want.

Example:

(foo
    (bar 1 2 3)
    baz 1 2 3)

Opps, baz 1 2 3 should be wrapped like so:

(foo
    (bar 1 2 3)
    (baz 1 2 3))

But, no... :

(foo
    (bar 1 2 3)
    () baz 1 2 3)
like image 419
AnnanFay Avatar asked Jan 06 '12 23:01

AnnanFay


2 Answers

You didn't mention what editor you're working in. In any case if you just enter an opening paren then its closing pair is immediately added as well. In order to wrap an expression in parentheses you need to use a 'wrap' function.

In emacs this can be paredit-wrap-round or M-(, please find an emacs paredit cheatsheet here.

In vim using slimv this is ,W (if you select an expression first then the whole expression will be wrapped).

If you happen to wrap the wrong number of elements then you can move them into/out of the s-expression (see 'slurp' and 'barf' for emacs), or you can move the parenthesis (,< or ,> for vim).

like image 131
Tamas Kovacs Avatar answered Nov 08 '22 21:11

Tamas Kovacs


Type C-u ( instead of ( to make it wrap around everything from the point on, or M-3 ( (or M-3 M-() to make it wrap around the next three S-expressions.

Alternatively, you can mark the region you want to parenthesize and then type (.

Another alternative is to type ( and then hit M-) to slurp in what you want term by term.

like image 2
Ronald L. Frobnitz Avatar answered Nov 08 '22 21:11

Ronald L. Frobnitz