X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/36a50f38fbbcf5cc0cafc44af9d1bfcd6c13fc25..1bd74554970450054c874dbb69837b43f783c6bd:/lisp/dom.el diff --git a/lisp/dom.el b/lisp/dom.el index 42131073a0..cf3a02a51d 100644 --- a/lisp/dom.el +++ b/lisp/dom.el @@ -1,6 +1,6 @@ ;;; dom.el --- XML/HTML (etc.) DOM manipulation and searching functions -;; Copyright (C) 2014-2015 Free Software Foundation, Inc. +;; Copyright (C) 2014-2016 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: xml, html @@ -25,6 +25,7 @@ ;;; Code: (require 'cl-lib) +(eval-when-compile (require 'subr-x)) (defsubst dom-tag (node) "Return the NODE tag." @@ -138,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)) @@ -150,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))