* 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)
@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},
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
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
(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