diff --git a/lisp/org-element.el b/lisp/org-element.el index d7847a678..f8442511c 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -548,7 +548,14 @@ Return modified element." "Set ELEMENT's contents to CONTENTS. Return ELEMENT." (cond ((null element) contents) - ((not (symbolp (car element))) contents) + ((not (symbolp (car element))) + (if (not (listp element)) + ;; Non-element. + contents + ;; Anonymous element (el1 el2 ...) + (setcar element (car contents)) + (setcdr element (cdr contents)) + element)) ((cdr element) (setcdr (cdr element) contents) element) (t (nconc element contents)))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 43f1d860f..957e99194 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -125,7 +125,13 @@ Some other text (org-test-with-temp-text "* Headline\n *a*" (let ((tree (org-element-parse-buffer))) (org-element-set-contents (org-element-map tree 'bold 'identity nil t)) - (org-element-contents (org-element-map tree 'bold 'identity nil t)))))) + (org-element-contents (org-element-map tree 'bold 'identity nil t))))) + ;; Set contents of anonymous elements. + (should + (equal '#1=((b (:parent #1#))) + (let ((element '#1=((a (:parent #1#)) (b (:parent #1#))))) + (org-element-set-contents element `(b (:parent ,element))) + element)))) (ert-deftest test-org-element/secondary-p () "Test `org-element-secondary-p' specifications."