From 1b2d06880f03c4e2063a9c91741935ea49144d2c Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 28 Oct 2021 22:32:50 +0800 Subject: [PATCH] org-persist.el: Do not write global variables on buffer kill * lisp/org-persist.el (org-persist-write-all): Prevent writing global variables when BUFFER arg is provided. (org-persist-gc): Handle case when :persist-file is set to nil in the index. Fixes https://list.orgmode.org/DB9PR08MB66336CDF0F43DE3DB1D08649A3869@DB9PR08MB6633.eurprd08.prod.outlook.com/T/#m40fcc5ea8ba0ef52518a58713cf9ad3d1fffa33d --- lisp/org-persist.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/org-persist.el b/lisp/org-persist.el index 47a31e016..fd6fed945 100644 --- a/lisp/org-persist.el +++ b/lisp/org-persist.el @@ -209,11 +209,12 @@ When BUFFER is `all', unregister VAR in all buffers." "Save all the persistent data." (unless (and buffer (not (buffer-file-name buffer))) (dolist (index org-persist--index) - (when (or (not (plist-get index :path)) - (and (get-file-buffer (plist-get index :path)) - (or (not buffer) - (equal (buffer-file-name buffer) - (plist-get index :path))))) + (when (or (and (not (plist-get index :path)) + (not buffer)) + (and (plist-get index :path) + (get-file-buffer (plist-get index :path)) + (equal (buffer-file-name buffer) + (plist-get index :path)))) (org-persist-write (plist-get index :variable) (when (plist-get index :path) (get-file-buffer (plist-get index :path)))))))) @@ -272,9 +273,10 @@ When BUFFER is `all', unregister VAR in all buffers." (let (new-index) (dolist (index org-persist--index) (let ((file (plist-get index :path)) - (persist-file (org-file-name-concat - org-persist-directory - (plist-get index :persist-file)))) + (persist-file (when (plist-get index :persist-file) + (org-file-name-concat + org-persist-directory + (plist-get index :persist-file))))) (when (and file persist-file) (if (file-exists-p file) (push index new-index)