[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to delete the parens around a sexp?
From: |
Emanuel Berg |
Subject: |
Re: How to delete the parens around a sexp? |
Date: |
Wed, 23 Sep 2015 02:49:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Marcin Borkowski <mbork@mbork.pl> writes:
> 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
You say "sexp" when you want to delete the parens
around
(some gibberish)
but place point within the parens and do for example
`forward-sexp' and see that "some" and "gibberish" are
not a unit.
If you want do just delete right and left parens in
natural languages, something like the below
would work.
If you want do delete *matching* pairs in programming,
you would have to do the same, only with
`matching-paren' or so to find out what should
be deleted.
(defun remove-parens ()
(interactive)
(let ((start (point))
(right)
(left)
(done) )
(setq right (re-search-forward ")" nil t) )
(when right
(goto-char start)
(setq left (re-search-backward "(" nil t))
(when (and right left)
(goto-char right)
(delete-char -1)
(goto-char left)
(delete-char 1)
(goto-char (1- start))
(setq done t) ))
(unless done (message "No parenthesis pair around point.") )))
--
underground experts united
http://user.it.uu.se/~embe8573