4

I like electric pairing for things like...

someJavascript(function() {  });

Where it automatically pairs { with {) etc.

However, it infuriates me when I have

someFunction();

and I want to turn that into

wrapped(someFunction());

It comes out as:

wrapped()someFunction();

so I have to break my rhythm and delete the ).

  • 1
    You might want to look into smartparens. – PythonNut Feb 19 '16 at 15:30
  • 3
    On #1, you can select someFunction() as the region and then type (. – xuchunyang Feb 19 '16 at 15:36
  • 2
    Could you break your second question off into a second post, please? – Dan Feb 19 '16 at 20:36
2

One way to deal with this is to use structural editing commands. So, instead of thinking "delete the character, add it at the end", I think something like "wrap the paren pair around the next token".

One library that does this is called smartparens, and the function is #'sp-forward-slurp-sexp. Starting with this text (with the pipe marking point):

wrapped(|)someFunction();

Calling #'sp-forward-slurp-sexp results in:

wrapped(|someFunction)();

And a second time in:

wrapped(someFunction());
| improve this answer | |
  • 1
    Consider using sp-slurp-hybrid-sexp. It does the right thing in this context. – PythonNut Feb 20 '16 at 20:19
  • That's interesting. Is there a downside to using sp-slurp-hybrid-sexp? The documentation seems to indicate that the only loss of functionality is that it doesn't support prefix arguments the way sp-forward-slurp-sexp does. – zck Feb 20 '16 at 20:27
  • 1
    There is also no equivalent barfing command, and it only operates to the right. Other than that, I'm unaware of any shortcomings. – PythonNut Feb 20 '16 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.