diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-06-23 11:18:36 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-06-23 15:22:03 +0200 |
commit | 7ee2d9312243f69f77933217c260061c7efae15a (patch) | |
tree | 2e52d0e9ef928772fff5285b16d4141bff784edc | |
parent | 0a45e4fcbc39f710468c90972221b2a78ddd7b91 (diff) | |
download | org-mode-7ee2d9312243f69f77933217c260061c7efae15a.tar.gz |
org-element: Implement `org-element-create'
* lisp/org-element.el (org-element-create): New function.
(org-element-adopt-elements): Small refactoring.
-rw-r--r-- | lisp/org-element.el | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el index d9aa79f..29c5464 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -489,18 +489,18 @@ objects, or a strings. The function takes care of setting `:parent' property for CHILD. Return parent element." - ;; 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. - (or parent children)) + (if (not children) parent + ;; Link every child to PARENT. If PARENT is nil, it is a secondary + ;; string: parent is the list itself. + (dolist (child children) + (org-element-put-property child :parent (or parent 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. + (or parent children))) (defun org-element-extract-element (element) "Extract ELEMENT from parse tree. @@ -573,6 +573,13 @@ The function takes care of setting `:parent' property for NEW." ;; Transfer type. (setcar old (car new)))) +(defun org-element-create (type &optional props &rest children) + "Create a new element of type TYPE. +Optional argument PROPS, when non-nil, is a plist defining the +properties of the element. CHILDREN can be elements, objects or +strings." + (apply #'org-element-adopt-elements (list type props) children)) + (defun org-element-copy (datum) "Return a copy of DATUM. DATUM is an element, object, string or nil. `:parent' property |