branch: externals/persist
commit 2f9b5de9d33b8503e84b8394ff0c261a475cacb3
Author: Joseph Turner <jos...@breatheoutbreathe.in>
Commit: Philip Kaludercic <phil...@posteo.net>

    Copy default when resetting with persist-reset
    
    Previously, persist-reset set the value of SYM to its default without
    copying it, which caused subsequent modifications to the value of SYM
    to erroneously modify the default value.
    
    Co-authored-by: Adam Porter <a...@alphapapa.net>
---
 persist.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/persist.el b/persist.el
index 6cc94b4db3..df7f3836c5 100644
--- a/persist.el
+++ b/persist.el
@@ -122,9 +122,7 @@ to load a previously saved location."
   (let ((initvalue (or initvalue (symbol-value symbol))))
     (add-to-list 'persist--symbols symbol)
     (put symbol 'persist t)
-    (if (hash-table-p initvalue)
-        (put symbol 'persist-default (copy-hash-table initvalue))
-      (put symbol 'persist-default (persist-copy-tree initvalue t)))))
+    (put symbol 'persist-default (persist-copy initvalue))))
 
 (defun persist--persistant-p (symbol)
   "Return non-nil if SYMBOL is a persistent variable."
@@ -164,8 +162,8 @@ variables persist automatically when Emacs exits."
   (get symbol 'persist-default))
 
 (defun persist-reset (symbol)
-  "Reset the value of SYMBOL to the default."
-  (set symbol (persist-default symbol)))
+  "Set the value of SYMBOL to a copy of the default."
+  (set symbol (persist-copy (persist-default symbol))))
 
 (defun persist-load (symbol)
   "Load the saved value of SYMBOL."
@@ -241,5 +239,11 @@ traverses and copies vectors and records as well as 
conses."
          tree)
       tree)))
 
+(defun persist-copy (obj)
+  "Return copy of OBJ."
+  (if (hash-table-p obj)
+      (copy-hash-table obj)
+    (persist-copy-tree obj t)))
+
 (provide 'persist)
 ;;; persist.el ends here

Reply via email to