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

* bug#73284: [PATCH] Add option to push mark after delete-pair
  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
                     ` (2 more replies)
  2024-09-21 10:25 ` Eli Zaretskii
  1 sibling, 3 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-09-16 11:44 UTC (permalink / raw)
  To: Paul Nelson; +Cc: 73284

> From: Paul Nelson <ultrono@gmail.com>
> Date: Sun, 15 Sep 2024 22:58:09 +0200
> 
> 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.

Shouldn't this activate the region, instead of forcing users to do
that manually?  Users that have transient-mark-mode enabled (which is
ON by default), will expect that, I think.

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

I don't think doing this by default is a good idea.  Such significant
changes in behavior are better off starting disabled.

Let's see what others think about such optional behavior.

Thanks.





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

* bug#73284: [PATCH] Add option to push mark after delete-pair
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Paul Nelson @ 2024-09-16 14:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73284

Thank you for the feedback.  I'll be happy to hear what others think.

> Shouldn't this activate the region, instead of forcing users to do
> that manually?  Users that have transient-mark-mode enabled (which is
> ON by default), will expect that, I think.

I've been using transient-mark-mode lately, and I actually prefer that
the proposed feature doesn't activate the region automatically, as I
don't always want to operate on the contents immediately.

But I understand your point about user expectations.  We could
accommodate both preferences by expanding the option to accept the
values nil, 'push and 'activate.





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

* bug#73284: [PATCH] Add option to push mark after delete-pair
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2024-09-17  6:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73284, Paul Nelson

>> 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.
>
> Shouldn't this activate the region, instead of forcing users to do
> that manually?  Users that have transient-mark-mode enabled (which is
> ON by default), will expect that, I think.

Please don't activate the region since this command is not related
to region selection.

>> 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.
>
> I don't think doing this by default is a good idea.  Such significant
> changes in behavior are better off starting disabled.
>
> Let's see what others think about such optional behavior.

I use delete-pair all the time, and sometimes indeed occurs the need
to operate on the boundaries of the deleted delimiters afterwards.
A workaround was to select the region before using delete-pair,
and for example reindent it.  But adding an easy way to do the same
after using delete-pair by pushing the mark for 'C-x C-x' would be nice.

This command doesn't use the region and I don't remember a need
to use the mark immediately before or after executing this command,
so it seems safe to push the mark without an option.





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

* bug#73284: [PATCH] Add option to push mark after delete-pair
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Sean Whitton @ 2024-09-17  9:20 UTC (permalink / raw)
  To: Eli Zaretskii, Paul Nelson, 73284

Hello,

The optional behaviour seems useful to me, and without activating the
mark, though I don't use delete-pair myself, so I'm kind of guessing.

(I have TMM turned on.)

-- 
Sean Whitton





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

* bug#73284: [PATCH] Add option to push mark after delete-pair
  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-21 10:25 ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-09-21 10:25 UTC (permalink / raw)
  To: Paul Nelson; +Cc: 73284-done

> From: Paul Nelson <ultrono@gmail.com>
> Date: Sun, 15 Sep 2024 22:58:09 +0200
> 
> 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, installed on master, and closing the bug.

Please in the future make sure any new user options always have the
:version tag.





^ permalink raw reply	[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.