org-element: Fix post-blank shared between items

* lisp/org-element.el (org-element-item-parser): Do not parse beyond
LIMIT - they may extend :post-blank beyond parent list contents.
(org-element-plain-list-parser): Make sure that plain list always owns
the trailing blank lines.
(org-element-cache-version): Bump cache version.
* testing/lisp/test-org-element.el (test-org-element/item-parser): Add
test.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/1c833eb8-c556-437b-ac5b-be360ebcc869@app.fastmail.com
This commit is contained in:
Ihor Radchenko 2023-08-22 11:24:36 +03:00
parent 80ae8462a6
commit 53c9d91d3c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 12 additions and 4 deletions

View File

@ -1518,8 +1518,8 @@ CONTENTS is the contents of inlinetask."
;;;; Item ;;;; Item
(defun org-element-item-parser (_ struct &optional raw-secondary-p) (defun org-element-item-parser (limit struct &optional raw-secondary-p)
"Parse an item. "Parse an item up to LIMIT.
STRUCT is the structure of the plain list. STRUCT is the structure of the plain list.
@ -1545,7 +1545,8 @@ Assume point is at the beginning of the item."
((equal "[X]" box) 'on) ((equal "[X]" box) 'on)
((equal "[-]" box) 'trans)))) ((equal "[-]" box) 'trans))))
(end (progn (goto-char (nth 6 (assq (point) struct))) (end (progn (goto-char (nth 6 (assq (point) struct)))
(if (bolp) (point) (line-beginning-position 2)))) (min limit
(if (bolp) (point) (line-beginning-position 2)))))
(pre-blank 0) (pre-blank 0)
(contents-begin (contents-begin
(progn (progn
@ -1760,6 +1761,9 @@ Assume point is at the beginning of the list."
(= (nth 1 item) ind)) (= (nth 1 item) ind))
(setq pos (nth 6 item))) (setq pos (nth 6 item)))
pos)) pos))
(contents-end (progn (goto-char contents-end)
(skip-chars-backward " \r\t\n")
(if (bolp) (point) (line-beginning-position 2))))
(end (progn (goto-char contents-end) (end (progn (goto-char contents-end)
(skip-chars-forward " \r\t\n" limit) (skip-chars-forward " \r\t\n" limit)
(if (= (point) limit) limit (line-beginning-position))))) (if (= (point) limit) limit (line-beginning-position)))))
@ -5419,7 +5423,7 @@ indentation removed from its contents."
(defvar org-element-cache-persistent t (defvar org-element-cache-persistent t
"Non-nil when cache should persist between Emacs sessions.") "Non-nil when cache should persist between Emacs sessions.")
(defconst org-element-cache-version "2.1" (defconst org-element-cache-version "2.2"
"Version number for Org AST structure. "Version number for Org AST structure.
Used to avoid loading obsolete AST representation when using Used to avoid loading obsolete AST representation when using
`org-element-cache-persistent'.") `org-element-cache-persistent'.")

View File

@ -2110,6 +2110,10 @@ DEADLINE: <2012-03-29 thu.>"
(should (should
(= 0 (= 0
(org-test-with-temp-text "- A\n\n - B\n\n<point> - C\n\n End sub-list" (org-test-with-temp-text "- A\n\n - B\n\n<point> - C\n\n End sub-list"
(org-element-property :post-blank (org-element-at-point)))))
(should
(= 0
(org-test-with-temp-text "1. foo\n 1. bar\n 2.<point> baz\n\n2. lorem\nipsum"
(org-element-property :post-blank (org-element-at-point)))))) (org-element-property :post-blank (org-element-at-point))))))