I have some text like this

This is a {{text}} with { { {some {extra} unneeded {
{and ugly}} braces 

Is there a way to remove the extra unneeded parenthesis so that the result is

This is a {text} with {some {extra} unneeded 
{and ugly} braces 

Or something like this, up to whitespace. I use smartparens but I couldn't find anything there to resolve this (other than going through each extra pair and removing it).


I use sp-unwrap-sexp.

In your example, having

  • sp-unwrap-sexp bind to M-Backspace
  • sp-next-sexp bind to C-M-n
  • sp-down-sexp bind to C-M-d

and a cursor in the beginning of the text, I do:

  1. C-M-d to go to {text}
  2. M-Backspace to remove outer {}
  3. C-M-n 3 times to go to { { {some {extra} unneeded {
  4. M-Backspace 2 times to get {some {extra} unneeded { of course matching braces } were also removed
  5. C-M-d C-M-n C-M-n C-M-n to go to the last { on the first line
  6. M-Backspace and we are done.


Here is short demo: https://youtu.be/LJMPnIUXTW0

  • Thanks. Although, I was hoping for something that I can run on a buffer to automatically do this. In general, I find Emacs' handling of paired delimiters quite limited.
    – Tohiko
    May 24 '18 at 8:23
  • Well, that was not clear from the Q desc. To do it automatically you have to actually create an interactive function that does it for you. Or try to come up with the keyboard macro.
    – Maxim Kim
    May 24 '18 at 8:27

You can try using sp-raise-sexp.

From the documentation (C-h f sp-raise-sexp):

Unwrap the current list and kill everything inside except next expression.

For example, with this:


You can:

  • place point/cursor on the second {
  • M-x sp-raise-sexp

And you will get:

  • Or the builtin raise-sexp, no need to used smartparens for this.
    – Omar
    Mar 15 '20 at 22:20

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .