Sfoglia il codice sorgente

org-element-cache: Handle some edits in top-level property drawer

* lisp/org-element.el (org-element--cache-sensitive-re): Make proprety
drawer lines sensitive.
(org-element--cache-for-removal): Make sensitive edits inside cache
gap right after org-data re-parse the org-data.  Make sensitive
top-section edits re-parse org-data.

The specific error has been reported in
https://github.com/yantar92/org/issues/40
The recepy involves loading org-contrib:
1. emacs -Q -L ~/.emacs.d/.local/straight/repos/org/lisp -L ~/.emacs.d/.local/straight/repos/org-contrib/lisp -l org
 -l org-eldoc
 2. Create a test.org file with the following content:
 :PROPERTIES:
:ID:       test
:END:

Test.
3.
(goto-char (point-min))
(org-entry-put nil "ID" "test")
(save-buffer)
(org-entry-get nil "ID")
Return value is nil, while should be "test"
Ihor Radchenko 3 anni fa
parent
commit
54534eebbb
1 ha cambiato i file con 17 aggiunte e 2 eliminazioni
  1. 17 2
      lisp/org-element.el

+ 17 - 2
lisp/org-element.el

@@ -6495,7 +6495,7 @@ If you observe Emacs hangs frequently, please report this to Org mode mailing li
    org-list-full-item-re "\\|"
    ":\\(?: \\|$\\)" "\\|"
    "\\\\begin{[A-Za-z0-9*]+}" "\\|"
-   ":\\(?:\\w\\|[-_]\\)+:[ \t]*$"
+   ":\\(?:\\w\\|[-_]\\)+:[ \t]*.*$"
    "\\)")
   "Regexp matching a sensitive line, structure wise.
 A sensitive line is a headline, inlinetask, block, drawer, or
@@ -6619,6 +6619,11 @@ known element in cache (it may start after END)."
     (if (not before) after
       (let ((up before)
 	    (robust-flag t))
+        (when (and (eq 'org-data (org-element-type up))
+                   org-element--cache-change-warning)
+          ;; We may be doing changes in first section that affect
+          ;; org-data.
+          (setq org-element--cache-change-warning 'org-data))
 	(while up
 	  (if (let ((type (org-element-type up)))
                 (or (and (memq type '( center-block dynamic-block
@@ -6644,7 +6649,17 @@ known element in cache (it may start after END)."
                          (pcase type
                            ;; Sensitive change in section.  Need to
                            ;; re-parse.
-                           (`section (not org-element--cache-change-warning))
+                           (`section
+                            (or (not org-element--cache-change-warning) ; robust
+                                (when (and org-element--cache-change-warning
+                                           (eq 'org-data
+                                               (org-element-type (org-element-property :parent up))))
+                                  ;; Breaking change in section
+                                  ;; potentially breaks org-data
+                                  ;; (i.e. top property drawer change).
+                                  (setq org-element--cache-change-warning 'org-data)
+                                  ;; Not robust
+                                  nil)))
                            ;; Headline might be inserted.  This is non-robust
                            ;; change when `up' is a `headline' or `section'
                            ;; with `>' level compared to the inserted headline.