I like electric pairing for things like...

someJavascript(function() {  });

Where it automatically pairs { with {) etc.

However, it infuriates me when I have


and I want to turn that into


It comes out as:


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

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

1 Answer 1


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


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


And a second time in:

  • 1
    Consider using sp-slurp-hybrid-sexp. It does the right thing in this context.
    – PythonNut
    Feb 20, 2016 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, 2016 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, 2016 at 20:28
  • It would be great if electric-pair support sp-forward-slurp-sexp function.
    – Jiacai Liu
    May 4, 2021 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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