branch: externals/transient
commit 652c0932e4d9e7d7f385d21264f26f1aa7e72bb2
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    transient--pp-to-file: Avoid saving empty value
    
    Do not create the file and containing directory if the value to be
    saved is nil.  If the file already exists, then always update, even
    if the value is nil, to ensure an older value doesn't stick around.
    
    If someone customized where history is stored, but has to use "emacs
    -Q", then they used to end up with "~/.emacs.d/transient/history.el"
    with content "nil".
---
 lisp/transient.el | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index f5ed899354..84f0db0a3b 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -725,14 +725,15 @@ See also option `transient-highlight-mismatched-keys'."
            (read (current-buffer))))))
 
 (defun transient--pp-to-file (list file)
-  (make-directory (file-name-directory file) t)
-  (setq list (cl-sort (copy-sequence list) #'string< :key #'car))
-  (with-temp-file file
-    (let ((print-level nil)
-          (print-length nil)
-          (pp-default-function 'pp-28)
-          (fill-column 999))
-      (pp list (current-buffer)))))
+  (when (or list (file-exists-p file))
+    (make-directory (file-name-directory file) t)
+    (setq list (cl-sort (copy-sequence list) #'string< :key #'car))
+    (with-temp-file file
+      (let ((print-level nil)
+            (print-length nil)
+            (pp-default-function 'pp-28)
+            (fill-column 999))
+        (pp list (current-buffer))))))
 
 (defvar transient-values
   (transient--read-file-contents transient-values-file)

Reply via email to