Wrap shapes around text?

When using paredit, how do you exchange curly braces around text? I used paredit several times, but I'm upset because it prevents me from doing what I want.

Example:

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

Opps, baz 1 2 3 should be wrapped as follows:

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

But no...:

 (foo (bar 1 2 3) () baz 1 2 3) 
+6
source share
2 answers

You did not indicate which editor you are working in. In any case, if you just enter the initial groove, then its closing pair is immediately added. To enclose the expression in parentheses, you need to use the "wrap" function.

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

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

If you happen to wrap the wrong number of elements, you can move them to / from the s-expression (see "slurp" and "barf" for emacs), or you can move the brackets ( ,< or ,> for vim).

+4
source

Type Cu ( instead of ( so that it wraps everything from the point, or M-3 ( (or M-3 M-( ) so that it wraps around the next three S-expressions.

Alternatively, you can mark the region you want to copy, and then enter ( .

Another alternative is to type ( and then press M-) to split into what you want in terms of the term.

+2
source

Source: https://habr.com/ru/post/905371/


All Articles