From 6631b3f7bba703be2348fa3df61c77f895762b6a Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 14 Jan 2022 14:10:02 +0800 Subject: [PATCH] org-element--parse-to: Fix limit when pasting top-comment and no cache * lisp/org-element.el (org-element--parse-to): Manually parse org-data and set appropriate parser mode when POS is before first headline and cache is disabled. (org-element-org-data-parser--recurse): New variable flagging if `org-element-data-parser' is called recursively. (org-element-org-data-parser): Handle recursive calls from inside `org-element-at-point-no-context'. This also fixes false-positives in `org-element--cache-verify-element'. --- lisp/org-element.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index e7ccd3ba8..a8e42af85 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1253,6 +1253,8 @@ parser (e.g. `:end' and :END:). Return value is a plist." (while (and (org-at-comment-p) (bolp)) (forward-line)) (org-element--get-node-properties t))) + +(defvar org-element-org-data-parser--recurse nil) (defun org-element-org-data-parser (&optional _) "Parse org-data." (org-with-wide-buffer @@ -1286,13 +1288,17 @@ parser (e.g. `:end' and :END:). Return value is a plist." ((symbolp org-category) (symbol-name org-category)) (t org-category))) (category (catch 'buffer-category - (org-with-point-at end - (while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t) - (org-element-with-disabled-cache - (let ((element (org-element-at-point-no-context))) - (when (eq (org-element-type element) 'keyword) - (throw 'buffer-category - (org-element-property :value element))))))) + (unless org-element-org-data-parser--recurse + (org-with-point-at end + ;; Avoid recusrive calls from + ;; `org-element-at-point-no-context'. + (let ((org-element-org-data-parser--recurse t)) + (while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t) + (org-element-with-disabled-cache + (let ((element (org-element-at-point-no-context))) + (when (eq (org-element-type element) 'keyword) + (throw 'buffer-category + (org-element-property :value element))))))))) category)) (properties (org-element--get-global-node-properties))) (unless (plist-get properties :CATEGORY) @@ -6378,7 +6384,8 @@ the expected result." (setq element (org-element-headline-parser nil 'fast)) (setq mode 'planning) (forward-line)) - (setq mode 'top-comment)) + (setq element (org-element-org-data-parser)) + (setq mode 'org-data)) (org-skip-whitespace) (beginning-of-line)) ;; Check if CACHED or any of its ancestors contain point.