org-element: Refactor code
This commit is contained in:
parent
29e633f7cd
commit
fcd4418a70
|
@ -2985,29 +2985,7 @@ Nil values returned from FUN are ignored in the result."
|
||||||
(assq (car el)
|
(assq (car el)
|
||||||
org-element-string-restrictions))))
|
org-element-string-restrictions))))
|
||||||
collect (car el))))
|
collect (car el))))
|
||||||
--walk-tree ; For byte-compiler
|
|
||||||
--acc
|
--acc
|
||||||
(--check-blob
|
|
||||||
(function
|
|
||||||
(lambda (--type types fun --blob)
|
|
||||||
;; Check if TYPE is matching among TYPES. If so, apply
|
|
||||||
;; FUN to --BLOB and accumulate return value into --ACC.
|
|
||||||
;; INFO is the communication channel. If --BLOB has
|
|
||||||
;; a secondary string that can contain objects with their
|
|
||||||
;; type amond TYPES, look into that string first.
|
|
||||||
(when (memq --type types)
|
|
||||||
(let ((result (funcall fun --blob)))
|
|
||||||
(cond ((not result))
|
|
||||||
(first-match (throw 'first-match result))
|
|
||||||
(t (push result --acc)))))
|
|
||||||
(when (memq --type --restricts)
|
|
||||||
(funcall
|
|
||||||
--walk-tree
|
|
||||||
`(org-data
|
|
||||||
nil
|
|
||||||
,@(org-element-property
|
|
||||||
(cdr (assq --type org-element-secondary-value-alist))
|
|
||||||
--blob)))))))
|
|
||||||
(--walk-tree
|
(--walk-tree
|
||||||
(function
|
(function
|
||||||
(lambda (--data)
|
(lambda (--data)
|
||||||
|
@ -3015,31 +2993,34 @@ Nil values returned from FUN are ignored in the result."
|
||||||
;; a plist holding contextual information.
|
;; a plist holding contextual information.
|
||||||
(mapc
|
(mapc
|
||||||
(lambda (--blob)
|
(lambda (--blob)
|
||||||
(let ((--type (org-element-type --blob)))
|
(unless (and info (member --blob (plist-get info :ignore-list)))
|
||||||
;; Determine if a recursion into --BLOB is
|
(let ((--type (org-element-type --blob)))
|
||||||
;; possible and allowed.
|
;; Check if TYPE is matching among TYPES. If so,
|
||||||
(cond
|
;; apply FUN to --BLOB and accumulate return value
|
||||||
;; Element or object not exportable.
|
;; into --ACC (or exit if FIRST-MATCH is non-nil).
|
||||||
((and info (member --blob (plist-get info :ignore-list))))
|
(when (memq --type types)
|
||||||
;; Limiting recursion to greater elements, and --BLOB
|
(let ((result (funcall fun --blob)))
|
||||||
;; isn't one.
|
(cond ((not result))
|
||||||
((and (eq --category 'greater-elements)
|
(first-match (throw 'first-match result))
|
||||||
(not (memq --type org-element-greater-elements)))
|
(t (push result --acc)))))
|
||||||
(funcall --check-blob --type types fun --blob))
|
;; If --BLOB has a secondary string that can
|
||||||
;; Limiting recursion to elements, and --BLOB only
|
;; contain objects with their type among TYPES,
|
||||||
;; contains objects.
|
;; look into that string.
|
||||||
((and (eq --category 'elements) (eq --type 'paragraph))
|
(when (memq --type --restricts)
|
||||||
(funcall --check-blob --type types fun --blob))
|
(funcall
|
||||||
;; No limitation on recursion, but --BLOB hasn't
|
--walk-tree
|
||||||
;; got a recursive type.
|
`(org-data
|
||||||
((and (eq --category 'objects)
|
nil
|
||||||
(not (or (eq --type 'paragraph)
|
,@(org-element-property
|
||||||
(memq --type org-element-greater-elements)
|
(cdr (assq --type org-element-secondary-value-alist))
|
||||||
(memq --type org-element-recursive-objects))))
|
--blob))))
|
||||||
(funcall --check-blob --type types fun --blob))
|
;; Now determine if a recursion into --BLOB is
|
||||||
;; Recursion is possible and allowed: Maybe apply
|
;; possible. If so, do it.
|
||||||
;; FUN to --BLOB, then move into it.
|
(when (or (memq --type org-element-recursive-objects)
|
||||||
(t (funcall --check-blob --type types fun --blob)
|
(and (memq --type org-element-all-elements)
|
||||||
|
(not (eq --category 'elements)))
|
||||||
|
(and (memq --type org-element-greater-elements)
|
||||||
|
(not (eq --category 'greater-elements))))
|
||||||
(funcall --walk-tree --blob)))))
|
(funcall --walk-tree --blob)))))
|
||||||
(org-element-contents --data))))))
|
(org-element-contents --data))))))
|
||||||
(catch 'first-match
|
(catch 'first-match
|
||||||
|
|
Loading…
Reference in New Issue