all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#73284: [PATCH] Add option to push mark after delete-pair
@ 2024-09-15 20:58 Paul Nelson
  2024-09-16 11:44 ` Eli Zaretskii
  2024-09-21 10:25 ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Paul Nelson @ 2024-09-15 20:58 UTC (permalink / raw)
  To: 73284

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

The delete-pair command from lisp.el deletes a matched pair of
delimiters.  After using this command, I often want to operate on the
region enclosed by the deleted delimiters.  As far as I know, there's
currently no quick way to access the end of that region.

This patch introduces a custom option, delete-pair-push-mark.  When
enabled, it causes delete-pair to push a mark at the end of the
enclosed region.

This opens up various workflows.  For instance, after deleting a pair,
we can use C-x C-x to highlight the region and act on it further.
Alternatively, we can use C-M-k to delete the first sexp inside the
delimiters, then act on the remainder.

To err on the side of caution, I hid the new behavior behind a user
option, disabled by default.  I could just as well see it being turned
on by default (or getting rid of the user option, making the new
behavior "mandatory"), and am open to suggestions/feedback.

Thanks, best,

Paul

[-- Attachment #2: 0001-Add-option-for-delete-pair-to-mark-end-of-region.patch --]
[-- Type: application/octet-stream, Size: 2313 bytes --]

From 0c54eff47299e8a30ab4f5fcafc44801d8983763 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
Date: Sun, 15 Sep 2024 22:29:46 +0200
Subject: [PATCH] Add option for delete-pair to mark end of region

* lisp/emacs-lisp/lisp.el (delete-pair-push-mark): New user option.
(delete-pair): Use it.

* etc/NEWS: Announce the new user option.
---
 etc/NEWS                |  6 ++++++
 lisp/emacs-lisp/lisp.el | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 492159439fc..619e0d2eadf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -147,6 +147,12 @@ instead of raising an error.  Note that if you have disabled Transient
 Mark mode you might prefer to use 'unix-word-rubout', as this feature
 relies on there being an active region.
 
+---
+** New user option 'delete-pair-push-mark'.
+This option, if non-nil, makes 'delete-pair' push a mark at the end of
+the region enclosed by the deleted delimiters.  This makes it easy to
+act on that region.  For example, we can highlight it using 'C-x C-x'.
+
 \f
 * Changes in Specialized Modes and Packages in Emacs 31.1
 
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index e65eec508d9..f6eebcda35a 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -850,10 +850,16 @@ delete-pair-blink-delay
   :group 'lisp
   :version "28.1")
 
+(defcustom delete-pair-push-mark nil
+  "Non-nil means `delete-pair' pushes mark at end of delimited region."
+  :type 'boolean)
+
 (defun delete-pair (&optional arg)
   "Delete a pair of characters enclosing ARG sexps that follow point.
 A negative ARG deletes a pair around the preceding ARG sexps instead.
-The option `delete-pair-blink-delay' can disable blinking."
+The option `delete-pair-blink-delay' can disable blinking.  With
+`delete-pair-push-mark' enabled, pushes a mark at the end of the
+enclosed region."
   (interactive "P")
   (if arg
       (setq arg (prefix-numeric-value arg))
@@ -887,7 +893,9 @@ delete-pair
 	  (when (and (numberp delete-pair-blink-delay)
 		     (> delete-pair-blink-delay 0))
 	    (sit-for delete-pair-blink-delay))
-	  (delete-char -1)))
+	  (delete-char -1)
+	  (when delete-pair-push-mark
+	    (push-mark))))
       (delete-char 1))))
 
 (defun raise-sexp (&optional n)
-- 
2.39.3 (Apple Git-145)


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

end of thread, other threads:[~2024-09-21 10:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-15 20:58 bug#73284: [PATCH] Add option to push mark after delete-pair Paul Nelson
2024-09-16 11:44 ` Eli Zaretskii
2024-09-16 14:07   ` Paul Nelson
2024-09-17  6:56   ` Juri Linkov
2024-09-17  9:20   ` Sean Whitton
2024-09-21 10:25 ` Eli Zaretskii

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.