[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/undo-fu-session e2043f8350 10/53: Add `undo-fu-session-lin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/undo-fu-session e2043f8350 10/53: Add `undo-fu-session-linear` option |
Date: |
Thu, 7 Jul 2022 12:05:15 -0400 (EDT) |
branch: elpa/undo-fu-session
commit e2043f8350970e1a9ef06a94956a733826cdf32b
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add `undo-fu-session-linear` option
Optionally write out linear undo history
(omitting branches of the undo stack which have themselves been undone).
---
changelog.rst | 14 +++++++++++
readme.rst | 4 +++
undo-fu-session.el | 74 ++++++++++++++++++++++++++++++++++++++++++++----------
3 files changed, 79 insertions(+), 13 deletions(-)
diff --git a/changelog.rst b/changelog.rst
new file mode 100644
index 0000000000..69c02d2309
--- /dev/null
+++ b/changelog.rst
@@ -0,0 +1,14 @@
+
+##########
+Change Log
+##########
+
+- Version 0.2 (2020-05-17)
+
+ - Add ``undo-fu-session-linear`` to optionally write linear undo history.
+ - Fix ``global-undo-fu-session`` activating with the mini-buffer.
+ - Fix loading the undo session clearing the ``undo-equiv-table`` for other
buffers.
+
+- Version 0.1 (2020-01-27)
+
+ Initial release.
diff --git a/readme.rst b/readme.rst
index 6454e620d9..5880645b51 100644
--- a/readme.rst
+++ b/readme.rst
@@ -76,6 +76,10 @@ Customization
``undo-fu-session-directory`` (``"undo-fu-session"`` in emacs user directory)
The location of stored files.
+``undo-fu-session-linear`` (``nil``)
+ Write linear undo history, omitting branches which were themselves undone.
+
+ Note that this only writes undo steps which would be used by ``undo-only``.
``undo-fu-session-compression`` (``t``)
Store files compressed.
``undo-fu-session-incompatible-files`` (``'()``)
diff --git a/undo-fu-session.el b/undo-fu-session.el
index 5267353416..54dd5a989e 100644
--- a/undo-fu-session.el
+++ b/undo-fu-session.el
@@ -7,7 +7,7 @@
;; URL: https://gitlab.com/ideasman42/emacs-undo-fu-session
;; Keywords: convenience
-;; Version: 0.1
+;; Version: 0.2
;; Package-Requires: ((emacs "24.1"))
;; This program is free software; you can redistribute it and/or modify
@@ -58,6 +58,11 @@
"Persistent undo steps, stored on disk between sessions."
:group 'convenience)
+(defcustom undo-fu-session-linear nil
+ "Store linear history (without redo)."
+ :group 'undo-fu-session
+ :type 'boolean)
+
(defcustom undo-fu-session-directory
(locate-user-emacs-file "undo-fu-session" ".emacs-undo-fu-session")
"The directory to store undo data."
@@ -86,6 +91,32 @@ Enforcing removes the oldest files."
:type 'integer
:group 'undo-fu-session)
+;; ---------------------------------------------------------------------------
+;; Undo List Make Linear
+;;
+;; Note that this only works for `buffer-undo-list', not `pending-undo-list'.
+
+(defun undo-fu-session--linear-undo-list (undo-list equiv-table)
+ (let ((linear-list nil))
+ (while
+ ;; Collapse all redo branches (giving the same results as if running
'undo-only')
+ (let ((undo-list-next nil))
+ (while (setq undo-list-next (gethash undo-list equiv-table))
+ (setq undo-list undo-list-next))
+ (and undo-list (not (eq t undo-list))))
+
+ ;; Pop all steps until the next boundary 'nil'.
+ (let ((undo-elt t))
+ (while undo-elt
+ (setq undo-elt (pop undo-list))
+ (push undo-elt linear-list))))
+
+ ;; Pass through 't', when there is no undo information.
+ ;; Also convert '(list nil)' to 't', since this is no undo info too.
+ (if (and linear-list (not (equal (list nil) linear-list)))
+ (nreverse linear-list)
+ t)))
+
;; ---------------------------------------------------------------------------
;; Undo Encode/Decode Functionality
@@ -348,18 +379,35 @@ Argument PENDING-LIST an `pending-undo-list'. compatible
list."
(unless (or (consp buffer-undo-list) (consp pending-undo-list))
(throw 'exit nil))
- (setq content-header `((buffer-size . ,(buffer-size)) (buffer-checksum .
,(sha1 buffer))))
- (setq content-data
- `
- ((emacs-pending-undo-list . ,(undo-fu-session--encode
pending-undo-list))
- (emacs-buffer-undo-list . ,(undo-fu-session--encode
buffer-undo-list))
- (emacs-undo-equiv-table
- .
- ,
- (undo-fu-session--equivtable-encode
- undo-equiv-table
- buffer-undo-list
- pending-undo-list)))))
+ (let
+ ( ;; Variables to build the 'content-data'.
+ (emacs-pending-undo-list nil)
+ (emacs-buffer-undo-list nil)
+ (emacs-undo-equiv-table nil))
+
+ (cond
+ ;; Simplified linear history (no redo).
+ (undo-fu-session-linear
+ (setq emacs-buffer-undo-list
+ (undo-fu-session--encode
+ (undo-fu-session--linear-undo-list buffer-undo-list
undo-equiv-table))))
+ ;; Full non-linear history (full undo/redo).
+ (t
+ (setq emacs-buffer-undo-list (undo-fu-session--encode
buffer-undo-list))
+ (setq emacs-pending-undo-list (undo-fu-session--encode
pending-undo-list))
+ (setq emacs-undo-equiv-table
+ (undo-fu-session--equivtable-encode
+ undo-equiv-table
+ buffer-undo-list
+ pending-undo-list))))
+
+ (setq content-header
+ (list (cons 'buffer-size (buffer-size)) (cons 'buffer-checksum (sha1
buffer))))
+ (setq content-data
+ (list
+ (cons 'emacs-buffer-undo-list emacs-buffer-undo-list)
+ (cons 'emacs-pending-undo-list emacs-pending-undo-list)
+ (cons 'emacs-undo-equiv-table emacs-undo-equiv-table)))))
(when content-data
(setq undo-file (undo-fu-session--make-file-name filename))
- [nongnu] branch elpa/undo-fu-session created (now 52c71b1cee), ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session b808ef0cdc 08/53: Fix global-undo-fu-session activating with the minibuffer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session f0f8e2443f 27/53: Use group "undo", ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session f9589be462 22/53: Global mode is no longer enables in special-modes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 2424ad50ff 04/53: Use 'string-match-p' to avoid changing match data, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 35d4cf3771 07/53: Update commentary to make it more useful., ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session e2043f8350 10/53: Add `undo-fu-session-linear` option,
ELPA Syncer <=
- [nongnu] elpa/undo-fu-session 39f9b1997e 13/53: Ignore encrypted files by default, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session fddcc75a58 01/53: Initial commit., ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 98a8cc6396 14/53: Add missing docstring, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 243d93b4c7 21/53: Cleanup: formatting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session dae6dfbc7d 28/53: Cleanup: docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session a6a23301a4 30/53: Fix #2: resolve potential security issue with file permissions, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 7bbc89a42f 36/53: Build linear-list in-order instead of reversing, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 2fe1efcfa1 37/53: Shorten message, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 5862b90b9c 38/53: Cleanup: use file-name-concat for clarity, ELPA Syncer, 2022/07/07
- [nongnu] elpa/undo-fu-session 56d3134287 40/53: Cleanup: use simpler syntax to construct the overlay list, ELPA Syncer, 2022/07/07