emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]