branch: externals/persist
commit 743861cdc0b2e5fa39042bf2bf7587acc432319b
Author: Joseph Turner <[email protected]>
Commit: Philip Kaludercic <[email protected]>
Fix persist-default prop being set to current value again
ead2a75934 attempted to fix bug#75779. After that commit however,
when persist-defvar received a nil INITVALUE, the issue remained.
This commit resolves the nil case by making the second arg to
persist-symbol mandatory, thereby distinguishing between an explicit
nil argument and an optionally omitted argument.
See the commit message for ead2a75934 for more details related to the
original bug.
---
persist.el | 16 ++++++----------
test/persist-tests.el | 6 ++++++
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/persist.el b/persist.el
index 2100be700c..cab92a2a12 100644
--- a/persist.el
+++ b/persist.el
@@ -113,23 +113,19 @@ to persist a variable, you will normally need to call
`persist-load' to load a previously saved location."
(put symbol 'persist-location (expand-file-name directory)))
-(defun persist-symbol (symbol &optional initvalue)
+(defun persist-symbol (symbol initvalue)
"Make SYMBOL a persistent variable.
-If non-nil, INITVALUE is the value to which SYMBOL will be set if
-`persist-reset' is called. Otherwise, the INITVALUE will be the
-current `symbol-value' of SYMBOL.
-
-INITVALUE is set for the session and will itself not persist
+INITVALUE is the value to which SYMBOL will be set if `persist-reset' is
+called. INITVALUE is set for the session and will itself not persist
across sessions.
This does force the loading of value from this directory, so to
persist a variable, you will normally need to call `persist-load'
to load a previously saved location."
- (let ((initvalue (or initvalue (symbol-value symbol))))
- (add-to-list 'persist--symbols symbol)
- (put symbol 'persist t)
- (put symbol 'persist-default (persist-copy initvalue))))
+ (add-to-list 'persist--symbols symbol)
+ (put symbol 'persist t)
+ (put symbol 'persist-default (persist-copy initvalue)))
(defun persist--persistant-p (symbol)
"Return non-nil if SYMBOL is a persistent variable."
diff --git a/test/persist-tests.el b/test/persist-tests.el
index 2c452b7d38..59ae319c13 100644
--- a/test/persist-tests.el
+++ b/test/persist-tests.el
@@ -114,6 +114,12 @@
(persist-defvar test-persist-variable-default 'INIT "Docstring.")
(should (equal 'INIT (persist-default 'test-persist-variable-default))))
+(ert-deftest test-persist-default-nil-initvalue ()
+ (persist-defvar test-persist-variable-default nil "Docstring.")
+ (setq test-persist-variable-default 'CHANGED)
+ (persist-defvar test-persist-variable-default nil "Docstring.")
+ (should (null (persist-default 'test-persist-variable-default))))
+
(ert-deftest test-persist-location ()
(unwind-protect
(let ((sym (cl-gensym)))