* bug#73782: [PATCH] Add `delete-selection-local-mode'.
@ 2024-10-13 1:25 Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 5:38 ` Eli Zaretskii
2024-10-17 17:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 7+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-13 1:25 UTC (permalink / raw)
To: 73782
[-- Attachment #1: Type: text/plain, Size: 611 bytes --]
Hello,
This patch adds a local version of `delete-selection-mode`. I use a
modal editing package for which I would like to have
`delete-selection-mode` enabled depending on the modal state that is
active in the buffer. This doesn't currently work because
`delete-selection-mode` applies to all buffers.
For compatibility, I made the local mode set the value of the variable
`delete-selection-mode` buffer locally. I see that some features, such
as the built-in `table.el`, check that variable to adjust their
behavior. Do you think that is a good way to maintain compatibility?
Thank you.
[-- Attachment #2: 0001-Add-delete-selection-local-mode.patch --]
[-- Type: text/x-patch, Size: 1959 bytes --]
From 1ee5897e0177ac86026a7656ce05be4ab97bb10f Mon Sep 17 00:00:00 2001
From: Earl Hyatt <okamsn@protonmail.com>
Date: Sat, 12 Oct 2024 20:28:25 -0400
Subject: [PATCH] Add delete-selection-local-mode.
* lisp/delsel.el (delete-selection-local-mode): Add local version
of delete-selection-mode.
* lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
is active.
---
lisp/delsel.el | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/lisp/delsel.el b/lisp/delsel.el
index df99a56d7bc..b4cc6745603 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -95,6 +95,22 @@ delete-selection-mode
(remove-hook 'pre-command-hook 'delete-selection-pre-hook)
(add-hook 'pre-command-hook 'delete-selection-pre-hook)))
+;;;###autoload
+(define-minor-mode delete-selection-local-mode
+ "Toggle Delete Selection mode in the current buffer.
+
+See the command `delete-selection-mode'.
+
+For compatibility with features and packages that are aware of
+`delete-selection-mode', this mode also sets the
+variable `delete-selection-mode' in the current buffer."
+ :global nil :group 'editing-basics
+ (remove-hook 'pre-command-hook 'delete-selection-pre-hook t)
+ (setq-local delete-selection-mode nil)
+ (when delete-selection-local-mode
+ (add-hook 'pre-command-hook 'delete-selection-pre-hook t)
+ (setq-local delete-selection-mode t)))
+
(defvar delsel--replace-text-or-position nil)
;;;###autoload
@@ -264,7 +280,8 @@ delete-selection-pre-hook
property on their symbol; commands which insert text but don't
have this property won't delete the selection.
See `delete-selection-helper'."
- (when (and delete-selection-mode (use-region-p)
+ (when (and (or delete-selection-mode delete-selection-local-mode)
+ (use-region-p)
(not buffer-read-only)
(or (null delete-selection-temporary-region)
(and delete-selection-temporary-region
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-13 1:25 bug#73782: [PATCH] Add `delete-selection-local-mode' Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-13 5:38 ` Eli Zaretskii
2024-10-17 17:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-10-13 5:38 UTC (permalink / raw)
To: Okamsn, Stefan Monnier; +Cc: 73782
> Date: Sun, 13 Oct 2024 01:25:28 +0000
> From: Okamsn via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> This patch adds a local version of `delete-selection-mode`. I use a
> modal editing package for which I would like to have
> `delete-selection-mode` enabled depending on the modal state that is
> active in the buffer. This doesn't currently work because
> `delete-selection-mode` applies to all buffers.
Thanks. This feature needs a NEWS entry, and maybe also a suitable
change to the user manual.
> For compatibility, I made the local mode set the value of the variable
> `delete-selection-mode` buffer locally. I see that some features, such
> as the built-in `table.el`, check that variable to adjust their
> behavior. Do you think that is a good way to maintain compatibility?
SGTM, but I'd like to hear from Stefan (CC'ed) as well.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-13 1:25 bug#73782: [PATCH] Add `delete-selection-local-mode' Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 5:38 ` Eli Zaretskii
@ 2024-10-17 17:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 3:24 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-17 17:07 UTC (permalink / raw)
To: Okamsn; +Cc: 73782
> +(define-minor-mode delete-selection-local-mode
> + "Toggle Delete Selection mode in the current buffer.
> +
> +See the command `delete-selection-mode'.
> +
> +For compatibility with features and packages that are aware of
> +`delete-selection-mode', this mode also sets the
> +variable `delete-selection-mode' in the current buffer."
> + :global nil :group 'editing-basics
Have you tried to use the `:variable (buffer-local-value
'delete-selection-mode)` instead of introducing a parallel
`delete-selection-local-mode` variable?
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-17 17:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-24 3:24 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 7+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-24 3:24 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 73782, Eli Zaretskii
[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]
Stefan Monnier wrote:
>> +(define-minor-mode delete-selection-local-mode
>> + "Toggle Delete Selection mode in the current buffer.
>> +
>> +See the command `delete-selection-mode'.
>> +
>> +For compatibility with features and packages that are aware of
>> +`delete-selection-mode', this mode also sets the
>> +variable `delete-selection-mode' in the current buffer."
>> + :global nil :group 'editing-basics
>
> Have you tried to use the `:variable (buffer-local-value
> 'delete-selection-mode)` instead of introducing a parallel
> `delete-selection-local-mode` variable?
>
>
> Stefan
>
I had not thought to try that. Attached is a patch which uses
`buffer-local-value` as a `setf`-able place. I had to include the third
argument `(current-buffer)`.
Do you think that disabling the local mode should remove the
buffer-local version of `delete-selection-mode` via
`kill-local-variable`? It seems that once the variable is made buffer
local, the global mode can't take effect in the buffer, even when the
local mode is disabled.
If you do think that the local version of the variable should be
removed, do you think that it should be removed selectively or always?
Thank you.
[-- Attachment #2: v3-0001-Add-delete-selection-local-mode.patch --]
[-- Type: text/x-patch, Size: 3754 bytes --]
From 900131edb9337bed3b624a80295c2e95cb75e24d Mon Sep 17 00:00:00 2001
From: Earl Hyatt <okamsn@protonmail.com>
Date: Sat, 12 Oct 2024 20:28:25 -0400
Subject: [PATCH v3] Add delete-selection-local-mode.
* lisp/delsel.el (delete-selection-local-mode): Add local version of
delete-selection-mode. The local mode sets the value of the variable
'delete-selection-mode' to maintain compatibility with packages and
features that consider the existing mode.
* lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
is active.
* doc/emacs/mark.texi (Using Region): Describe
delete-selection-local-mode.
* etc/NEWS: Describe delete-selection-local-mode.
---
doc/emacs/mark.texi | 4 +++-
etc/NEWS | 11 +++++++++++
lisp/delsel.el | 15 +++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi
index 0d705769f55..83261d36495 100644
--- a/doc/emacs/mark.texi
+++ b/doc/emacs/mark.texi
@@ -306,6 +306,7 @@ Using Region
@cindex Delete Selection mode
@cindex mode, Delete Selection
@findex delete-selection-mode
+@findex delete-selection-local-mode
@vindex delete-selection-temporary-region
By default, text insertion occurs normally even if the mark is
active---for example, typing @kbd{a} inserts the character @samp{a},
@@ -323,7 +324,8 @@ Using Region
then temporary regions by @kbd{C-u C-x C-x} won't be replaced, only
the ones activated by dragging the mouse or shift-selection. To
toggle Delete Selection mode on or off, type @kbd{M-x
-delete-selection-mode}.
+delete-selection-mode}. To toggle Delete Selection mode on or off
+in the current buffer only, type @kbd{M-x delete-selection-local-mode}.
@node Mark Ring
@section The Mark Ring
diff --git a/etc/NEWS b/etc/NEWS
index daaae54d7d3..ea36f3002e9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -204,6 +204,17 @@ a prefix argument when inserting one of the delimiters.
Typing M-~ while saving some buffers means not to save the buffer and
also to mark it as unmodified. This is an alternative way to mark a
buffer as unmodified which doesn't require switching to that buffer.
+
+** New minor mode 'delete-selection-local-mode'.
+'delete-selection-local-mode' is a buffer-local version of the existing
+'delete-selection-mode'. This can be useful for enabling or disabling
+the features of 'delete-selection-mode' based on the state of the
+buffer, such as for the different states of modal editing packages.
+
+For compatibility with features and packages that are aware of the
+existing 'delete-selection-mode', 'delete-selection-local-mode' will set
+the value of the variable 'delete-selection-mode' buffer locally when
+enabled or disabled.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/delsel.el b/lisp/delsel.el
index df99a56d7bc..5a492999585 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -95,6 +95,21 @@ delete-selection-mode
(remove-hook 'pre-command-hook 'delete-selection-pre-hook)
(add-hook 'pre-command-hook 'delete-selection-pre-hook)))
+;;;###autoload
+(define-minor-mode delete-selection-local-mode
+ "Toggle Delete Selection mode in the current buffer.
+
+See the command `delete-selection-mode'.
+
+For compatibility with features and packages that are aware of
+`delete-selection-mode', this mode sets the variable
+`delete-selection-mode' in the current buffer."
+ :global nil :group 'editing-basics
+ :variable (buffer-local-value 'delete-selection-mode (current-buffer))
+ (remove-hook 'pre-command-hook 'delete-selection-pre-hook t)
+ (when delete-selection-mode
+ (add-hook 'pre-command-hook 'delete-selection-pre-hook t)))
+
(defvar delsel--replace-text-or-position nil)
;;;###autoload
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-24 3:24 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-24 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 18:14 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-24 14:01 UTC (permalink / raw)
To: Okamsn; +Cc: 73782, Eli Zaretskii
> Do you think that disabling the local mode should remove the
> buffer-local version of `delete-selection-mode` via
> `kill-local-variable`? It seems that once the variable is made buffer
> local, the global mode can't take effect in the buffer, even when the
> local mode is disabled.
In `electric-indent-local-mode` I faced the same question and wasn't
completely sure but I opted somewhat arbitrarily to do the
`kill-local-variable` whenever applicable.
I still don't know if it's the better choice, but FWIW, nobody's
complained about it:
(cond
((eq electric-indent-mode (default-value 'electric-indent-mode))
(kill-local-variable 'electric-indent-mode))
> * lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
> is active.
AFAICT you don't change `delete-selection-pre-hook` any more.
> * doc/emacs/mark.texi (Using Region): Describe
> delete-selection-local-mode.
> +;;;###autoload
> +(define-minor-mode delete-selection-local-mode
> + "Toggle Delete Selection mode in the current buffer.
> +
> +See the command `delete-selection-mode'.
FWIW, for `electric-indent-local-mode` I went for something shorter:
"Toggle `electric-indent-mode' only in this buffer."
- Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-24 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-26 18:14 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 18:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 7+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-26 18:14 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 73782, Eli Zaretskii
[-- Attachment #1: Type: text/plain, Size: 1435 bytes --]
Stefan Monnier wrote:
>> Do you think that disabling the local mode should remove the
>> buffer-local version of `delete-selection-mode` via
>> `kill-local-variable`? It seems that once the variable is made buffer
>> local, the global mode can't take effect in the buffer, even when the
>> local mode is disabled.
>
> In `electric-indent-local-mode` I faced the same question and wasn't
> completely sure but I opted somewhat arbitrarily to do the
> `kill-local-variable` whenever applicable.
> I still don't know if it's the better choice, but FWIW, nobody's
> complained about it:
>
> (cond
> ((eq electric-indent-mode (default-value 'electric-indent-mode))
> (kill-local-variable 'electric-indent-mode))
>
>> * lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
>> is active.
>
> AFAICT you don't change `delete-selection-pre-hook` any more.
>
>> * doc/emacs/mark.texi (Using Region): Describe
>> delete-selection-local-mode.
>> +;;;###autoload
>> +(define-minor-mode delete-selection-local-mode
>> + "Toggle Delete Selection mode in the current buffer.
>> +
>> +See the command `delete-selection-mode'.
>
> FWIW, for `electric-indent-local-mode` I went for something shorter:
>
> "Toggle `electric-indent-mode' only in this buffer."
>
>
> - Stefan
>
Hello,
Please see the attached patch with the changes you suggested.
Thank you.
[-- Attachment #2: v4-0001-Add-delete-selection-local-mode.patch --]
[-- Type: text/x-patch, Size: 3859 bytes --]
From 52d8ac478ef015e6875faa6e0c76dc3009fa5960 Mon Sep 17 00:00:00 2001
From: Earl Hyatt <okamsn@protonmail.com>
Date: Sat, 12 Oct 2024 20:28:25 -0400
Subject: [PATCH v4] Add delete-selection-local-mode.
* lisp/delsel.el (delete-selection-local-mode): Add local version of
'delete-selection-mode'. The local mode sets the value of the variable
'delete-selection-mode' to maintain compatibility with packages and
features that consider the existing mode.
* doc/emacs/mark.texi (Using Region): Describe
'delete-selection-local-mode'.
* etc/NEWS: Describe 'delete-selection-local-mode'.
---
doc/emacs/mark.texi | 4 +++-
etc/NEWS | 11 +++++++++++
lisp/delsel.el | 18 ++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi
index 0d705769f55..83261d36495 100644
--- a/doc/emacs/mark.texi
+++ b/doc/emacs/mark.texi
@@ -306,6 +306,7 @@ Using Region
@cindex Delete Selection mode
@cindex mode, Delete Selection
@findex delete-selection-mode
+@findex delete-selection-local-mode
@vindex delete-selection-temporary-region
By default, text insertion occurs normally even if the mark is
active---for example, typing @kbd{a} inserts the character @samp{a},
@@ -323,7 +324,8 @@ Using Region
then temporary regions by @kbd{C-u C-x C-x} won't be replaced, only
the ones activated by dragging the mouse or shift-selection. To
toggle Delete Selection mode on or off, type @kbd{M-x
-delete-selection-mode}.
+delete-selection-mode}. To toggle Delete Selection mode on or off
+in the current buffer only, type @kbd{M-x delete-selection-local-mode}.
@node Mark Ring
@section The Mark Ring
diff --git a/etc/NEWS b/etc/NEWS
index daaae54d7d3..40d626644b2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -204,6 +204,17 @@ a prefix argument when inserting one of the delimiters.
Typing M-~ while saving some buffers means not to save the buffer and
also to mark it as unmodified. This is an alternative way to mark a
buffer as unmodified which doesn't require switching to that buffer.
+
+** New minor mode 'delete-selection-local-mode'.
+'delete-selection-local-mode' is a buffer-local version of the existing
+'delete-selection-mode'. This can be useful for enabling or disabling
+the features of 'delete-selection-mode' based on the state of the
+buffer, such as for the different states of modal editing packages.
+
+For compatibility with features and packages that are aware of the
+existing 'delete-selection-mode', 'delete-selection-local-mode' will set
+the value of the variable 'delete-selection-mode' buffer locally as
+needed.
\f
* Changes in Specialized Modes and Packages in Emacs 31.1
diff --git a/lisp/delsel.el b/lisp/delsel.el
index df99a56d7bc..18d889ab4c8 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -95,6 +95,24 @@ delete-selection-mode
(remove-hook 'pre-command-hook 'delete-selection-pre-hook)
(add-hook 'pre-command-hook 'delete-selection-pre-hook)))
+;;;###autoload
+(define-minor-mode delete-selection-local-mode
+ "Toggle `delete-selection-mode' only in this buffer.
+
+For compatibility with features and packages that are aware of
+`delete-selection-mode', this local mode sets the variable
+`delete-selection-mode' in the current buffer as needed."
+ :global nil :group 'editing-basics
+ :variable (buffer-local-value 'delete-selection-mode (current-buffer))
+ (cond
+ ((eq delete-selection-mode (default-value 'delete-selection-mode))
+ (kill-local-variable 'delete-selection-mode))
+ ((not (default-value 'delete-selection-mode))
+ ;; Locally enabled, but globally disabled.
+ (delete-selection-mode 1) ; Setup the hooks.
+ (setq-default delete-selection-mode nil) ; But keep it globally disabled.
+ )))
+
(defvar delsel--replace-text-or-position nil)
;;;###autoload
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#73782: [PATCH] Add `delete-selection-local-mode'.
2024-10-26 18:14 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-26 18:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-26 18:53 UTC (permalink / raw)
To: Okamsn; +Cc: 73782-done, Eli Zaretskii
> Please see the attached patch with the changes you suggested.
Thanks, pushed, closing,
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-26 18:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-13 1:25 bug#73782: [PATCH] Add `delete-selection-local-mode' Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 5:38 ` Eli Zaretskii
2024-10-17 17:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 3:24 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 18:14 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 18:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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.