org-element-insert-before: Fix return value when setting plain-text
* lisp/org-element-ast.el (org-element-set-element): When setting plain-text node, return the new node instead of immutable old one. * testing/lisp/test-org-element.el (test-org-element/set): Add test.
This commit is contained in:
parent
755fef38f5
commit
286a8fb798
|
@ -1131,8 +1131,11 @@ The function takes care of setting `:parent' property for NEW."
|
|||
(eq new-type 'plain-text))
|
||||
;; We cannot replace OLD with NEW since strings are not mutable.
|
||||
;; We take the long path.
|
||||
(progn (org-element-insert-before new old)
|
||||
(org-element-extract old))
|
||||
(progn
|
||||
(org-element-insert-before new old)
|
||||
(org-element-extract old)
|
||||
;; We will return OLD.
|
||||
(setq old new))
|
||||
;; Since OLD is going to be changed into NEW by side-effect, first
|
||||
;; make sure that every element or object within NEW has OLD as
|
||||
;; parent.
|
||||
|
|
|
@ -755,6 +755,15 @@ Some other text
|
|||
(text (org-element-map tree 'plain-text 'identity nil t)))
|
||||
(org-element-set text "b")
|
||||
(org-element-map tree 'plain-text 'identity nil t)))))
|
||||
;; Replace string inside anonymous element with another string.
|
||||
(let* ((parent (org-element-create 'anonymous nil "test"))
|
||||
(str (car (org-element-contents parent))))
|
||||
(let ((return (org-element-set str "repl"))
|
||||
(new (car (org-element-contents parent))))
|
||||
;; Return the modified value.
|
||||
(should (eq return new))
|
||||
(should (equal new "repl"))
|
||||
(should (eq (org-element-parent new) parent))))
|
||||
;; KEEP-PROPS
|
||||
(should
|
||||
(org-element-property
|
||||
|
|
Loading…
Reference in New Issue