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

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

[elpa] externals/org b00c2d0e1d 039/101: org-element--parse-to: Provide


From: ELPA Syncer
Subject: [elpa] externals/org b00c2d0e1d 039/101: org-element--parse-to: Provide deferred :parent when cache is inactive
Date: Sat, 1 Jul 2023 09:59:04 -0400 (EDT)

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

    org-element--parse-to: Provide deferred :parent when cache is inactive
    
    * lisp/org-element.el (org-element--headline-parent-deferred): New
    function to calculate :parent of a heading on demand.
    (org-element--parse-to): Assign deferred :parent when cache is
    inactive.
---
 lisp/org-element.el | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 6109f677d9..deec546ce3 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -6446,6 +6446,22 @@ and footnote-definition."
             (skip-chars-backward " \r\n\t")
             (line-beginning-position 2)))))
 
+(defun org-element--headline-parent-deferred (headline)
+  "Parse parent for HEADLINE."
+  (with-current-buffer (org-element-property :buffer headline)
+    (org-with-point-at (org-element-begin headline)
+      (if (or (bobp) (= 1 (org-element-property :true-level headline)))
+          ;; Top-level heading.  Parent is `org-data'.
+          (org-element-org-data-parser)
+        (re-search-backward
+         (org-headline-re
+          (1- (org-element-property :true-level headline)))
+         nil 'move)
+        (let ((parent (org-element-at-point)))
+          (if (org-element-type-p parent 'headline) parent
+            ;; Before first headline.  Assign `org-data'.
+            (org-element-lineage parent 'org-data t)))))))
+
 (defun org-element--parse-to (pos &optional syncp time-limit)
   "Parse elements in current section, down to POS.
 
@@ -6489,8 +6505,7 @@ the expected result."
             (setq mode 'org-data))
             ;; Nothing in cache before point because cache is not active.
             ;; Parse from previous heading to avoid re-parsing the whole
-            ;; buffer above.  This comes at the cost of not calculating
-            ;; `:parent' property for headings.
+            ;; buffer above.  Arrange `:parent' to be calculated on demand.
             ((not cached)
              (end-of-line) ; ensure the end of current heading.
              (if (re-search-backward
@@ -6498,6 +6513,10 @@ the expected result."
                   nil 'move)
                  (progn
                    (setq element (org-element-headline-parser nil 'fast))
+                   (org-element-put-property
+                    element :parent
+                    (org-element-deferred-create
+                     t #'org-element--headline-parent-deferred))
                   (setq mode 'planning)
                   (forward-line))
                (setq element (org-element-org-data-parser))
@@ -6533,7 +6552,12 @@ the expected result."
                (when up (setq element up)))))
            ;; Parse successively each element until we reach POS.
            (let ((end (or (org-element-end element) (point-max)))
-                (parent (org-element-parent element)))
+                (parent (when (org-element--cache-active-p)
+                           ;; Cache is not active.  Parent is deferred.
+                           ;; We will not actually use parent during
+                           ;; the first iteration of the `while' loop.
+                           ;; Avoid undeferring here.
+                           (org-element-parent element))))
              (while t
               (when (org-element--cache-interrupt-p time-limit)
                  (throw 'org-element--cache-interrupt nil))



reply via email to

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