org-element-create: Allow single &rest argument as a list

* lisp/org-element-ast.el (org-element-create): Add special case when
CHILDREN contains a single list of Org notes:

  (let ((children (list a b c ...)))
    (org-element-create 'type nil children))

This will simplify creating new elements when children are stored in a
list.
This commit is contained in:
Ihor Radchenko 2023-05-03 14:19:29 +02:00
parent 6333a20aa5
commit ea9d5b45db
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 11 additions and 1 deletions

View File

@ -905,6 +905,12 @@ Optional argument PROPS, when non-nil, is a plist defining the
properties of the node. CHILDREN can be elements, objects or
strings.
When CHILDREN is a single anonymous node, use its contents as children
nodes. This way,
(org-element-create 'section nil (org-element-contents node))
will yield expected results with contents of another node adopted into
a newly created one.
When TYPE is `plain-text', CHILDREN must contain a single node -
string. Alternatively, TYPE can be a string. When TYPE is nil or
`anonymous', PROPS must be nil."
@ -934,7 +940,11 @@ string. Alternatively, TYPE can be a string. When TYPE is nil or
(org-add-props (car children) props))
((pred stringp)
(if props (org-add-props type props) type))
(_ (apply #'org-element-adopt (list type props) children))))
(_
(if (and (= 1 (length children))
(org-element-type-p (car children) 'anonymous))
(apply #'org-element-adopt (list type props) (car children))
(apply #'org-element-adopt (list type props) children)))))
(defun org-element-copy (datum &optional keep-contents)
"Return a copy of DATUM.