1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-12 09:28:11 +00:00

org-element-cache: Add more self-consistency checks

* lisp/org-element.el (org-element--parse-to):
(org-element--cache-verify-element): Add check asserting that all the
parsed elements are assigned with non-nil parent (except org-data).
This commit is contained in:
Ihor Radchenko 2022-02-05 19:16:30 +08:00
parent 5da9d6810b
commit bb8aa14923
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B

View File

@ -6447,6 +6447,13 @@ If you observe Emacs hangs frequently, please report this to Org mode mailing li
(setq element (or (org-element--cache-put element) element))
;; Nothing to parse (i.e. empty file).
(throw 'exit parent))
(unless (or (not (org-element--cache-active-p)) parent)
(org-element--cache-warn "Got empty parent while parsing. Please report it to Org mode mailing list (M-x org-submit-bug-report).\n Backtrace:\n%S"
(when (and (fboundp 'backtrace-get-frames)
(fboundp 'backtrace-to-string))
(backtrace-to-string (backtrace-get-frames 'backtrace))
(org-element-cache-reset)
(error "org-element--cache: Emergency exit"))))
(org-element-put-property element :parent parent))
(let ((elem-end (org-element-property :end element))
(type (org-element-type element)))
@ -6988,6 +6995,10 @@ change, as an integer."
Return non-nil when verification failed."
;; Verify correct parent for the element.
(unless (or (org-element-property :parent element)
(eq 'org-data (org-element-type element)))
(org-element--cache-warn "Got element without parent (cache active?: %S). Please report it to Org mode mailing list (M-x org-submit-bug-report).\n%S" (org-element--cache-active-p) element)
(org-element-cache-reset))
(let ((org-element--cache-self-verify (or org-element--cache-self-verify
(and (boundp 'org-batch-test) org-batch-test)))
(org-element--cache-self-verify-frequency (if (and (boundp 'org-batch-test) org-batch-test)