[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 54fe3b6 1/3: Add new function dom-remove-node
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 54fe3b6 1/3: Add new function dom-remove-node |
Date: |
Mon, 27 Jun 2016 20:26:16 +0000 (UTC) |
branch: master
commit 54fe3b6ec0557941c5759523b36bfdec21003f77
Author: Lars Magne Ingebrigtsen <address@hidden>
Commit: Lars Magne Ingebrigtsen <address@hidden>
Add new function dom-remove-node
* doc/lispref/text.texi (Document Object Model): Document
dom-remove-node.
* lisp/dom.el (dom-remove-node): New function.
---
doc/lispref/text.texi | 3 +++
lisp/dom.el | 11 +++++++++++
2 files changed, 14 insertions(+)
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 43d4945..4dc943f 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -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}.
+
address@hidden dom-remove @var{dom} @var{node}
+Remove @var{node} from @var{dom}.
@end table
The following are functions for altering the @acronym{DOM}.
diff --git a/lisp/dom.el b/lisp/dom.el
index 03fe759..cf3a02a 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -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))