Function: dom-add-child-before
dom-add-child-before is a byte-compiled function defined in dom.el.gz.
Signature
(dom-add-child-before NODE CHILD &optional BEFORE)
Documentation
Add CHILD to NODE's children before child BEFORE.
If BEFORE is nil, make CHILD NODE's first child.
Source Code
;; Defined in /usr/src/emacs/lisp/dom.el.gz
(defun dom-add-child-before (node child &optional before)
"Add CHILD to NODE's children before child BEFORE.
If BEFORE is nil, make CHILD NODE's first child."
(setq node (dom-ensure-node node))
(let ((children (dom-children node)))
(when (and before
(not (memq before children)))
(error "%s does not exist as a child" before))
(let ((pos (if before
(cl-position before children)
0)))
(if (zerop pos)
;; First child.
(setcdr (cdr node) (cons child (cddr node)))
(setcdr (nthcdr (1- pos) children)
(cons child (nthcdr pos children))))))
node)