]> git.eshelyaron.com Git - emacs.git/commitdiff
Add delete-selection-local-mode.
authorEarl Hyatt <okamsn@protonmail.com>
Sun, 13 Oct 2024 00:28:25 +0000 (20:28 -0400)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Oct 2024 09:52:15 +0000 (10:52 +0100)
* 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'.

(cherry picked from commit e0b21b6c4de4d7f0b7ad9ae112755435f501835e)

doc/emacs/mark.texi
etc/NEWS
lisp/delsel.el

index 0d705769f55d11c0501f61b31f0cf623855a2053..83261d3649565e084e2e9016417ce11c2d6b9b73 100644 (file)
@@ -306,6 +306,7 @@ instead signal an error if the mark is inactive.
 @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 @@ setting @code{delete-selection-temporary-region} to @code{selection}:
 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
index b16d415aad1d9df92f7a8abdb741e0dd6e5cd980..8526a80da5e659b19fde63b30a45a901f3f31811 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -156,6 +156,13 @@ 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'.
+This mode sets 'delete-selection-mode' buffer-locally.  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.
+
 \f
 * Changes in Specialized Modes and Packages in Emacs 31.1
 
index 8a7002eb965bf660884a4ac5508e6c72c919e77f..130fdfbe851621bf32c118f00a8fa2e6bfa89cb5 100644 (file)
@@ -95,6 +95,24 @@ information on adapting behavior of commands in 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