lisp/org-element-ast.el (org-element-copy): Fix altering source element

* testing/lisp/test-org-element.el (test-org-element/copy): Add new
test case.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/e0252d664af25728243734d67432ad64@posteo.net
This commit is contained in:
Ihor Radchenko 2024-01-03 15:41:18 +01:00
parent d57d3bd9bb
commit dfeff03c5a
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 9 additions and 3 deletions

View File

@ -810,8 +810,8 @@ When DATUM is `plain-text', all the properties are removed."
(org-element-put-property (car tail) :parent node-copy)
(setq tail (cdr tail)))
node-copy))
(_
(let ((node-copy (copy-sequence datum)))
(type
(let ((node-copy (append (list type (copy-sequence (cadr datum))) (copy-sequence (cddr datum)))))
;; Copy `:standard-properties'
(when-let ((parray (org-element-property-raw :standard-properties node-copy)))
(org-element-put-property node-copy :standard-properties (copy-sequence parray)))

View File

@ -794,7 +794,13 @@ Some other text
(should-not (org-element-copy nil))
;; Return a copy secondary strings.
(should (equal '("text") (org-element-copy '("text"))))
(should-not (eq '("text") (org-element-copy '("text")))))
(should-not (eq '("text") (org-element-copy '("text"))))
;; Do not alter the source.
(org-test-with-temp-text "*bold*"
(let* ((source (org-element-context))
(copy (org-element-copy source)))
(should-not (org-element-parent copy))
(should (org-element-parent source)))))