>From 49e09eadf09b1848ce3dbe109e557384c99ce94d Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Sun, 29 May 2022 11:45:19 +0530 Subject: [PATCH] delete-selection-mode: Add user option to delete temporary regions only * lisp/delsel.el (delete-selection-temporary-regions-only): Add new user option. (delete-selection-pre-hook): Respect it. * doc/emacs/mark.texi (Using Region): Document the new user option. * etc/NEWS: Announce the new user option. (bug#55692) --- doc/emacs/mark.texi | 7 +++++-- etc/NEWS | 5 +++++ lisp/delsel.el | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi index 91c44d527b..1b53c2c478 100644 --- a/doc/emacs/mark.texi +++ b/doc/emacs/mark.texi @@ -291,13 +291,16 @@ Using Region @cindex Delete Selection mode @cindex mode, Delete Selection @findex delete-selection-mode +@vindex delete-selection-temporary-regions-only By default, text insertion occurs normally even if the mark is active---for example, typing @kbd{a} inserts the character @samp{a}, then deactivates the mark. Delete Selection mode, a minor mode, modifies this behavior: if you enable that mode, then inserting text while the mark is active causes the text in the region to be deleted -first. To toggle Delete Selection mode on or off, type @kbd{M-x -delete-selection-mode}. +first. If you want to replace only temporary regions, set by +mouse-dragging or shift-selection, then change the variable +@code{delete-selection-temporary-regions-only} to @code{t}. To toggle +Delete Selection mode on or off, type @kbd{M-x delete-selection-mode}. @node Mark Ring @section The Mark Ring diff --git a/etc/NEWS b/etc/NEWS index 85a0ee44b9..3016c62db0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -271,6 +271,11 @@ startup. Previously, these functions ignored * Changes in Emacs 29.1 ++++ +** New user option 'delete-selection-temporary-regions-only'. +When non-nil, 'delete-selection-mode' will only delete the temporary +regions (usually set by mouse-dragging or shift-selection). + +++ ** New user option 'switch-to-prev-buffer-skip-regexp'. This should be a regexp or a list of regexps; buffers whose names diff --git a/lisp/delsel.el b/lisp/delsel.el index f5fe7cf793..7ee41ff2a7 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el @@ -64,6 +64,14 @@ delete-selection-save-to-register "If non-nil, deleted region text is stored in this register. Value must be the register (key) to use.") +(defcustom delete-selection-temporary-regions-only nil + "Whether to delete only temporary regions. +When non-nil, typed text only replaces temporary regions (usually +set by mouse-dragging or shift-selection)." + :version "29.1" + :group 'editing-basics + :type 'boolean) + ;;;###autoload (defalias 'pending-delete-mode 'delete-selection-mode) @@ -251,6 +259,10 @@ delete-selection-pre-hook have this property won't delete the selection. See `delete-selection-helper'." (when (and delete-selection-mode (use-region-p) + (if delete-selection-temporary-regions-only + (and (consp transient-mark-mode) + (eq (car transient-mark-mode) 'only)) + t) (not buffer-read-only)) (delete-selection-helper (and (symbolp this-command) (get this-command 'delete-selection))))) -- 2.33.1