[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/undo-fu cad12914a4 15/82: Add 'undo-fu-allow-undo-in-regio
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/undo-fu cad12914a4 15/82: Add 'undo-fu-allow-undo-in-region' option |
Date: |
Thu, 7 Jul 2022 12:04:49 -0400 (EDT) |
branch: elpa/undo-fu
commit cad12914a4556faa116aca1701c381c4e85c38e2
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add 'undo-fu-allow-undo-in-region' option
---
readme.rst | 13 ++++++++++++-
undo-fu.el | 47 +++++++++++++++++++++++++++++++++++++++--------
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/readme.rst b/readme.rst
index 36417f1fe7..1e35085c9a 100644
--- a/readme.rst
+++ b/readme.rst
@@ -74,10 +74,21 @@ Details
until a new chain of undo/redo events is started.
+Customization
+-------------
+
+``undo-fu-allow-undo-in-region``
+ This option exists for users who prefer to trade-off undo/redo functionality
+ with the ability to limit undo to a region.
+
+ When this boolean is ``t``, undoing with a selection
+ will use undo within this region.
+
+
Limitations
===========
-The feature ``undo-in-region`` is currently unsupported.
+The feature ``undo-in-region`` is disabled by default.
Installation
diff --git a/undo-fu.el b/undo-fu.el
index ce4af3270b..83db225c5e 100644
--- a/undo-fu.el
+++ b/undo-fu.el
@@ -43,6 +43,16 @@
;;; Code:
+;; Custom variables.
+
+(defcustom undo-fu-allow-undo-in-region nil
+ "When t, use `undo-in-region' when a selection is present.
+Otherwise `undo-in-region' is never used, since it doesn't support `undo-only',
+causing undo-fu to work with reduced functionality when a selection exists."
+ :group 'undo-fu
+ :type 'boolean)
+
+
;; Internal variables.
;; First undo step in the chain, don't redo past this.
@@ -52,6 +62,9 @@
;; Apply undo/redo constraints to stop redo from undoing or
;; passing the initial undo checkpoint.
(defvar-local undo-fu--respect t)
+;; Initiated an undo-in region (don't use `undo-only').
+;; Only use when `undo-fu-allow-undo-in-region' is true.
+(defvar-local undo-fu--in-region nil)
;; Internal functions/macros.
@@ -59,6 +72,7 @@
(defun undo-fu--checkpoint-disable ()
"Disable check to prevent crossing the initial boundary when redoing."
(setq undo-fu--respect nil)
+ (setq undo-fu--in-region nil)
(setq undo-fu--checkpoint-is-blocking nil)
(setq undo-fu--checkpoint nil))
@@ -152,8 +166,19 @@ Optional argument ARG The number of steps to redo."
;; after running non-undo related commands.
(unless undo-fu--respect
(unless was-undo-or-redo
+ (when undo-fu-allow-undo-in-region
+ (setq undo-fu--in-region nil))
(setq undo-fu--respect t)))
+ (when (region-active-p)
+ (if undo-fu-allow-undo-in-region
+ (progn
+ (message "Undo in region in use. Undo end-point ignored!")
+ (undo-fu--checkpoint-disable)
+ (setq undo-fu--in-region t))
+ ;; Default behavior, just remove selection.
+ (deactivate-mark)))
+
;; Allow crossing the boundary, if we press [keyboard-quit].
;; This allows explicitly over-stepping the boundary, in cases where it's
needed.
(when undo-fu--respect
@@ -197,9 +222,6 @@ Optional argument ARG The number of steps to redo."
(success
(condition-case err
(progn
- ;; 'undo-in-region' unsupported.
- (when transient-mark-mode
- (deactivate-mark))
(undo-fu--with-message-suffix
(if undo-fu--respect
""
@@ -233,11 +255,22 @@ Optional argument ARG the number of steps to undo."
;; after running non-undo related commands.
(unless undo-fu--respect
(unless was-undo-or-redo
+ (when undo-fu-allow-undo-in-region
+ (setq undo-fu--in-region nil))
(setq undo-fu--respect t)))
(when (or undo-fu--checkpoint-is-blocking (not was-undo-or-redo))
(setq undo-fu--checkpoint (cdr buffer-undo-list)))
+ (when (region-active-p)
+ (if undo-fu-allow-undo-in-region
+ (progn
+ (message "Undo in region in use. Undo end-point ignored!")
+ (undo-fu--checkpoint-disable)
+ (setq undo-fu--in-region t))
+ ;; Default behavior, just remove selection.
+ (deactivate-mark)))
+
;; Allow crossing the boundary, if we press [keyboard-quit].
;; This allows explicitly over-stepping the boundary, in cases where it's
needed.
(when undo-fu--respect
@@ -261,15 +294,13 @@ Optional argument ARG the number of steps to undo."
(success
(condition-case err
(progn
- ;; 'undo-in-region' unsupported.
- (when transient-mark-mode
- (deactivate-mark))
-
(undo-fu--with-message-suffix
(if undo-fu--respect
""
" (unconstrained)")
- (undo-only steps))
+ (if undo-fu--in-region
+ (undo steps)
+ (undo-only steps)))
t)
(error (message "%s" (error-message-string err))))))
(when success
- [nongnu] elpa/undo-fu 756a4846b3 06/82: Remove redundant error handling case, (continued)
- [nongnu] elpa/undo-fu 756a4846b3 06/82: Remove redundant error handling case, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu e49ee5bdc3 10/82: Show unconstrained suffix for unconstrained undo/redo, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 9bf729c727 09/82: Support pressing C-g before undo, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu ad8a60f979 28/82: Lazy initialize checkpoint length (minor speedup for linear redo), ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu f883424345 36/82: readme: disable undo-tree in the evil-example, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu f938ee2d94 38/82: Cleanup: pass in 'was-redo' as an argument, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 06772aef15 70/82: Use "undo" group, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu e07fd219a0 74/82: Sync backported functions from Emacs, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu c92261a3b7 80/82: Cleanup: use with-eval-after-load, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 1baca3da6b 03/82: Lookup key for keyboard-quit instead of hard coding in message, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu cad12914a4 15/82: Add 'undo-fu-allow-undo-in-region' option,
ELPA Syncer <=
- [nongnu] elpa/undo-fu a0e111b955 21/82: Add .elisp-autofmt to enable auto-formatting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu d561fa8e0c 23/82: Fix #2 Support linear redo, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 459c90479d 24/82: Release 0.2, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 29a8c3d5a8 32/82: Use more prominent comment sections, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu d81063c96d 42/82: Cleanup: remove unnecessary checkpoint-is-blocking variable, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 0ce9ac3614 53/82: Cleanup: use updated auto-formatting results, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu 20c9d6170a 77/82: Cleanup: simplify checks for clearing the checkpoint, ELPA Syncer, 2022/07/07