|
@@ -72,7 +72,6 @@
|
|
|
(declare-function org-at-heading-p "org" (&optional _))
|
|
|
(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
|
|
|
(declare-function org-escape-code-in-string "org-src" (s))
|
|
|
-(declare-function org-find-visible "org" ())
|
|
|
(declare-function org-macro-escape-arguments "org-macro" (&rest args))
|
|
|
(declare-function org-macro-extract-arguments "org-macro" (s))
|
|
|
(declare-function org-reduced-level "org" (l))
|
|
@@ -4361,54 +4360,52 @@ elements.
|
|
|
Elements are accumulated into ACC."
|
|
|
(save-excursion
|
|
|
(goto-char beg)
|
|
|
- ;; Visible only: skip invisible parts at the beginning of the
|
|
|
- ;; element.
|
|
|
- (when (and visible-only (org-invisible-p2))
|
|
|
- (goto-char (min (1+ (org-find-visible)) end)))
|
|
|
;; When parsing only headlines, skip any text before first one.
|
|
|
(when (and (eq granularity 'headline) (not (org-at-heading-p)))
|
|
|
(org-with-limited-levels (outline-next-heading)))
|
|
|
(let (elements)
|
|
|
(while (< (point) end)
|
|
|
- ;; Find current element's type and parse it accordingly to
|
|
|
- ;; its category.
|
|
|
- (let* ((element (org-element--current-element
|
|
|
- end granularity mode structure))
|
|
|
- (type (org-element-type element))
|
|
|
- (cbeg (org-element-property :contents-begin element)))
|
|
|
- (goto-char (org-element-property :end element))
|
|
|
- ;; Visible only: skip invisible parts between siblings.
|
|
|
- (when (and visible-only (org-invisible-p2))
|
|
|
- (goto-char (min (1+ (org-find-visible)) end)))
|
|
|
- ;; Fill ELEMENT contents by side-effect.
|
|
|
- (cond
|
|
|
- ;; If element has no contents, don't modify it.
|
|
|
- ((not cbeg))
|
|
|
- ;; Greater element: parse it between `contents-begin' and
|
|
|
- ;; `contents-end'. Make sure GRANULARITY allows the
|
|
|
- ;; recursion, or ELEMENT is a headline, in which case going
|
|
|
- ;; inside is mandatory, in order to get sub-level headings.
|
|
|
- ((and (memq type org-element-greater-elements)
|
|
|
- (or (memq granularity '(element object nil))
|
|
|
- (and (eq granularity 'greater-element)
|
|
|
- (eq type 'section))
|
|
|
- (eq type 'headline)))
|
|
|
- (org-element--parse-elements
|
|
|
- cbeg (org-element-property :contents-end element)
|
|
|
- ;; Possibly switch to a special mode.
|
|
|
- (org-element--next-mode mode type t)
|
|
|
- (and (memq type '(item plain-list))
|
|
|
- (org-element-property :structure element))
|
|
|
- granularity visible-only element))
|
|
|
- ;; ELEMENT has contents. Parse objects inside, if
|
|
|
- ;; GRANULARITY allows it.
|
|
|
- ((memq granularity '(object nil))
|
|
|
- (org-element--parse-objects
|
|
|
- cbeg (org-element-property :contents-end element) element
|
|
|
- (org-element-restriction type))))
|
|
|
- (push (org-element-put-property element :parent acc) elements)
|
|
|
- ;; Update mode.
|
|
|
- (setq mode (org-element--next-mode mode type nil))))
|
|
|
+ ;; Visible only: skip invisible parts due to folding.
|
|
|
+ (if (and visible-only (org-invisible-p nil t))
|
|
|
+ (progn
|
|
|
+ (goto-char (org-find-visible))
|
|
|
+ (when (and (eolp) (not (eobp))) (forward-char)))
|
|
|
+ ;; Find current element's type and parse it accordingly to
|
|
|
+ ;; its category.
|
|
|
+ (let* ((element (org-element--current-element
|
|
|
+ end granularity mode structure))
|
|
|
+ (type (org-element-type element))
|
|
|
+ (cbeg (org-element-property :contents-begin element)))
|
|
|
+ (goto-char (org-element-property :end element))
|
|
|
+ ;; Fill ELEMENT contents by side-effect.
|
|
|
+ (cond
|
|
|
+ ;; If element has no contents, don't modify it.
|
|
|
+ ((not cbeg))
|
|
|
+ ;; Greater element: parse it between `contents-begin' and
|
|
|
+ ;; `contents-end'. Ensure GRANULARITY allows recursion,
|
|
|
+ ;; or ELEMENT is a headline, in which case going inside
|
|
|
+ ;; is mandatory, in order to get sub-level headings.
|
|
|
+ ((and (memq type org-element-greater-elements)
|
|
|
+ (or (memq granularity '(element object nil))
|
|
|
+ (and (eq granularity 'greater-element)
|
|
|
+ (eq type 'section))
|
|
|
+ (eq type 'headline)))
|
|
|
+ (org-element--parse-elements
|
|
|
+ cbeg (org-element-property :contents-end element)
|
|
|
+ ;; Possibly switch to a special mode.
|
|
|
+ (org-element--next-mode mode type t)
|
|
|
+ (and (memq type '(item plain-list))
|
|
|
+ (org-element-property :structure element))
|
|
|
+ granularity visible-only element))
|
|
|
+ ;; ELEMENT has contents. Parse objects inside, if
|
|
|
+ ;; GRANULARITY allows it.
|
|
|
+ ((memq granularity '(object nil))
|
|
|
+ (org-element--parse-objects
|
|
|
+ cbeg (org-element-property :contents-end element) element
|
|
|
+ (org-element-restriction type))))
|
|
|
+ (push (org-element-put-property element :parent acc) elements)
|
|
|
+ ;; Update mode.
|
|
|
+ (setq mode (org-element--next-mode mode type nil)))))
|
|
|
;; Return result.
|
|
|
(apply #'org-element-set-contents acc (nreverse elements)))))
|
|
|
|