How to wrap forms with already written external form in paredit

Suppose I have this code

(hello world) (hi world) 

Then it occurs to me that I should wrap this as follows:

 (let (acc) <> (nreverse acc)) 

bringing this code:

 (let (acc) (hello world) (hi world) (nreverse acc)) 

This is how I usually do the wrapper. First, I write an incomplete external form in front of such wrapped forms:

 (let (acc)) (hello world) (hi world) 

Then I paredit-forward-slurp-sexp C-) twice ( paredit-forward-slurp-sexp ) to separate things:

 (let (acc) (hello world) (hi world)) 

Then I end up adding (nreverse acc) at the end.

Now I wonder, what if I started writing the full external form template first, how is it?

 (let (acc) (nreverse acc)) (hello world) (hi world) 

or how is it

 (hello world) (hi world) (let (acc) (nreverse acc)) 

Is there a short sequence of paredit or non-paredit commands that I can click to finish the job from this run?

I could move the point, cut out the two shapes to be wrapped, move the point, paste the shapes. But I wonder if there is a more convenient way.

I am happy with the way I do the wrapping, but it seems to me that I can skip some other neat editing tricks that can be found from a different start.

+6
source share
2 answers

Instead of reusing the paredit-forward-slurp-sexp or kill-yank'ing areas, you can mark the sexps area to enclose and use paredit-wrap-round M- (

If I typed your example, I would start with the last expression:

 (hello world) (hi world) (nreverse acc)_ 

C-SPC CMa CMa CMa M- ( gives:

 (_(hello world) (hi world) (nreverse acc)) 

Insert let (acc) and end with RET CMh TAB to re-index.

Probably the best way =), but even if you are not using transient-mark-mode , you can specify other options for packaging:

  • Cu wraps at the end of the buffer or spanning list
  • Cu # wraps the following expressions #

See docstring for paredit-wrap-sexp

+7
source

You can also look at redshank, an emacs package that does a bunch of useful things like this. Works with paredit very nicely.

+1
source

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


All Articles