all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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; 3+ 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] 3+ 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; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2024-10-17 17:07 UTC | newest]

Thread overview: 3+ 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

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.