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: Sat, 26 Oct 2024 18:14:57 +0000 [thread overview]
Message-ID: <036d33f0-f5fc-46f1-aadd-f9d6d8b17d0b@protonmail.com> (raw)
In-Reply-To: <jwvwmhx1ub0.fsf-monnier+emacs@gnu.org>
[-- 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
next prev parent reply other threads:[~2024-10-26 18:14 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
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 [this message]
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=036d33f0-f5fc-46f1-aadd-f9d6d8b17d0b@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.