Function: org-element-copy

org-element-copy is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element-copy DATUM)

Documentation

Return a copy of DATUM.

DATUM is an element, object, string or nil. :parent property is cleared and contents are removed in the process.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defun org-element-copy (datum)
  "Return a copy of DATUM.
DATUM is an element, object, string or nil.  `:parent' property
is cleared and contents are removed in the process."
  (when datum
    (let ((type (org-element-type datum)))
      (pcase type
	(`org-data (list 'org-data nil))
	(`plain-text (substring-no-properties datum))
	(`nil (copy-sequence datum))
	(_
         (let ((element-copy (list type (plist-put (copy-sequence (nth 1 datum)) :parent nil))))
           ;; We cannot simply return the copies property list.  When
           ;; DATUM is i.e. a headline, it's property list (`:title'
           ;; in case of headline) can contain parsed objects.  The
           ;; objects will contain `:parent' property set to the DATUM
           ;; itself.  When copied, these inner `:parent' property
           ;; values will contain incorrect object decoupled from
           ;; DATUM.  Changes to the DATUM copy will not longer be
           ;; reflected in the `:parent' properties.  So, we need to
           ;; reassign inner `:parent' properties to the DATUM copy
           ;; explicitly.
           (org-element-map element-copy (cons 'plain-text org-element-all-objects)
             (lambda (obj) (when (equal datum (org-element-property :parent obj))
                        (org-element-put-property obj :parent element-copy))))
           element-copy))))))