all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Edward Knyshov <edvorg@gmail.com>
To: Nicolas Richard <youngfrog@members.fsf.org>,
	Marcin Borkowski <mbork@mbork.pl>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to delete the parens around a sexp?
Date: Tue, 22 Sep 2015 11:30:10 +0000	[thread overview]
Message-ID: <CAOi_WG2iV0iYrm13B1jZM7-urr0if0WPR5KkxDe7o3r4sS_5Xg@mail.gmail.com> (raw)
In-Reply-To: <87lhby7ogy.fsf@members.fsf.org>

You may use unwrap-sexp from smartparens

On Tue, Sep 22, 2015, 1:14 PM Nicolas Richard <youngfrog@members.fsf.org>
wrote:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
> > Hi list,
> >
> > I'd like to transform this:
> >
> > -!-(some gibberish)
> >
> > into this:
> >
> > -!-some gibberish
>
> I use the following code, which allows me to delete the brackets (M-D
> RET) or replace them by another pair, e.g. square brackets (M-D [).
>
> M-D runs the command yf/replace-or-delete-pair defined as follows:
>
> (defun yf/replace-or-delete-pair (open)
>   "Replace pair at point by OPEN and its corresponding closing character.
> The closing character is lookup in the syntax table or asked to
> the user if not found."
>   (interactive
>    (list
>     (read-char
>      (format "Replacing pair %c%c by (or hit RET to delete pair):"
>              (char-after)
>              (save-excursion
>                (forward-sexp 1)
>                (char-before))))))
>   (if (memq open '(?\n ?\r))
>       (delete-pair)
>     (let ((close (cdr (aref (syntax-table) open))))
>       (when (not close)
>         (setq close
>               (read-char
>                (format "Don't know how to close character %s (#%d) ;
> please provide a closing character: "
>                        (single-key-description open 'no-angles)
>                        open))))
>       (yf/replace-pair open close))))
>
> (defun yf/replace-pair (open close)
>   "Replace pair at point by respective chars OPEN and CLOSE.
> If CLOSE is nil, lookup the syntax table. If that fails, signal
> an error."
>   (let ((close (or close
>                    (cdr-safe (aref (syntax-table) open))
>                    (error "No matching closing char for character %s (#%d)"
>                           (single-key-description open t)
>                           open)))
>         (parens-require-spaces))
>     (insert-pair 1 open close))
>   (delete-pair)
>   (backward-char 1))
>
> --
> Nicolas Richard
>
>


  reply	other threads:[~2015-09-22 11:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22  7:40 How to delete the parens around a sexp? Marcin Borkowski
2015-09-22 10:11 ` Nicolas Richard
2015-09-22 11:30   ` Edward Knyshov [this message]
2015-09-22 11:45 ` Rasmus
2015-09-22 11:54 ` Andreas Röhler
2015-09-23  0:49 ` Emanuel Berg
2015-09-23  0:58   ` Emanuel Berg
2015-09-23  2:15 ` John Mastro
2015-09-23  3:06   ` Emanuel Berg
2015-10-19  6:04   ` Marcin Borkowski
2015-10-21 11:23     ` Oleh Krehel
2015-10-18 22:12 ` Thien-Thi Nguyen
2015-10-19  5:59   ` Marcin Borkowski
     [not found] ` <mailman.588.1445207663.7904.help-gnu-emacs@gnu.org>
2015-10-19  0:49   ` Pascal J. Bourguignon
2015-10-19  5:59     ` Marcin Borkowski
     [not found] <mailman.1573.1442907653.19560.help-gnu-emacs@gnu.org>
2015-09-22  8:28 ` Joost Kremers
2015-09-22  8:38 ` Marco Wahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOi_WG2iV0iYrm13B1jZM7-urr0if0WPR5KkxDe7o3r4sS_5Xg@mail.gmail.com \
    --to=edvorg@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    --cc=youngfrog@members.fsf.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.