[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree f0a6192 184/195: Proper fix to copy-undo-tree
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree f0a6192 184/195: Proper fix to copy-undo-tree by writing bespoke copier. |
Date: |
Sat, 28 Nov 2020 13:41:49 -0500 (EST) |
branch: externals/undo-tree
commit f0a6192210127b3e0375928b6ac18921ff12e8a2
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Proper fix to copy-undo-tree by writing bespoke copier.
Previous fix didn't copy current node correctly.
---
undo-tree.el | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index bf5b5c1..2c23e2b 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -1332,7 +1332,6 @@ in visualizer."
(defstruct
(undo-tree
:named
- (:type vector) ; needed for `copy-undo-tree' implementation
(:constructor nil)
(:constructor make-undo-tree
(&aux
@@ -1345,14 +1344,24 @@ in visualizer."
root current size count object-pool)
(defun copy-undo-tree (tree)
+ ;; Return a copy of undo-tree TREE.
(unwind-protect
- (progn
+ (let ((new (make-undo-tree)))
(undo-tree-decircle tree)
- (copy-tree tree 'copy-vectors))
+ (setf (undo-tree-root new)
+ (copy-undo-tree-node (undo-tree-root tree)
+ new (undo-tree-current tree)))
+ (setf (undo-tree-size new)
+ (undo-tree-size tree))
+ (setf (undo-tree-count new)
+ (undo-tree-count tree))
+ (setf (undo-tree-object-pool new)
+ (copy-hash-table (undo-tree-object-pool tree)))
+ (undo-tree-recircle new)
+ new)
(undo-tree-recircle tree)))
-
(defstruct
(undo-tree-node
(:type vector) ; create unnamed struct
@@ -1378,6 +1387,25 @@ in visualizer."
(let ((len (length (undo-tree-make-node nil nil))))
`(and (vectorp ,n) (= (length ,n) ,len))))
+(defun copy-undo-tree-node (node &optional tree current)
+ ;; Return a copy of undo-tree NODE, sans previous link or meta-data.
+ ;; If TREE and CURRENT are supplied, set (undo-tree-current TREE) to the
+ ;; copy of CURRENT node, if found.
+ (let ((new (undo-tree-make-node
+ nil (copy-tree (undo-tree-node-undo node) 'copy-vectors)
+ (copy-tree (undo-tree-node-redo node) 'copy-vectors))))
+ (setf (undo-tree-node-timestamp new)
+ (copy-sequence (undo-tree-node-timestamp node)))
+ (setf (undo-tree-node-branch new)
+ (undo-tree-node-branch node))
+ ;; recursively copy next nodes
+ (setf (undo-tree-node-next new)
+ (mapcar (lambda (n) (copy-undo-tree-node n tree current))
+ (undo-tree-node-next node)))
+ ;; set (undo-tree-current TREE) to copy if we've found CURRENT
+ (when (and tree (eq node current))
+ (setf (undo-tree-current tree) new))
+ new))
(defstruct
- [elpa] externals/undo-tree b35a6af 160/195: Bump copyright year and version number., (continued)
- [elpa] externals/undo-tree b35a6af 160/195: Bump copyright year and version number., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree a3e81b6 161/195: Fix bug that caused undo-tree to hang when undoing in region (bug#16377)., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2947d7c 169/195: Add hooks to transform/discard undo elements on saving/loading., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree c3d04ea 165/195: Change obsolete subtract-time -> time-subtract., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree af99ee3 166/195: Uncoditionally clear visualizer data before writing to file., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f6471ef 173/195: Simplify undo-list-byte-size., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ea165ed 174/195: Refactor undo-list-transfer-to-tree to not act directly on buffer-undo-list., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8842bb5 176/195: More undo-tree GC corruption mitigations., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f6f557c 178/195: Fix various bugs in undo history loading/saving., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b8652b4 180/195: Null undo-tree-limit attemps to preserve all undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f0a6192 184/195: Proper fix to copy-undo-tree by writing bespoke copier.,
Stefan Monnier <=
- [elpa] externals/undo-tree 3090c4f 185/195: Temporarily increase max-lisp-eval-depth and max-specpdl-size when copying undo-trees., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8cf384f 187/195: Redraw visualizer when history-discarding invalidates it., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree d79fab9 193/195: Switch from cl to cl-lib., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bd65bb0 192/195: Fix hook function issue in Emacs 27., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e01a3e7 191/195: Fix some byte-compilation warnings., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 17454bd 084/195: Improved undo-tree-switch-branch behaviour., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f16ab5f 067/195: Trivial fix in Commentary., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e8215a7 078/195: Minor typo fixes in comments., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8697a0b 077/195: Clear registers referring to nodes being discarded from undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f956d55 074/195: Added autoload cookies, and other tweaks to prepare for ELPA packaging., Stefan Monnier, 2020/11/28