Mercurial > emacs
comparison lisp/emacs-lisp/ewoc.el @ 70851:9119e54a8121
(ewoc-delete): New function.
(ewoc-filter): Use `ewoc-delete'.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Tue, 23 May 2006 07:30:20 +0000 |
parents | fd87105a0d34 |
children | 5fd02ab03d96 |
comparison
equal
deleted
inserted
replaced
70850:b90abedf3b79 | 70851:9119e54a8121 |
---|---|
105 ;; (defun ewoc-next (ewoc node) | 105 ;; (defun ewoc-next (ewoc node) |
106 ;; (defun ewoc-prev (ewoc node) | 106 ;; (defun ewoc-prev (ewoc node) |
107 ;; (defun ewoc-nth (ewoc n) | 107 ;; (defun ewoc-nth (ewoc n) |
108 ;; (defun ewoc-map (map-function ewoc &rest args) | 108 ;; (defun ewoc-map (map-function ewoc &rest args) |
109 ;; (defun ewoc-filter (ewoc predicate &rest args) | 109 ;; (defun ewoc-filter (ewoc predicate &rest args) |
110 ;; (defun ewoc-delete (ewoc &rest nodes) | |
110 ;; (defun ewoc-locate (ewoc &optional pos guess) | 111 ;; (defun ewoc-locate (ewoc &optional pos guess) |
111 ;; (defun ewoc-invalidate (ewoc &rest nodes) | 112 ;; (defun ewoc-invalidate (ewoc &rest nodes) |
112 ;; (defun ewoc-goto-prev (ewoc arg) | 113 ;; (defun ewoc-goto-prev (ewoc arg) |
113 ;; (defun ewoc-goto-next (ewoc arg) | 114 ;; (defun ewoc-goto-next (ewoc arg) |
114 ;; (defun ewoc-goto-node (ewoc node) | 115 ;; (defun ewoc-goto-node (ewoc node) |
374 (while (not (eq node footer)) | 375 (while (not (eq node footer)) |
375 (if (apply map-function (ewoc--node-data node) args) | 376 (if (apply map-function (ewoc--node-data node) args) |
376 (ewoc--refresh-node pp node)) | 377 (ewoc--refresh-node pp node)) |
377 (setq node (ewoc--node-next dll node)))))) | 378 (setq node (ewoc--node-next dll node)))))) |
378 | 379 |
380 (defun ewoc-delete (ewoc &rest nodes) | |
381 "Delete NODES from EWOC." | |
382 (ewoc--set-buffer-bind-dll-let* ewoc | |
383 ((L nil) (R nil)) | |
384 (dolist (node nodes) | |
385 ;; If we are about to delete the node pointed at by last-node, | |
386 ;; set last-node to nil. | |
387 (if (eq (ewoc--last-node ewoc) node) | |
388 (setf (ewoc--last-node ewoc) nil)) | |
389 (delete-region (ewoc--node-start-marker node) | |
390 (ewoc--node-start-marker (ewoc--node-next dll node))) | |
391 (set-marker (ewoc--node-start-marker node) nil) | |
392 (setf L (ewoc--node-left node) | |
393 R (ewoc--node-right node) | |
394 ;; Link neighbors to each other. | |
395 (ewoc--node-right L) R | |
396 (ewoc--node-left R) L | |
397 ;; Forget neighbors. | |
398 (ewoc--node-left node) nil | |
399 (ewoc--node-right node) nil)))) | |
400 | |
379 (defun ewoc-filter (ewoc predicate &rest args) | 401 (defun ewoc-filter (ewoc predicate &rest args) |
380 "Remove all elements in EWOC for which PREDICATE returns nil. | 402 "Remove all elements in EWOC for which PREDICATE returns nil. |
381 Note that the buffer for EWOC will be current-buffer when PREDICATE | 403 Note that the buffer for EWOC will be current-buffer when PREDICATE |
382 is called. PREDICATE must restore the current buffer before it returns | 404 is called. PREDICATE must restore the current buffer before it returns |
383 if it changes it. | 405 if it changes it. |
384 The PREDICATE is called with the element as its first argument. If any | 406 The PREDICATE is called with the element as its first argument. If any |
385 ARGS are given they will be passed to the PREDICATE." | 407 ARGS are given they will be passed to the PREDICATE." |
386 (ewoc--set-buffer-bind-dll-let* ewoc | 408 (ewoc--set-buffer-bind-dll-let* ewoc |
387 ((node (ewoc--node-nth dll 1)) | 409 ((node (ewoc--node-nth dll 1)) |
388 (footer (ewoc--footer ewoc)) | 410 (footer (ewoc--footer ewoc)) |
389 (next nil) | 411 (goodbye nil) |
390 (L nil) (R nil) | |
391 (inhibit-read-only t)) | 412 (inhibit-read-only t)) |
392 (while (not (eq node footer)) | 413 (while (not (eq node footer)) |
393 (setq next (ewoc--node-next dll node)) | |
394 (unless (apply predicate (ewoc--node-data node) args) | 414 (unless (apply predicate (ewoc--node-data node) args) |
395 ;; If we are about to delete the node pointed at by last-node, | 415 (push node goodbye)) |
396 ;; set last-node to nil. | 416 (setq node (ewoc--node-next dll node))) |
397 (if (eq (ewoc--last-node ewoc) node) | 417 (apply 'ewoc-delete ewoc goodbye))) |
398 (setf (ewoc--last-node ewoc) nil)) | |
399 (delete-region (ewoc--node-start-marker node) | |
400 (ewoc--node-start-marker (ewoc--node-next dll node))) | |
401 (set-marker (ewoc--node-start-marker node) nil) | |
402 (setf L (ewoc--node-left node) | |
403 R (ewoc--node-right node) | |
404 ;; Link neighbors to each other. | |
405 (ewoc--node-right L) R | |
406 (ewoc--node-left R) L | |
407 ;; Forget neighbors. | |
408 (ewoc--node-left node) nil | |
409 (ewoc--node-right node) nil)) | |
410 (setq node next)))) | |
411 | 418 |
412 (defun ewoc-locate (ewoc &optional pos guess) | 419 (defun ewoc-locate (ewoc &optional pos guess) |
413 "Return the node that POS (a buffer position) is within. | 420 "Return the node that POS (a buffer position) is within. |
414 POS may be a marker or an integer. It defaults to point. | 421 POS may be a marker or an integer. It defaults to point. |
415 GUESS should be a node that it is likely to be near POS. | 422 GUESS should be a node that it is likely to be near POS. |