unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Where is ewoc--node-delete
@ 2006-05-19  9:50 Stefan Reichör
  2006-05-19 22:22 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Reichör @ 2006-05-19  9:50 UTC (permalink / raw)


Hi!

Why was ewoc--node-delete removed?

>From ewoc.el:
;; An ewoc is a very dynamic thing.  You can easily add or delete elements.
;; You can apply a function to all elements in an ewoc, etc, etc.

So, how can one now remove a node?


Stefan.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-19  9:50 Where is ewoc--node-delete Stefan Reichör
@ 2006-05-19 22:22 ` Thien-Thi Nguyen
  2006-05-20 19:14   ` Stefan Reichör
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2006-05-19 22:22 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Reichör <stefan@xsteve.at> writes:

> Why was ewoc--node-delete removed?

it was merged into its unique caller, the rationale being
that "internal" (i.e., "ewoc--" -- note double hyphen) interfaces
should not be multiplied needlessly.
 
> So, how can one now remove a node?

you can use `ewoc-filter' to remove nodes.  for example:

(defun my-delete-nodes-with-data (ewoc data)
  (ewoc-filter ewoc (lambda (d) (not (eq data d)))))

if your program is calling `ewoc--node-delete' within a loop,
that is a good chance to restructure it to let `ewoc-filter'
do the looping.

if not, perhaps it would be best to add `ewoc-delete-node'
w/ the body of the former `ewoc--node-delete'.

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-19 22:22 ` Thien-Thi Nguyen
@ 2006-05-20 19:14   ` Stefan Reichör
  2006-05-21  8:38     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Reichör @ 2006-05-20 19:14 UTC (permalink / raw)
  Cc: emacs-devel

Thien-Thi Nguyen <ttn@gnu.org> writes:

> Stefan Reichör <stefan@xsteve.at> writes:
>
>> Why was ewoc--node-delete removed?
>
> it was merged into its unique caller, the rationale being
> that "internal" (i.e., "ewoc--" -- note double hyphen) interfaces
> should not be multiplied needlessly.
>  
>> So, how can one now remove a node?
>
> you can use `ewoc-filter' to remove nodes.  for example:
>
> (defun my-delete-nodes-with-data (ewoc data)
>   (ewoc-filter ewoc (lambda (d) (not (eq data d)))))
>
> if your program is calling `ewoc--node-delete' within a loop,
> that is a good chance to restructure it to let `ewoc-filter'
> do the looping.
>
> if not, perhaps it would be best to add `ewoc-delete-node'
> w/ the body of the former `ewoc--node-delete'.

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.


Stefan.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-20 19:14   ` Stefan Reichör
@ 2006-05-21  8:38     ` Thien-Thi Nguyen
  2006-05-21 11:33       ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2006-05-21  8:38 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Reichör <stefan@xsteve.at> 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))

thi


_____________________________________________________
(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))))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-21  8:38     ` Thien-Thi Nguyen
@ 2006-05-21 11:33       ` Stefan Monnier
  2006-05-21 11:36         ` David Kastrup
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2006-05-21 11:33 UTC (permalink / raw)
  Cc: Stefan Reichör, emacs-devel

> As a special case, if PREDICATE is t, ARGS specifies nodes to be
> deleted unconditionally."

This is very ugly.


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-21 11:33       ` Stefan Monnier
@ 2006-05-21 11:36         ` David Kastrup
  2006-05-21 13:05           ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: David Kastrup @ 2006-05-21 11:36 UTC (permalink / raw)
  Cc: Thien-Thi Nguyen, Stefan Reichör, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> As a special case, if PREDICATE is t, ARGS specifies nodes to be
>> deleted unconditionally."
>
> This is very ugly.

Sort of what an XEmacs interface would look like...  At the very
least, we should have a wrapper to ewoc-filter doing that.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-21 11:36         ` David Kastrup
@ 2006-05-21 13:05           ` Stefan Monnier
  2006-05-21 14:29             ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2006-05-21 13:05 UTC (permalink / raw)
  Cc: Thien-Thi Nguyen, Stefan Reichör, emacs-devel

>>> As a special case, if PREDICATE is t, ARGS specifies nodes to be
>>> deleted unconditionally."
>> 
>> This is very ugly.

> Sort of what an XEmacs interface would look like...  At the very
> least, we should have a wrapper to ewoc-filter doing that.

(ewoc-filter ewoc (lambda (node nodes) (not (memq node nodes))) nodes)


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-21 13:05           ` Stefan Monnier
@ 2006-05-21 14:29             ` Thien-Thi Nguyen
  2006-05-21 21:55               ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2006-05-21 14:29 UTC (permalink / raw)
  Cc: Stefan Reichör, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> (ewoc-filter ewoc (lambda (node nodes) (not (memq node nodes))) nodes)

this would be great if the predicate were applied to each node,
rather than to each data element.

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Where is ewoc--node-delete
  2006-05-21 14:29             ` Thien-Thi Nguyen
@ 2006-05-21 21:55               ` Thien-Thi Nguyen
  0 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2006-05-21 21:55 UTC (permalink / raw)
  Cc: emacs-devel

after some thought i have changed my mind and
now agree w/ a need for a function to delete nodes.

does the following give good results?

thi


__________________________________________
(defun ewoc-delete (ewoc &rest nodes)
  "Delete NODES from EWOC."
  (ewoc--set-buffer-bind-dll-let* ewoc
      ((L nil) (R nil))
    (dolist (node nodes)
      ;; 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))))

(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."
  (ewoc--set-buffer-bind-dll-let* ewoc
      ((node (ewoc--node-nth dll 1))
       (footer (ewoc--footer ewoc))
       (goodbye nil)
       (inhibit-read-only t))
    (while (not (eq node footer))
      (unless (apply predicate (ewoc--node-data node) args)
        (push node goodbye))
      (setq node (ewoc--node-next dll node)))
    (apply 'ewoc-delete ewoc goodbye)))

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-05-21 21:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-19  9:50 Where is ewoc--node-delete Stefan Reichör
2006-05-19 22:22 ` Thien-Thi Nguyen
2006-05-20 19:14   ` Stefan Reichör
2006-05-21  8:38     ` Thien-Thi Nguyen
2006-05-21 11:33       ` Stefan Monnier
2006-05-21 11:36         ` David Kastrup
2006-05-21 13:05           ` Stefan Monnier
2006-05-21 14:29             ` Thien-Thi Nguyen
2006-05-21 21:55               ` Thien-Thi Nguyen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).