org-element-set-contents: Do alter the anonymous parents

* lisp/org-element.el (org-element-set-contents): Do alter anonymous
elements (el1 el2 ...).  Such elements are used, for example, when
parsing keyword values during export, like :title.
* testing/lisp/test-org-element.el (test-org-element/set-contents):
Add test.

The patch fixed bug during export when exporting a subtree with
option stat:nil.  The :title during subtree export is taken from the
heading title and parsed.  However, the parsed value is stored outside
the parse tree, in :title property of the INFO channel.  The parsed
value does get filtered through `org-export--prune-tree', but before
this commit, `org-element-set-contents' did not actually alter the
out-of-AST-tree parent lists of elements.

Reported-by: Leo Butler <Leo.Butler@umanitoba.ca>
Link: https://orgmode.org/list/87mt4w8epo.fsf@t14.reltub.ca
This commit is contained in:
Ihor Radchenko 2023-03-03 16:31:37 +01:00
parent 973669389b
commit f93cc661c6
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 15 additions and 2 deletions

View File

@ -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))))

View File

@ -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."