]> code.delx.au - gnu-emacs/commitdiff
Add new function dom-remove-node
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 27 Jun 2016 20:20:29 +0000 (22:20 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 27 Jun 2016 20:20:29 +0000 (22:20 +0200)
* doc/lispref/text.texi (Document Object Model): Document
dom-remove-node.

* lisp/dom.el (dom-remove-node): New function.

doc/lispref/text.texi
lisp/dom.el

index 43d4945b685c1c9ba1a12b5eb415619b26a06dba..4dc943f868b799cdada71f7f4c55aca28ef8f204 100644 (file)
@@ -4614,6 +4614,9 @@ to be inserted between the textual elements.
 
 @item dom-parent @var{dom} @var{node}
 Return the parent of @var{node} in @var{dom}.
+
+@item dom-remove @var{dom} @var{node}
+Remove @var{node} from @var{dom}.
 @end table
 
 The following are functions for altering the @acronym{DOM}.
index 03fe75975a423e5e9c9d022dd247671888b772ec..cf3a02a51dbcc1d0963e2a77d673f2422ac677b8 100644 (file)
@@ -139,6 +139,16 @@ ATTRIBUTE would typically be `class', `id' or the like."
        (cons dom matches)
       matches)))
 
+(defun dom-remove-node (dom node)
+  "Remove NODE from DOM."
+  ;; If we're removing the top level node, just return nil.
+  (dolist (child (dom-children dom))
+    (cond
+     ((eq node child)
+      (delq node dom))
+     ((not (stringp child))
+      (dom-remove-node child node)))))
+
 (defun dom-parent (dom node)
   "Return the parent of NODE in DOM."
   (if (memq node (dom-children dom))
@@ -151,6 +161,7 @@ ATTRIBUTE would typically be `class', `id' or the like."
       result)))
 
 (defun dom-previous-sibling (dom node)
+  "Return the previous sibling of NODE in DOM."
   (when-let (parent (dom-parent dom node))
     (let ((siblings (dom-children parent))
          (previous nil))