emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org a97b378ee5 4/9: org-persist-read: Do not return rel


From: ELPA Syncer
Subject: [elpa] externals/org a97b378ee5 4/9: org-persist-read: Do not return related containers by default
Date: Thu, 29 Dec 2022 04:58:03 -0500 (EST)

branch: externals/org
commit a97b378ee50fa2b38069f05da2a27f0439aae76b
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-persist-read: Do not return related containers by default
    
    * lisp/org-persist.el (org-persist-read): Only return the requested
    containers.  Add new optional keyword argument :read-related to read
    the containers stored together with requested.  Update the docstring
    accordingly.
    (org-persist-load): Update definition according to `org-persist-read'.
    * lisp/org.el (org-mode): Explicitly load all the associated
    cache variables.
---
 lisp/org-persist.el | 38 +++++++++++++++++++++++++++-----------
 lisp/org.el         |  4 ++--
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index 60088af9ee..aee2070319 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -822,14 +822,27 @@ When ASSOCIATED is `all', unregister CONTAINER 
everywhere."
   "Hash table storing as-written data objects.
 
 This data is used to avoid reading the data multiple times.")
-(defun org-persist-read (container &optional associated hash-must-match load?)
+(cl-defun org-persist-read (container &optional associated hash-must-match 
load &key read-related)
   "Restore CONTAINER data for ASSOCIATED.
 When HASH-MUST-MATCH is non-nil, do not restore data if hash for
 ASSOCIATED file or buffer does not match.
+
 ASSOCIATED can be a plist, a buffer, or a string.
 A buffer is treated as (:buffer ASSOCIATED).
 A string is treated as (:file ASSOCIATED).
-When LOAD? is non-nil, load the data instead of reading."
+
+When LOAD is non-nil, load the data instead of reading.
+
+When READ-RELATED is non-nil, return the data stored alongside with
+CONTAINER as well.  For example:
+
+    (let ((info \"test\"))
+      (org-persist-register
+        \\='((version \"My data\") (elisp info local))
+        nil :write-immediately t))
+    (org-persist-read \\='(version \"My data\")) ; => \"My data\"
+    (org-persist-read \\='(version \"My data\")
+                      :read-related t) ; => (\"My data\" \"test\")"
   (unless org-persist--index (org-persist--load-index))
   (setq associated (org-persist--normalize-associated associated))
   (setq container (org-persist--normalize-container container))
@@ -859,19 +872,22 @@ When LOAD? is non-nil, load the data instead of reading."
         (setq data (or (gethash persist-file org-persist--write-cache)
                        (org-persist--read-elisp-file persist-file)))
         (when data
-          (cl-loop for container in (plist-get collection :container)
+          (cl-loop for c in (plist-get collection :container)
                    with result = nil
                    do
-                   (if load?
-                       (push (org-persist-load:generic container (alist-get 
container data nil nil #'equal) collection) result)
-                     (push (org-persist-read:generic container (alist-get 
container data nil nil #'equal) collection) result))
-                   (run-hook-with-args 'org-persist-after-read-hook container 
associated)
-                   finally return (if (= 1 (length result)) (car result) 
result)))))))
-
-(defun org-persist-load (container &optional associated hash-must-match)
+                   (when (or read-related
+                             (equal c container)
+                             (member c container))
+                     (if load
+                         (push (org-persist-load:generic c (alist-get c data 
nil nil #'equal) collection) result)
+                       (push (org-persist-read:generic c (alist-get c data nil 
nil #'equal) collection) result)))
+                   (run-hook-with-args 'org-persist-after-read-hook c 
associated)
+                   finally return (if (= 1 (length result)) (car result) 
(nreverse result))))))))
+
+(cl-defun org-persist-load (container &optional associated hash-must-match 
&key read-related)
   "Load CONTAINER data for ASSOCIATED.
 The arguments have the same meaning as in `org-persist-read'."
-  (org-persist-read container associated hash-must-match t))
+  (org-persist-read container associated hash-must-match t :read-related 
read-related))
 
 (defun org-persist-load-all (&optional associated)
   "Restore all the persistent data associated with ASSOCIATED."
diff --git a/lisp/org.el b/lisp/org.el
index 26a4c8b1c6..6906881608 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -206,7 +206,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-latex-make-preamble "ox-latex" (info &optional template 
snippet?))
 (declare-function org-num-mode "org-num" (&optional arg))
 (declare-function org-plot/gnuplot "org-plot" (&optional params))
-(declare-function org-persist-load "org-persist" (container &optional 
associated hash-must-match))
+(declare-function org-persist-load "org-persist")
 (declare-function org-tags-view "org-agenda" (&optional todo-only match))
 (declare-function org-timer "org-timer" (&optional restart no-insert))
 (declare-function org-timer-item "org-timer" (&optional arg))
@@ -4839,7 +4839,7 @@ The following commands are available:
   (org-element-cache-reset)
   (when (and org-element-cache-persistent
              org-element-use-cache)
-    (org-persist-load 'org-element--cache (current-buffer) t))
+    (org-persist-load 'org-element--cache (current-buffer) 'match-hash 
:read-related t))
   ;; Initialize macros templates.
   (org-macro-initialize-templates)
   ;; Initialize radio targets.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]