aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2019-10-31 10:31:27 +0100
committerMattias EngdegÄrd2019-10-31 17:41:29 +0100
commitd75794fd5c168fb76406b88e231d8749160f934a (patch)
treef2ca99dbdca855ddc4d182658fda10233c44cac3
parent111a95fe6d209aff6e7f26cb6777fbdf02aae15d (diff)
downloademacs-d75794fd5c168fb76406b88e231d8749160f934a.tar.gz
emacs-d75794fd5c168fb76406b88e231d8749160f934a.zip
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.
-rw-r--r--doc/lispref/symbols.texi5
-rw-r--r--doc/lispref/text.texi6
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/mouse.el6
-rw-r--r--lisp/simple.el7
5 files changed, 29 insertions, 1 deletions
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 5d71fb39a25..936bda9b36e 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
590calls. In addition to byte compiler optimizations, this property is 590calls. In addition to byte compiler optimizations, this property is
591also used for determining function safety (@pxref{Function Safety}). 591also used for determining function safety (@pxref{Function Safety}).
592 592
593@item undo-inhibit-region
594If non-@code{nil}, the named function prevents the @code{undo} operation
595from being restricted to the active region, if @code{undo} is invoked
596immediately after the function. @xref{Undo}.
597
593@item variable-documentation 598@item variable-documentation
594If non-@code{nil}, this specifies the named variable's documentation 599If non-@code{nil}, this specifies the named variable's documentation
595string. This is set automatically by @code{defvar} and related 600string. This is set automatically by @code{defvar} and related
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index ac444f6afeb..9bc6213f3ac 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -1451,6 +1451,12 @@ continuing to undo.
1451This function does not bind @code{undo-in-progress}. 1451This function does not bind @code{undo-in-progress}.
1452@end defun 1452@end defun
1453 1453
1454Some commands leave the region active after execution in such a way that
1455it interferes with selective undo of that command. To make @code{undo}
1456ignore the active region when invoked immediately after such a command,
1457set the property @code{undo-inhibit-region} of the command's function
1458symbol to a non-nil value. @xref{Standard Properties}.
1459
1454@node Maintaining Undo 1460@node Maintaining Undo
1455@section Maintaining Undo Lists 1461@section Maintaining Undo Lists
1456 1462
diff --git a/etc/NEWS b/etc/NEWS
index ee73d2414bd..7a76d90ed53 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3102,6 +3102,12 @@ in other packages are now obsolete aliases of 'xor'.
3102Setting this on the first character of a help string disables 3102Setting this on the first character of a help string disables
3103conversions via 'substitute-command-keys'. 3103conversions via 'substitute-command-keys'.
3104 3104
3105+++
3106** 'undo' can be made to ignore the active region for a command
3107by setting 'undo-inhibit-region' symbol property of that command to
3108non-nil. This is used by 'mouse-drag-region' to make the effect
3109easier to undo immediately afterwards.
3110
3105 3111
3106* Changes in Emacs 27.1 on Non-Free Operating Systems 3112* Changes in Emacs 27.1 on Non-Free Operating Systems
3107 3113
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 76fec507e71..4a351f7be25 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1104,6 +1104,12 @@ is dragged over to."
1104 (run-hooks 'mouse-leave-buffer-hook) 1104 (run-hooks 'mouse-leave-buffer-hook)
1105 (mouse-drag-track start-event))) 1105 (mouse-drag-track start-event)))
1106 1106
1107;; Inhibit the region-confinement when undoing mouse-drag-region
1108;; immediately after the command. Otherwise, the selection left
1109;; active around the dragged text would prevent an undo of the whole
1110;; operation.
1111(put 'mouse-drag-region 'undo-inhibit-region t)
1112
1107(defun mouse-posn-property (pos property) 1113(defun mouse-posn-property (pos property)
1108 "Look for a property at click position. 1114 "Look for a property at click position.
1109POS may be either a buffer position or a click position like 1115POS may be either a buffer position or a click position like
diff --git a/lisp/simple.el b/lisp/simple.el
index 29e195bca6c..10aecd651f3 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2508,6 +2508,10 @@ as an argument limits undo to changes within the current region."
2508 (base-buffer (or (buffer-base-buffer) (current-buffer))) 2508 (base-buffer (or (buffer-base-buffer) (current-buffer)))
2509 (recent-save (with-current-buffer base-buffer 2509 (recent-save (with-current-buffer base-buffer
2510 (recent-auto-save-p))) 2510 (recent-auto-save-p)))
2511 ;; Allow certain commands to inhibit an immediately following
2512 ;; undo-in-region.
2513 (inhibit-region (and (symbolp last-command)
2514 (get last-command 'undo-inhibit-region)))
2511 message) 2515 message)
2512 ;; If we get an error in undo-start, 2516 ;; If we get an error in undo-start,
2513 ;; the next command should not be a "consecutive undo". 2517 ;; the next command should not be a "consecutive undo".
@@ -2525,7 +2529,8 @@ as an argument limits undo to changes within the current region."
2525 ;; it shows nothing else happened in between. 2529 ;; it shows nothing else happened in between.
2526 (gethash list undo-equiv-table)))) 2530 (gethash list undo-equiv-table))))
2527 (setq undo-in-region 2531 (setq undo-in-region
2528 (or (region-active-p) (and arg (not (numberp arg))))) 2532 (and (or (region-active-p) (and arg (not (numberp arg))))
2533 (not inhibit-region)))
2529 (if undo-in-region 2534 (if undo-in-region
2530 (undo-start (region-beginning) (region-end)) 2535 (undo-start (region-beginning) (region-end))
2531 (undo-start)) 2536 (undo-start))