From 61c235b7780f07ee4024c4c71228a0bd13dc9ea5 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Tue, 13 Feb 2024 12:45:20 +0100 Subject: [PATCH] org-element-paragraph-parser: Fix edge case; fix tests * lisp/org-element.el (org-element-paragraph-parser): Fix edge case when :end: is in the middle of a paragraph. * testing/lisp/test-org-element.el (test-org-element/paragraph-parser): Fix point position in the tests. Add test case for ending lines of incomplete blocks/drawers. Remove test for incomplete dynamic blocks - they are keywords. Reported-by: Tom Alexander Link: https://orgmode.org/list/87o7hiwzma.fsf@localhost --- lisp/org-element.el | 1 + testing/lisp/test-org-element.el | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index e6df9743a..6691ea44e 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2870,6 +2870,7 @@ Assume point is at the beginning of the paragraph." (progn (forward-line 0) t)))) ((looking-at-p org-element-drawer-re) (save-excursion + (forward-line 1) (re-search-forward "^[ \t]*:END:[ \t]*$" limit t))) ((looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)") (save-excursion diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index ca7d77e28..93754bae5 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -2629,30 +2629,34 @@ e^{i\\pi}+1=0 (org-element-map (org-element-parse-buffer) 'paragraph 'identity))) ;; Include incomplete-drawers. (should - (org-test-with-temp-text ":TEST:\nParagraph" + (org-test-with-temp-text ":TEST:\nParagraph" + (let ((elem (org-element-at-point))) + (and (eq (org-element-type elem) 'paragraph) + (= (point-max) (org-element-property :end elem)))))) + (should + (org-test-with-temp-text "foo\n:end:\nbar" (let ((elem (org-element-at-point))) (and (eq (org-element-type elem) 'paragraph) (= (point-max) (org-element-property :end elem)))))) ;; Include incomplete blocks. (should - (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph" + (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph" (let ((elem (org-element-at-point))) (and (eq (org-element-type elem) 'paragraph) (= (point-max) (org-element-property :end elem)))))) - ;; Include incomplete dynamic blocks. (should - (org-test-with-temp-text "#+BEGIN: \nParagraph" + (org-test-with-temp-text "foo\n#+END_CENTER\nbar" (let ((elem (org-element-at-point))) (and (eq (org-element-type elem) 'paragraph) (= (point-max) (org-element-property :end elem)))))) ;; Include incomplete latex environments. (should - (org-test-with-temp-text "\begin{equation}\nParagraph" + (org-test-with-temp-text "\begin{equation}\nParagraph" (let ((elem (org-element-at-point))) (and (eq (org-element-type elem) 'paragraph) (= (point-max) (org-element-property :end elem)))))) (should - (org-test-with-temp-text "Paragraph\n\begin{equation}" + (org-test-with-temp-text "Paragraph\n\begin{equation}" (let ((elem (org-element-at-point))) (and (eq (org-element-type elem) 'paragraph) (= (point-max) (org-element-property :end elem))))))