emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org ea9d5b45db 012/101: org-element-create: Allow singl


From: ELPA Syncer
Subject: [elpa] externals/org ea9d5b45db 012/101: org-element-create: Allow single &rest argument as a list
Date: Sat, 1 Jul 2023 09:58:52 -0400 (EDT)

branch: externals/org
commit ea9d5b45db19493a81f342c539b656049a12daca
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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.
---
 lisp/org-element-ast.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/org-element-ast.el b/lisp/org-element-ast.el
index a98e879c13..c575f2aad7 100644
--- a/lisp/org-element-ast.el
+++ b/lisp/org-element-ast.el
@@ -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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]