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 ).

Shaun
  • 177
  • 8

1 Answers1

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());
zck
  • 8,984
  • 2
  • 31
  • 65
  • 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
  • It would be great if electric-pair support `sp-forward-slurp-sexp` function. – Jiacai Liu May 04 '21 at 15:56