I'm a long-time paredit user who's started experimenting with using smartparens for Ruby development. The various cursor motion commands have been nice, but now I'm regularly being confronted with a significant annoyance.

Suppose I've got a function call sitting by itself:

foo()

Now I want to wrap it in an if-end block. If I open a new line above the call and type if and a space, smartparens mode helpfully gives me the matching end, but before the line I wanted the if to include:

if |
end
foo()

(| being the cursor position.)

Now I have to delete the end, indent the foo(), and add the end after.

This is so annoying that I figure there must be some way to wrap a given block of code with a given control structure, since paredit makes it so trivial (M-() and "Smartparens aims to provide a superset of [paredit et al's] features, in all programming languages," but I just have not been able to glean how it might be done.

The smartparen wiki page entitled "Wrapping" mentions how single-character pairs wrap the region if it's active, just like I'm used to from paredit, and the section "Wrapping with tags" describes how starting and ending tags can be defined together, which seems to be what's happening with my if and end, but doesn't describe how to wrap existing text in that way. I can't just select the block I want to wrap and type if, so how would it be done? Is it even possible?

The only alternative I've found is to start with the empty if/end that smartparens gives me and the slurp the following expressions into it by repeatedly pressing C-) (sp-forward-slurp-sexp), but that hardly feels like any better of a solution that just manually deleting the end and inserting it in the right place.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.