forked from mirrors/org-mode
org-element: Fix block parsing
* contrib/lisp/org-element.el (org-element-parse-elements): Fix erroneous block parsing introduced by recent speed improvements. Also refactor code a bit.
This commit is contained in:
parent
3c4a0795df
commit
0bd090379b
|
@ -3105,7 +3105,9 @@ elements.
|
||||||
|
|
||||||
Elements are accumulated into ACC."
|
Elements are accumulated into ACC."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char beg)
|
(save-restriction
|
||||||
|
(narrow-to-region beg end)
|
||||||
|
(goto-char beg)
|
||||||
;; When parsing only headlines, skip any text before first one.
|
;; When parsing only headlines, skip any text before first one.
|
||||||
(when (and (eq granularity 'headline) (not (org-at-heading-p)))
|
(when (and (eq granularity 'headline) (not (org-at-heading-p)))
|
||||||
(org-with-limited-levels (outline-next-heading)))
|
(org-with-limited-levels (outline-next-heading)))
|
||||||
|
@ -3117,13 +3119,10 @@ Elements are accumulated into ACC."
|
||||||
(if (eq special 'item)
|
(if (eq special 'item)
|
||||||
(let ((element (org-element-item-parser structure)))
|
(let ((element (org-element-item-parser structure)))
|
||||||
(goto-char (org-element-get-property :end element))
|
(goto-char (org-element-get-property :end element))
|
||||||
(save-restriction
|
(org-element-parse-elements
|
||||||
(narrow-to-region
|
(org-element-get-property :contents-begin element)
|
||||||
(org-element-get-property :contents-begin element)
|
(org-element-get-property :contents-end element)
|
||||||
(org-element-get-property :contents-end element))
|
nil structure granularity visible-only (reverse element)))
|
||||||
(org-element-parse-elements
|
|
||||||
(point-min) (point-max) nil structure granularity visible-only
|
|
||||||
(reverse element))))
|
|
||||||
;; 2. When ITEM is nil, find current element's type and parse
|
;; 2. When ITEM is nil, find current element's type and parse
|
||||||
;; it accordingly to its category.
|
;; it accordingly to its category.
|
||||||
(let ((element (org-element-current-element special structure)))
|
(let ((element (org-element-current-element special structure)))
|
||||||
|
@ -3133,12 +3132,10 @@ Elements are accumulated into ACC."
|
||||||
;; if GRANULARITY allows it.
|
;; if GRANULARITY allows it.
|
||||||
((and (eq (car element) 'paragraph)
|
((and (eq (car element) 'paragraph)
|
||||||
(or (not granularity) (eq granularity 'object)))
|
(or (not granularity) (eq granularity 'object)))
|
||||||
(save-restriction
|
(org-element-parse-objects
|
||||||
(narrow-to-region
|
(org-element-get-property :contents-begin element)
|
||||||
(org-element-get-property :contents-begin element)
|
(org-element-get-property :contents-end element)
|
||||||
(org-element-get-property :contents-end element))
|
(reverse element) nil))
|
||||||
(org-element-parse-objects
|
|
||||||
(point-min) (point-max) (reverse element) nil)))
|
|
||||||
;; Case 2. ELEMENT is recursive: parse it between
|
;; Case 2. ELEMENT is recursive: parse it between
|
||||||
;; `contents-begin' and `contents-end'. Make sure
|
;; `contents-begin' and `contents-end'. Make sure
|
||||||
;; GRANULARITY allows the recursion, or ELEMENT is an
|
;; GRANULARITY allows the recursion, or ELEMENT is an
|
||||||
|
@ -3151,22 +3148,18 @@ Elements are accumulated into ACC."
|
||||||
(eq (car element) 'headline))
|
(eq (car element) 'headline))
|
||||||
(not (and visible-only
|
(not (and visible-only
|
||||||
(org-element-get-property :hiddenp element))))
|
(org-element-get-property :hiddenp element))))
|
||||||
(save-restriction
|
(org-element-parse-elements
|
||||||
(narrow-to-region
|
(org-element-get-property :contents-begin element)
|
||||||
(org-element-get-property :contents-begin element)
|
(org-element-get-property :contents-end element)
|
||||||
(org-element-get-property :contents-end element))
|
;; At a plain list, switch to item mode. At an
|
||||||
(org-element-parse-elements
|
;; headline, switch to section mode. Any other
|
||||||
(point-min) (point-max)
|
;; element turns off special modes.
|
||||||
;; At a plain list, switch to item mode. At an
|
(case (car element) (plain-list 'item) (headline 'section))
|
||||||
;; headline, switch to section mode. Any other
|
(org-element-get-property :structure element)
|
||||||
;; element turns off special modes.
|
granularity visible-only (reverse element)))
|
||||||
(case (car element) (plain-list 'item) (headline 'section))
|
|
||||||
(org-element-get-property :structure element)
|
|
||||||
granularity visible-only (reverse element))))
|
|
||||||
;; Case 3. Else, just accumulate ELEMENT.
|
;; Case 3. Else, just accumulate ELEMENT.
|
||||||
(t element))))
|
(t element))))
|
||||||
acc)
|
acc)))
|
||||||
(org-skip-whitespace))
|
|
||||||
;; Return result.
|
;; Return result.
|
||||||
(nreverse acc)))
|
(nreverse acc)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue