5

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

3

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.

PS

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
2

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:

{{text}}

You can:

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

And you will get:

{text}

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.