Suppose I have this code
(hello world)
(hi world)
Then it comes to my mind that I should wrap that with the following form:
(let (acc)
<>
(nreverse acc))
resulting in this code:
(let (acc)
(hello world)
(hi world)
(nreverse acc))
Here is how I usually do the wrapping. First I write an incomplete outer form before the to-be-wrapped forms like this:
(let (acc))
(hello world)
(hi world)
Then I press C-)
(paredit-forward-slurp-sexp
) twice to slurp things:
(let (acc)
(hello world)
(hi world))
Then I finish up by adding (nreverse acc)
at the end.
Now what I wonder is what if I started by first writing the complete outer form template like this?
(let (acc)
(nreverse acc))
(hello world)
(hi world)
or like this
(hello world)
(hi world)
(let (acc)
(nreverse acc))
Is there a short sequence of paredit or non-paredit commands that I can press to finish the job from that start?
I could move point, cut the two to-be-wrapped forms, move point, paste the forms. But I am wondering if there is a more convenient way.
I am satisfied with how I do the wrapping, but it feels like I might be missing some other neat editing tricks which are to be found from a different start.
Instead of repeatedly using paredit-forward-slurp-sexp
or kill-yank'ing the region, you can mark the region of sexps to enclose and use paredit-wrap-round
M-(
If I were typing your example I would start with the last expression:
(hello world)
(hi world)
(nreverse acc)_
C-SPC C-M-a C-M-a C-M-a M-( yields:
(_(hello world)
(hi world)
(nreverse acc))
Insert let (acc)
and finish with RET C-M-h TAB to reindentify.
There's probably a better way =), but even if you don't use transient-mark-mode
you can supply other options to wrapping:
#
expressionsSee the docstring for paredit-wrap-sexp
You might also want to look at redshank, a emacs package that does a bunch of useful things like this. Works with paredit very nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With