help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to delete the parens around a sexp?


From: Marcin Borkowski
Subject: Re: How to delete the parens around a sexp?
Date: Mon, 19 Oct 2015 08:04:01 +0200

On 2015-09-23, at 04:15, John Mastro <john.b.mastro@gmail.com> wrote:

>> I'd like to transform this:
>>
>> -!-(some gibberish)
>>
>> into this:
>>
>> -!-some gibberish
>>
>> I assume there's no function in Elisp for that, and it's trivial to
>> write one, but I just wanted to make sure before I code it.  raise-sexp
>> doesn't work, since it gobbles "gibberish" in the above example unless
>> given a prefix argument, and if you replace "some gibberish" with an
>> actual sentence, counting words manually is no fun.
>>
>> (Note: before anyone tells me how such a transformation doesn't make
>> sense: I need it for writing in a natural language.)
>
> As someone else noted, `sp-unwrap-sexp' (part of the `smartparens'
> package) does this. Smartparens is great for bringing some of the joy of
> Paredit to non-Lisps [1] so I'd recommend checking it out anyway.

Last time I did, it didn't work in my use-case.  Not that it doesn't
work; it is just not smart enough for me;-).  Consider this LaTeX code:

\left\{ ... \bigl\langle ... ( ... ] ... \bigr\rangle ... \right.

(The dot after \right is part of the code.)

> However, if you don't want to depend on a third-party package, something
> along these lines might help get you started:
>
>     (defun unwrap-next-sexp ()
>       (interactive)
>       (let ((close (progn (forward-sexp 1)
>                           (point)))
>             (open (progn (forward-sexp -1)
>                          (point))))
>         (goto-char close)
>         (delete-char -1)
>         (goto-char open)
>         (delete-char 1)))

Nice, better than delete-pair.

> [1] I still prefer Paredit when working with Lisps but plenty of
> reasonable people use Smartparens everywhere.

I didn't try paredit, but - as I wrote a minute ago - Lispy might be
even better due to its cool reuse of self-inserting commands in contexts
they don't make sense anyway.

Regards,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]