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: John Mastro
Subject: Re: How to delete the parens around a sexp?
Date: Tue, 22 Sep 2015 19:15:24 -0700

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

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

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

-- 
john



reply via email to

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