[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where is ewoc--node-delete

From: Thien-Thi Nguyen
Subject: Re: Where is ewoc--node-delete
Date: 21 May 2006 04:38:03 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Stefan Reichör <address@hidden> writes:

> I think the ewoc-delete-node is missing.  One could
> use the ewoc-filter trick above, but it is not the
> obvious way to delete a node.
> So please (re)add ewoc-delete-node.

i think it is better to avoid introducing "ewoc-delete-node"
for now, if we can.  can you use the `ewoc-filter' (below),
instead?  here is an "ewoc-delete-node" implementation
that uses it:

(defun ewoc-delete-node (ewoc node)
  (ewoc-filter ewoc t node))


(defun ewoc-filter (ewoc predicate &rest args)
  "Remove all elements in EWOC for which PREDICATE returns nil.
Note that the buffer for EWOC will be current-buffer when PREDICATE
is called.  PREDICATE must restore the current buffer before it returns
if it changes it.
The PREDICATE is called with the element as its first argument.  If any
ARGS are given they will be passed to the PREDICATE.
As a special case, if PREDICATE is t, ARGS specifies nodes to be
deleted unconditionally."
  (ewoc--set-buffer-bind-dll-let* ewoc
      ((node (ewoc--node-nth dll 1))
       (footer (ewoc--footer ewoc))
       (next nil)
       (L nil) (R nil)
       (goodbye nil)
       (inhibit-read-only t))
    (cond ((eq t predicate)
           (setq goodbye args))
          (t (while (not (eq node footer))
               (setq next (ewoc--node-next dll node))
               (unless (apply predicate (ewoc--node-data node) args)
                 (push node goodbye))
               (setq node next))))
    (dolist (node goodbye)
      ;; If we are about to delete the node pointed at by last-node,
      ;; set last-node to nil.
      (if (eq (ewoc--last-node ewoc) node)
          (setf (ewoc--last-node ewoc) nil))
      (delete-region (ewoc--node-start-marker node)
                     (ewoc--node-start-marker (ewoc--node-next dll node)))
      (set-marker (ewoc--node-start-marker node) nil)
      (setf L (ewoc--node-left  node)
            R (ewoc--node-right node)
            ;; Link neighbors to each other.
            (ewoc--node-right L) R
            (ewoc--node-left  R) L
            ;; Forget neighbors.
            (ewoc--node-left  node) nil
            (ewoc--node-right node) nil))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]