From: Okamsn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 73782@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Thu, 24 Oct 2024 03:24:14 +0000 [thread overview]
Message-ID: <d55dcb93-4af4-42e0-839e-c5a23802bdd5@protonmail.com> (raw)
In-Reply-To: <jwved4emzjb.fsf-monnier+emacs@gnu.org>
[-- 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
next prev parent reply other threads:[~2024-10-24 3:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d55dcb93-4af4-42e0-839e-c5a23802bdd5@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=73782@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=okamsn@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.