execution of @var{body} so that it can be undone as a single step.
@end defmac
+@vindex undo-inhibit-region
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-@code{nil} value. @xref{Standard Properties}.
+symbol to a non-@code{nil} value. @xref{Standard Properties}. You can
+also set the buffer-local variable @code{undo-inhibit-region} from any
+Lisp function to make the next @code{undo} ignore an active region.
@node Maintaining Undo
@section Maintaining Undo Lists
'read-buffer-function' to determine if the caller intends to switch to
the buffer that this function reads.
++++
+** New buffer-local variable 'undo-inhibit-region'.
+Lisp code can set this to non-nil to tell the next 'undo' command to
+ignore an active region. This allows functions to select a region
+without restricting a subsequent 'undo'. For commands that activate
+the region and never want to restrict 'undo' to that region, it is
+preferable to use the existing 'undo-inhibit-region' symbol property
+instead of this variable.
+
** New function 'merge-ordered-lists'.
Mostly used internally to do a kind of topological sort of
inheritance hierarchies.
"Within a run of consecutive undo commands, list remaining to be undone.
If t, we undid all the way to the end of it.")
+(defvar-local undo-inhibit-region nil
+ "Whether to inhibit the restriction of \\[undo] to the active region.
+
+If this is non-nil, the next invocation of \\[undo] operates on
+the entire buffer even if the region is active. \\[undo] sets
+this variable back to nil after consulting it.
+
+Functions that set the active region can use this variable to
+have a subsequent \\[undo] undo other changes outside the region.
+
+For commands that set the active region and never want to
+restrict \\[undo] to that region, it is preferable to use the
+`undo-inhibit-region' symbol property instead of this variable.")
+
(defun undo--last-change-was-undo-p (undo-list)
(while (and (consp undo-list) (eq (car undo-list) nil))
(setq undo-list (cdr undo-list)))
(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)))
+ (inhibit-region (or undo-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".
;; So set `this-command' to something other than `undo'.
- (setq this-command 'undo-start)
+ (setq this-command 'undo-start
+ ;; Restore region restrictions for subsequent invocations.
+ undo-inhibit-region nil)
;; Here we decide whether to break the undo chain. If the
;; previous command is `undo', we don't call `undo-start', i.e.,
;; don't break the undo chain.