[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master db214ae66c: delete-selection-mode: Add user option to delete temp
From: |
Eli Zaretskii |
Subject: |
master db214ae66c: delete-selection-mode: Add user option to delete temporary regions only |
Date: |
Wed, 1 Jun 2022 12:03:46 -0400 (EDT) |
branch: master
commit db214ae66ceac52ced201e8729a6d026f0518341
Author: Visuwesh <visuweshm@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
delete-selection-mode: Add user option to delete temporary regions only
* lisp/delsel.el (delete-selection-temporary-region): 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 | 13 ++++++++++++-
etc/NEWS | 5 +++++
lisp/delsel.el | 21 ++++++++++++++++++++-
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi
index 91c44d527b..ad25ed6a8a 100644
--- a/doc/emacs/mark.texi
+++ b/doc/emacs/mark.texi
@@ -291,12 +291,23 @@ instead signal an error if the mark is inactive.
@cindex Delete Selection mode
@cindex mode, Delete Selection
@findex delete-selection-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 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
+first. However, you can tune this behavior by customizing the
+@code{delete-selection-temporary-region} option. Its default value is
+@code{nil}, but you can set it to @code{t}, in which case only
+temporarily-active regions will be replaced: those which are set by
+dragging the mouse (@pxref{Setting Mark}) or by shift-selection
+(@pxref{Shift Selection}), as well as by @kbd{C-u C-x C-x} when
+Transient Mark Mode is disabled. You can further tune the behavior by
+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}.
@node Mark Ring
diff --git a/etc/NEWS b/etc/NEWS
index 4d68f066fc..71c19c06b4 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-region'.
+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..c9d3cf269b 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -64,6 +64,19 @@
"If non-nil, deleted region text is stored in this register.
Value must be the register (key) to use.")
+(defcustom delete-selection-temporary-region nil
+ "Whether to delete only temporary regions.
+When non-nil, typed text replaces only the regions set by
+mouse-dragging, shift-selection, and \"\\[universal-argument]
\\[exchange-point-and-mark]\" when
+`transient-mark-mode' is turned off. If the value is the symbol
+`selection', then replace only the regions set by mouse-dragging
+and shift-selection."
+ :version "29.1"
+ :group 'editing-basics
+ :type '(choice (const :tag "Replace all regions" nil)
+ (const :tag "Replace region from mouse, shift-selection, and
\"C-u C-x C-x\"" t)
+ (const :tag "Replace region from mouse and shift-selection"
selection)))
+
;;;###autoload
(defalias 'pending-delete-mode 'delete-selection-mode)
@@ -251,7 +264,13 @@ 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)
- (not buffer-read-only))
+ (not buffer-read-only)
+ (or (null delete-selection-temporary-region)
+ (and delete-selection-temporary-region
+ (consp transient-mark-mode)
+ (eq (car transient-mark-mode) 'only))
+ (and (not (eq delete-selection-temporary-region 'selection))
+ (eq transient-mark-mode 'lambda))))
(delete-selection-helper (and (symbolp this-command)
(get this-command 'delete-selection)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master db214ae66c: delete-selection-mode: Add user option to delete temporary regions only,
Eli Zaretskii <=