(defsubst org-element-contents (element)
"Extract contents from an ELEMENT."
- (and (consp element) (nthcdr 2 element)))
+ (cond ((not (consp element)) nil)
+ ((symbolp (car element)) (nthcdr 2 element))
+ (t element)))
(defsubst org-element-restriction (element)
"Return restriction associated to ELEMENT.
"Set ELEMENT contents to CONTENTS.
Return modified element."
(cond ((not element) (list contents))
+ ((not (symbolp (car element))) contents)
((cdr element) (setcdr (cdr element) contents))
(t (nconc element contents))))
The function takes care of setting `:parent' property for CHILD.
Return parent element."
- (if (not parent) children
- ;; Link every child to PARENT.
- (mapc (lambda (child) (org-element-put-property child :parent parent))
- children)
- ;; Add CHILDREN at the end of PARENT contents.
+ ;; Link every child to PARENT. If PARENT is nil, it is a secondary
+ ;; string: parent is the list itself.
+ (mapc (lambda (child)
+ (org-element-put-property child :parent (or parent children)))
+ children)
+ ;; Add CHILDREN at the end of PARENT contents.
+ (when parent
(apply 'org-element-set-contents
parent
- (nconc (org-element-contents parent) children))
- ;; Return modified PARENT element.
- parent))
+ (nconc (org-element-contents parent) children)))
+ ;; Return modified PARENT element.
+ (or parent children))
\f
(insert string)
(let ((secondary (org-element--parse-objects
(point-min) (point-max) nil restriction)))
- (mapc (lambda (obj) (org-element-put-property obj :parent parent))
- secondary))))
+ (when parent
+ (mapc (lambda (obj) (org-element-put-property obj :parent parent))
+ secondary))
+ secondary)))
(defun org-element-map
(data types fun &optional info first-match no-recursion with-affiliated)