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

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

[elpa] externals/org 0d214ef008 1/2: org-element--current-element: Fix e


From: ELPA Syncer
Subject: [elpa] externals/org 0d214ef008 1/2: org-element--current-element: Fix edge case with affiliated keywords
Date: Fri, 13 Oct 2023 09:58:41 -0400 (EDT)

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

    org-element--current-element: Fix edge case with affiliated keywords
    
    * lisp/org-element.el (org-element--collect-affiliated-keywords): Fix
    edge case when a keyword matching affiliated keyword is preceding an
    element that is not allowed to have such.  We need to handle this case
    specially here rather than in `org-element--current-element' to avoid
    the default paragraph fallback.
    (org-element--current-element): Add a comment describing the pitfall.
    *
    testing/lisp/test-org-element.el 
(test-org-element/affiliated-keywords-parser):
    Add more tests.
    
    Reported-by: Tom Alexander <tom@fizz.buzz>
    Link: 
https://orgmode.org/list/e2be976d-1bcf-4136-9968-33212dcd1f83@app.fastmail.com
---
 lisp/org-element.el              | 10 +++++++++-
 testing/lisp/test-org-element.el | 17 ++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index bb5b2a003f..c6f96b89db 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4610,6 +4610,10 @@ element it has to parse."
        ;; Inlinetask.
        (at-task? (org-element-inlinetask-parser limit raw-secondary-p))
        ;; From there, elements can have affiliated keywords.
+        ;; Note an edge case with a keyword followed by element that
+        ;; cannot have affiliated keywords attached (the above).
+        ;; `org-element--collect-affiliated-keywords' must have a
+        ;; special check to fall back to parsing proper keyword.
        (t (let ((affiliated (org-element--collect-affiliated-keywords
                              limit (memq granularity '(nil object)))))
              (cond
@@ -4792,7 +4796,11 @@ When PARSE is non-nil, values from keywords belonging to
       ;; They will be parsed as a paragraph.
       (when (or (looking-at-p "[ \t]*$")
                 ;; Affiliated keywords are not allowed before comments.
-                (looking-at-p org-comment-regexp))
+                (looking-at-p org-comment-regexp)
+                ;; Clock lines are also not allowed.
+                (looking-at-p org-clock-line-re)
+                ;; Inlinetasks not allowed.
+                (looking-at-p "^\\*+ "))
         (goto-char origin) (setq output nil))
       ;; Return value.
       (cons origin output))))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index a8bfa9eaaf..bcc2efbdb0 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -878,7 +878,22 @@ Some other text
   (should-not
    (org-test-with-temp-text "#+name: foo\n# bar"
      (progn (search-forward "bar")
-           (org-element-property :name (org-element-at-point))))))
+           (org-element-property :name (org-element-at-point)))))
+  ;; Headlines cannot have affiliated keywords.
+  (should
+   (org-test-with-temp-text "<point>#+name: foo\n* Heading"
+     (org-element-type-p (org-element-at-point) 'keyword)))
+  ;; Clocks cannot have affiliated keywords.
+  (should
+   (org-test-with-temp-text "<point>#+name: foo
+CLOCK: [2023-10-13 Fri 14:40]--[2023-10-13 Fri 14:51] =>  0:11"
+     (org-element-type-p (org-element-at-point) 'keyword)))
+  ;; Inlinetasks cannot have affiliated keywords.
+  (should
+   (let ((org-inlinetask-min-level 4))
+     (org-test-with-temp-text "<point>#+name: foo
+**** Inlinetask"
+       (org-element-type-p (org-element-at-point) 'keyword)))))
 
 
 ;;;; Babel Call



reply via email to

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