[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d75794f: Inhibit undo-in-region for mouse-drag-region (bug#37700)
From: |
Mattias Engdegård |
Subject: |
master d75794f: Inhibit undo-in-region for mouse-drag-region (bug#37700) |
Date: |
Thu, 31 Oct 2019 12:45:55 -0400 (EDT) |
branch: master
commit d75794fd5c168fb76406b88e231d8749160f934a
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Inhibit undo-in-region for mouse-drag-region (bug#37700)
'mouse-drag-region' leaves the region active around the dragged text,
so a straight undo did not revert the entire operation. To remedy
this, inhibit undo-in-region when the last command was
mouse-drag-region. (Method suggested by Stefan Monnier.)
* lisp/mouse.el (undo-drag-region): Set the undo-inhibit-region property.
* lisp/simple.el (undo): Inhibit undo-in-region if the last command
had the undo-inhibit-region property set.
* doc/lispref/symbols.texi (Standard Properties):
* doc/lispref/text.texi (Undo): Document undo-inhibit-region.
* etc/NEWS: Announce the property.
---
doc/lispref/symbols.texi | 5 +++++
doc/lispref/text.texi | 6 ++++++
etc/NEWS | 6 ++++++
lisp/mouse.el | 6 ++++++
lisp/simple.el | 7 ++++++-
5 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 5d71fb3..936bda9 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -590,6 +590,11 @@ ignore a call whose value is unused. If the property's
value is
calls. In addition to byte compiler optimizations, this property is
also used for determining function safety (@pxref{Function Safety}).
+@item undo-inhibit-region
+If non-@code{nil}, the named function prevents the @code{undo} operation
+from being restricted to the active region, if @code{undo} is invoked
+immediately after the function. @xref{Undo}.
+
@item variable-documentation
If non-@code{nil}, this specifies the named variable's documentation
string. This is set automatically by @code{defvar} and related
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index ac444f6..9bc6213 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -1451,6 +1451,12 @@ continuing to undo.
This function does not bind @code{undo-in-progress}.
@end defun
+Some commands leave the region active after execution in such a way that
+it interferes with selective undo of that command. To make @code{undo}
+ignore the active region when invoked immediately after such a command,
+set the property @code{undo-inhibit-region} of the command's function
+symbol to a non-nil value. @xref{Standard Properties}.
+
@node Maintaining Undo
@section Maintaining Undo Lists
diff --git a/etc/NEWS b/etc/NEWS
index ee73d24..7a76d90 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3102,6 +3102,12 @@ in other packages are now obsolete aliases of 'xor'.
Setting this on the first character of a help string disables
conversions via 'substitute-command-keys'.
++++
+** 'undo' can be made to ignore the active region for a command
+by setting 'undo-inhibit-region' symbol property of that command to
+non-nil. This is used by 'mouse-drag-region' to make the effect
+easier to undo immediately afterwards.
+
* Changes in Emacs 27.1 on Non-Free Operating Systems
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 76fec50..4a351f7 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1104,6 +1104,12 @@ is dragged over to."
(run-hooks 'mouse-leave-buffer-hook)
(mouse-drag-track start-event)))
+;; Inhibit the region-confinement when undoing mouse-drag-region
+;; immediately after the command. Otherwise, the selection left
+;; active around the dragged text would prevent an undo of the whole
+;; operation.
+(put 'mouse-drag-region 'undo-inhibit-region t)
+
(defun mouse-posn-property (pos property)
"Look for a property at click position.
POS may be either a buffer position or a click position like
diff --git a/lisp/simple.el b/lisp/simple.el
index 29e195b..10aecd6 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2508,6 +2508,10 @@ as an argument limits undo to changes within the current
region."
(base-buffer (or (buffer-base-buffer) (current-buffer)))
(recent-save (with-current-buffer base-buffer
(recent-auto-save-p)))
+ ;; Allow certain commands to inhibit an immediately following
+ ;; undo-in-region.
+ (inhibit-region (and (symbolp last-command)
+ (get last-command 'undo-inhibit-region)))
message)
;; If we get an error in undo-start,
;; the next command should not be a "consecutive undo".
@@ -2525,7 +2529,8 @@ as an argument limits undo to changes within the current
region."
;; it shows nothing else happened in between.
(gethash list undo-equiv-table))))
(setq undo-in-region
- (or (region-active-p) (and arg (not (numberp arg)))))
+ (and (or (region-active-p) (and arg (not (numberp arg))))
+ (not inhibit-region)))
(if undo-in-region
(undo-start (region-beginning) (region-end))
(undo-start))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master d75794f: Inhibit undo-in-region for mouse-drag-region (bug#37700),
Mattias Engdegård <=