all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#32896: 27.0.50; wishlist: Delete matching pairs
@ 2018-10-01 14:34 Alex Branham
  2018-10-08 22:15 ` Juri Linkov
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Branham @ 2018-10-01 14:34 UTC (permalink / raw)
  To: 32896

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

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32896: 27.0.50; wishlist: Delete matching pairs
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Juri Linkov @ 2018-10-08 22:15 UTC (permalink / raw)
  To: Alex Branham; +Cc: 32896-done

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32896: 27.0.50; wishlist: Delete matching pairs
  2018-10-08 22:15 ` Juri Linkov
@ 2018-10-08 23:29   ` Alex Branham
  2018-10-16 23:00     ` Juri Linkov
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Branham @ 2018-10-08 23:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 32896-done

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


On Mon 08 Oct 2018 at 17:15, Juri Linkov <juri@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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32896: 27.0.50; wishlist: Delete matching pairs
  2018-10-08 23:29   ` Alex Branham
@ 2018-10-16 23:00     ` Juri Linkov
  0 siblings, 0 replies; 4+ messages in thread
From: Juri Linkov @ 2018-10-16 23:00 UTC (permalink / raw)
  To: Alex Branham; +Cc: 32896

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-16 23:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.