From: Gulshan Singh <gsingh2011@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Phillip Lord <phillip.lord@russet.org.uk>, 54346@debbugs.gnu.org
Subject: bug#54346: persist-save doesn't persist variables when the value is set to the default
Date: Sun, 10 Apr 2022 12:36:54 -0700 [thread overview]
Message-ID: <CANEZYre0CoF2qs-UsJ3FN08F_4FYTGWmTTBP4L_KHqzhrumdgw@mail.gmail.com> (raw)
In-Reply-To: <87pmlpqgix.fsf@gnus.org>
[-- Attachment #1: Type: text/plain, Size: 1237 bytes --]
Hi,
I cloned the upstream project [1] and created a merge request [2]
there. The fix deletes the persist file when it gets set back to the
default value, and it modifies a test to verify this behavior. I've
attached the same patch here (created with `git format-patch HEAD^`, I
haven't submitted a patch here before so let me know if this is the
correct way to do this).
I'm a little confused though, I see that on the externals/persist
branch [3] there is a commit that does not exist on the upstream
GitLab project. Why is this the case? Should I actually be making a
patch off of the externals/persist branch?
[1] https://gitlab.com/phillord/persist/
[2] https://gitlab.com/phillord/persist/-/merge_requests/1
[3] https://git.savannah.gnu.org/cgit/emacs/elpa.git/log/?h=externals/persist
On Sun, Apr 10, 2022 at 5:17 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Gulshan Singh <gsingh2011@gmail.com> writes:
>
> > If either of these solutions make sense, or if Phillip has any other
> > suggestions, I'd be happy to make the fix myself if that would be
> > easier.
>
> Yes, that'd be great (and post the patch here).
>
> --
> (domestic pets only, the antidote for overdose, milk.)
> bloggy blog: http://lars.ingebrigtsen.no
[-- Attachment #2: 0001-Delete-persist-file-when-symbol-is-set-to-default-va.patch --]
[-- Type: application/octet-stream, Size: 2265 bytes --]
From b0496a5a8848d11233f241f6b78f00f1536410d6 Mon Sep 17 00:00:00 2001
From: Gulshan Singh <gsingh2011@gmail.com>
Date: Sun, 10 Apr 2022 12:13:31 -0700
Subject: [PATCH] Delete persist file when symbol is set to default value
---
persist.el | 26 ++++++++++++++------------
test/persist-tests.el | 3 +++
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/persist.el b/persist.el
index 091e428..8b645ea 100644
--- a/persist.el
+++ b/persist.el
@@ -132,18 +132,20 @@ 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
- (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
+ (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 9fa406f..b6645a9 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)))))
--
2.35.1.1178.g4f1659d476-goog
next prev parent reply other threads:[~2022-04-10 19:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-12 1:15 bug#54346: persist-save doesn't persist variables when the value is set to the default Gulshan Singh
2022-03-12 17:44 ` Lars Ingebrigtsen
2022-04-09 21:45 ` Gulshan Singh
2022-04-10 12:17 ` Lars Ingebrigtsen
2022-04-10 19:36 ` Gulshan Singh [this message]
2022-04-11 10:18 ` Lars Ingebrigtsen
2022-06-21 2:14 ` Gulshan Singh
2022-06-21 10:49 ` Lars Ingebrigtsen
2022-06-22 0:55 ` Gulshan Singh
2022-06-22 4:21 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANEZYre0CoF2qs-UsJ3FN08F_4FYTGWmTTBP4L_KHqzhrumdgw@mail.gmail.com \
--to=gsingh2011@gmail.com \
--cc=54346@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=phillip.lord@russet.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).