all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Alex Branham <alex.branham@gmail.com>
Cc: 32896@debbugs.gnu.org
Subject: bug#32896: 27.0.50; wishlist: Delete matching pairs
Date: Wed, 17 Oct 2018 02:00:14 +0300	[thread overview]
Message-ID: <87murdlcox.fsf@mail.linkov.net> (raw)
In-Reply-To: <87ftxgf25b.fsf@gmail.com> (Alex Branham's message of "Mon, 08 Oct 2018 18:29:36 -0500")

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]

>> Fortunately, Emacs already has such a command named ‘delete-pair’:
>> it deletes the parens around the let function as in your first
>> example as well as the quotes in your second example.  It makes
>> sense to bind this command to e.g. ‘C-x M-(’ to be the inverse of
>> ‘M-(’ (insert-pair)
>
> Yay! I didn't know about that command (and I really did search before
> reporting this bug, no idea how I missed it!). It doesn't work backward
> though as far as I can tell:
>
> (let (message "%s" "foobar")|)

With a simple twist in the patch attached, it will be able to work backward
with M-- M-x delete-pair, i.e. with a negative prefix argument.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: delete-pair.patch --]
[-- Type: text/x-diff, Size: 714 bytes --]

diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 5a89923f8f..fd6018988e 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -723,11 +723,12 @@ insert-parentheses
   (interactive "P")
   (insert-pair arg ?\( ?\)))
 
-(defun delete-pair ()
+(defun delete-pair (&optional arg)
   "Delete a pair of characters enclosing the sexp that follows point."
-  (interactive)
-  (save-excursion (forward-sexp 1) (delete-char -1))
-  (delete-char 1))
+  (interactive "p")
+  (unless arg (setq arg 1))
+  (save-excursion (forward-sexp arg) (delete-char (if (> arg 0) -1 1)))
+  (delete-char (if (> arg 0) 1 -1)))
 
 (defun raise-sexp (&optional arg)
   "Raise ARG sexps higher up the tree."

      reply	other threads:[~2018-10-16 23:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 14:34 bug#32896: 27.0.50; wishlist: Delete matching pairs Alex Branham
2018-10-08 22:15 ` Juri Linkov
2018-10-08 23:29   ` Alex Branham
2018-10-16 23:00     ` Juri Linkov [this message]

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=87murdlcox.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=32896@debbugs.gnu.org \
    --cc=alex.branham@gmail.com \
    /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.