From 20b33106cdd108fd3212e5fef135a55e25ede4a4 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 22 Mar 2023 16:06:34 +0100 Subject: [PATCH] org-element-headline-parser: Fix empty headings with tags * lisp/org-element.el (org-element-headline-parser): Allow empty title with tags. Do not consider space after COMMENT to be a part of title. * testing/lisp/test-org-element.el (test-org-element/headline-todo-keyword): Add tests. Reported-by: Leo Butler Link: https://orgmode.org/list/87zg8t4zgo.fsf@localhost --- lisp/org-element.el | 15 ++++++--------- testing/lisp/test-org-element.el | 10 +++++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index d61a7efb2..357ad5596 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1114,16 +1114,13 @@ Assume point is at beginning of the headline." (aref (match-string 0) 2)))) (commentedp (and (let ((case-fold-search nil)) - (looking-at org-element-comment-string)) - (goto-char (match-end 0)) - (when (looking-at-p "\\(?:[ \t]\\|$\\)") - (point)))) - (title-start (prog1 (point) - (unless (or todo priority commentedp) - ;; Headline like "* :tag:" - (skip-chars-backward " \t")))) + (looking-at (concat org-element-comment-string "\\(?: \\|$\\)"))) + (prog1 t + (goto-char (match-end 0)) + (skip-chars-forward " \t")))) + (title-start (point)) (tags (when (re-search-forward - "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" + "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" (line-end-position) 'move) (goto-char (match-beginning 0)) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index e2cdadbd1..6f95b0f0a 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1209,7 +1209,15 @@ Some other text (should-not (org-element-property :todo-keyword (org-element-at-point))))) (org-test-with-temp-text "* TODO" (let ((org-todo-keywords '((sequence "TODO" "DONE")))) - (should (org-element-property :todo-keyword (org-element-at-point)))))) + (should (org-element-property :todo-keyword (org-element-at-point))))) + (org-test-with-temp-text "* :tag:" + (should (member "tag" (org-element-property :tags (org-element-at-point))))) + (org-test-with-temp-text "* COMMENT" + (should (org-element-property :commentedp (org-element-at-point)))) + (org-test-with-temp-text "* COMMENT title" + (should (equal "title" (org-element-property :raw-value (org-element-at-point))))) + (org-test-with-temp-text "* COMMENT:tag:" + (should-not (org-element-property :commentedp (org-element-at-point))))) (ert-deftest test-org-element/headline-comment-keyword () "Test COMMENT keyword recognition."