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

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

[elpa] externals/org 7efd5bba0a 2/2: org-element-cache: Add switch to ve


From: ELPA Syncer
Subject: [elpa] externals/org 7efd5bba0a 2/2: org-element-cache: Add switch to verify cache before writing to disk
Date: Fri, 22 Sep 2023 06:58:53 -0400 (EDT)

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

    org-element-cache: Add switch to verify cache before writing to disk
    
    *
    lisp/org-element.el (org-element--cache-self-verify-before-persisting):
    New internal variable toggling full verification pass before writing
    cache to disk.
    
    * lisp/org-element.el (org-element--cache-persist-before-write):
    Verify cache and throw error on failure when
    `org-element--cache-self-verify-before-persisting' is non-nil.
---
 lisp/org-element.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index aa809e14f0..7ea73637c4 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -5450,6 +5450,13 @@ of `org-element--cache-self-verify-frequency'.
 When set to symbol `backtrace', record and display backtrace log if
 any inconsistency is detected.")
 
+(defvar org-element--cache-self-verify-before-persisting nil
+  "Perform consistency checks for the cache before writing to disk.
+
+When non-nil, signal an error an show backtrace if cache contains
+incorrect elements.  `org-element--cache-self-verify' must be set to
+symbol `backtrace' to have non-empty backtrace displayed.")
+
 (defvar org-element--cache-self-verify-frequency 0.03
   "Frequency of cache element verification.
 
@@ -7360,9 +7367,10 @@ The element is: %S\n The real element is: %S\n Cache 
around :begin:\n%S\n%S\n%S"
                       (unless (org-element-type-p el2 'plain-text)
                         (org-element-put-property el2 :buffer nil)))
                     nil nil nil 'with-affiliated 'no-undefer)
-                  (when (and (not (org-element-parent el)) (not 
(org-element-type-p el 'org-data)))
-                    (org-element--cache-warn
-                     "Got element without parent when writing cache to 
disk.\n%S" el)))
+                  (let ((org-element--cache-self-verify-frequency 1.0))
+                    (when (and org-element--cache-self-verify-before-persisting
+                               (org-element--cache-verify-element el))
+                      (error "Cache verification failed: aborting"))))
                 org-element--cache)
                nil)
             'forbid))



reply via email to

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