GNU bug report logs - #32896
27.0.50; wishlist: Delete matching pairs

Previous Next

Package: emacs;

Reported by: Alex Branham <alex.branham <at> gmail.com>

Date: Mon, 1 Oct 2018 14:35:02 UTC

Severity: wishlist

Found in version 27.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32896 in the body.
You can then email your comments to 32896 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32896; Package emacs. (Mon, 01 Oct 2018 14:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alex Branham <alex.branham <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 01 Oct 2018 14:35:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alex Branham <alex.branham <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; wishlist: Delete matching pairs
Date: Mon, 01 Oct 2018 09:34:43 -0500
[Message part 1 (text/plain, inline)]
It would be nice if Emacs had a command to remove matching pairs of
things so that (with | representing point):

(|let (message "%s" "foobar"))

I could delete the parens around the let function. This should work for
other pairs too:

(let ((foobar "foobar")) (message "%s" "|foobar"))

to delete the quotes around the second "foobar"

I know there are 3rd-party packages that implement this but it seems
like this should be included with Emacs since it's such a great tool for
editing.

Alex
[signature.asc (application/pgp-signature, inline)]

Reply sent to Juri Linkov <juri <at> linkov.net>:
You have taken responsibility. (Mon, 08 Oct 2018 23:09:03 GMT) Full text and rfc822 format available.

Notification sent to Alex Branham <alex.branham <at> gmail.com>:
bug acknowledged by developer. (Mon, 08 Oct 2018 23:09:03 GMT) Full text and rfc822 format available.

Message #10 received at 32896-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Alex Branham <alex.branham <at> gmail.com>
Cc: 32896-done <at> debbugs.gnu.org
Subject: Re: bug#32896: 27.0.50; wishlist: Delete matching pairs
Date: Tue, 09 Oct 2018 01:15:30 +0300
> It would be nice if Emacs had a command to remove matching pairs of
> things so that (with | representing point):
>
> (|let (message "%s" "foobar"))
>
> I could delete the parens around the let function. This should work for
> other pairs too:
>
> (let ((foobar "foobar")) (message "%s" "|foobar"))
>
> to delete the quotes around the second "foobar"
>
> I know there are 3rd-party packages that implement this but it seems
> like this should be included with Emacs since it's such a great tool for
> editing.

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)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32896; Package emacs. (Mon, 08 Oct 2018 23:30:02 GMT) Full text and rfc822 format available.

Message #13 received at 32896-done <at> debbugs.gnu.org (full text, mbox):

From: Alex Branham <alex.branham <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 32896-done <at> debbugs.gnu.org
Subject: Re: bug#32896: 27.0.50; wishlist: Delete matching pairs
Date: Mon, 08 Oct 2018 18:29:36 -0500
[Message part 1 (text/plain, inline)]
On Mon 08 Oct 2018 at 17:15, Juri Linkov <juri <at> linkov.net> wrote:

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

M-x delete-pair there does nothing. I was hopeful about
`electric-pair-delete-pair' but it only works if the pair is adjacent.

I guess this is closer to what I wanted:

(defun my/delete-pair ()
  "Call `delete-pair', perhaps also calling `backward-up-list'."
  (interactive)
  (condition-case nil (delete-pair)
    (t (progn (backward-up-list)
              (delete-pair)))))

Anyway, thanks for the response!

Alex
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32896; Package emacs. (Tue, 16 Oct 2018 23:02:02 GMT) Full text and rfc822 format available.

Message #16 received at 32896 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Alex Branham <alex.branham <at> gmail.com>
Cc: 32896 <at> debbugs.gnu.org
Subject: Re: bug#32896: 27.0.50; wishlist: Delete matching pairs
Date: Wed, 17 Oct 2018 02:00:14 +0300
[Message part 1 (text/plain, inline)]
>> 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.

[delete-pair.patch (text/x-diff, inline)]
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."

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 14 Nov 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 223 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.