[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/persist 2719b2d3c0: Persist variables that have changed
From: |
Lars Ingebrigtsen |
Subject: |
[elpa] externals/persist 2719b2d3c0: Persist variables that have changed back to default values |
Date: |
Wed, 22 Jun 2022 00:21:10 -0400 (EDT) |
branch: externals/persist
commit 2719b2d3c006f3963face1ad27fcadf1490d8efc
Author: Gulshan Singh <gsingh2011@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Persist variables that have changed back to default values
* persist.el (persist-save): Persist variables that have changed
back to default values (bug#54346).
Copyright-paperwork-exempt: yes
---
persist.el | 38 ++++++++++++++++++++------------------
test/persist-tests.el | 3 +++
2 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/persist.el b/persist.el
index 3d8d1af5ce..950de3a231 100644
--- a/persist.el
+++ b/persist.el
@@ -132,24 +132,26 @@ variables persist automatically when Emacs exits."
(unless (persist--persistant-p symbol)
(error (format
"Symbol %s is not persistant" symbol)))
- (unless (equal (symbol-value symbol)
- (persist-default symbol))
- (let ((dir-loc
- (file-name-directory
- (persist--file-location symbol))))
- (unless (file-exists-p dir-loc)
- (mkdir dir-loc)))
- (with-temp-buffer
- (let (print-level
- print-length
- print-quoted
- (print-escape-control-characters t)
- (print-escape-nonascii t)
- (print-circle t))
- (print (symbol-value symbol) (current-buffer)))
- (write-region (point-min) (point-max)
- (persist--file-location symbol)
- nil 'quiet))))
+ (let ((symbol-file-loc (persist--file-location symbol)))
+ (if (equal (symbol-value symbol)
+ (persist-default symbol))
+ (when (file-exists-p symbol-file-loc)
+ (delete-file symbol-file-loc))
+ (let ((dir-loc
+ (file-name-directory symbol-file-loc)))
+ (unless (file-exists-p dir-loc)
+ (mkdir dir-loc))
+ (with-temp-buffer
+ (let (print-level
+ print-length
+ print-quoted
+ (print-escape-control-characters t)
+ (print-escape-nonascii t)
+ (print-circle t))
+ (print (symbol-value symbol) (current-buffer)))
+ (write-region (point-min) (point-max)
+ symbol-file-loc
+ nil 'quiet))))))
(defun persist-default (symbol)
"Return the default value for SYMBOL."
diff --git a/test/persist-tests.el b/test/persist-tests.el
index 9fa406f4d9..b6645a9297 100644
--- a/test/persist-tests.el
+++ b/test/persist-tests.el
@@ -44,6 +44,9 @@
(with-temp-buffer
(insert-file-contents (persist--file-location sym))
(buffer-string))))
+ (set sym 10)
+ (persist-save sym)
+ (should-not (file-exists-p (persist--file-location sym)))
(should-error
(persist-save 'fred)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/persist 2719b2d3c0: Persist variables that have changed back to default values,
Lars Ingebrigtsen <=