summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-29 19:03:54 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-29 19:03:54 +0100
commitc7f4a9ebad99fd065155e12d53807b1dbd7170dc (patch)
treebca4e5cf324d97eb559d673fb8d41f4f3fc3581b
parent07c889570538c332ccf4f6d67c4040718a202f0e (diff)
downloadorg-mode-c7f4a9ebad99fd065155e12d53807b1dbd7170dc.tar.gz
org-element: Fix accessors and setters wrt secondary strings
* lisp/org-element.el (org-element-contents, org-element-set-contents, org-element-adopt-elements): Fix accessors and setters wrt secondary strings.
-rw-r--r--lisp/org-element.el29
1 files changed, 18 insertions, 11 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 5c06f72..1e18553 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -391,7 +391,9 @@ It can also return the following special value:
(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.
@@ -411,6 +413,7 @@ Return modified 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))))
@@ -439,16 +442,18 @@ objects, or a strings.
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))
@@ -3943,8 +3948,10 @@ containing the secondary string. It is used to set correctly
(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)