("latin-1-prefix"): Change ~s to give \e,A'\e(B and
[emacs.git] / lisp / emacs-lisp / ewoc.el
blobbcf8a732a1dfb89df2bbdc4486f252fbd2d51d12
1 ;;; ewoc.el -- Utility to maintain a view of a list of objects in a buffer
3 ;; Copyright (C) 1991-2000 Free Software Foundation
5 ;; Author: Per Cederqvist <ceder@lysator.liu.se>
6 ;; Inge Wallin <inge@lysator.liu.se>
7 ;; Maintainer: monnier@gnu.org
8 ;; Created: 3 Aug 1992
9 ;; Keywords: extensions, lisp
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
28 ;;; Commentary:
30 ;; Ewoc Was Once Cookie
31 ;; But now it's Emacs' Widget for Object Collections
33 ;; As the name implies this derives from the `cookie' package (part
34 ;; of Elib). The changes are mostly superficial:
36 ;; - uses CL (and its `defstruct'
37 ;; - separate from Elib.
38 ;; - uses its own version of a doubly-linked list which allows us
39 ;; to merge the elib-wrapper and the elib-node structures into ewoc-node
40 ;; - dropping functions not used by PCL-CVS (the only client of ewoc at the
41 ;; time of writing)
42 ;; - removing unused arguments
43 ;; - renaming:
44 ;; elib-node ==> ewoc--node
45 ;; collection ==> ewoc
46 ;; tin ==> ewoc--node
47 ;; cookie ==> data or element or elem
49 ;; Introduction
50 ;; ============
52 ;; Ewoc is a package that implements a connection between an
53 ;; dll (a doubly linked list) and the contents of a buffer.
54 ;; Possible uses are dired (have all files in a list, and show them),
55 ;; buffer-list, kom-prioritize (in the LysKOM elisp client) and
56 ;; others. pcl-cvs.el uses ewoc.el.
58 ;; Ewoc can be considered as the `view' part of a model-view-controller.
60 ;; A `element' can be any lisp object. When you use the ewoc
61 ;; package you specify a pretty-printer, a function that inserts
62 ;; a printable representation of the element in the buffer. (The
63 ;; pretty-printer should use "insert" and not
64 ;; "insert-before-markers").
66 ;; A `ewoc' consists of a doubly linked list of elements, a
67 ;; header, a footer and a pretty-printer. It is displayed at a
68 ;; certain point in a certain buffer. (The buffer and point are
69 ;; fixed when the ewoc is created). The header and the footer
70 ;; are constant strings. They appear before and after the elements.
72 ;; Ewoc does not affect the mode of the buffer in any way. It
73 ;; merely makes it easy to connect an underlying data representation
74 ;; to the buffer contents.
76 ;; A `ewoc--node' is an object that contains one element. There are
77 ;; functions in this package that given an ewoc--node extracts the data, or
78 ;; gives the next or previous ewoc--node. (All ewoc--nodes are linked together
79 ;; in a doubly linked list. The 'previous' ewoc--node is the one that appears
80 ;; before the other in the buffer.) You should not do anything with
81 ;; an ewoc--node except pass it to the functions in this package.
83 ;; An ewoc is a very dynamic thing. You can easily add or delete elements.
84 ;; You can apply a function to all elements in an ewoc, etc, etc.
86 ;; Remember that an element can be anything. Your imagination is the
87 ;; limit! It is even possible to have another ewoc as an
88 ;; element. In that way some kind of tree hierarchy can be created.
90 ;; Full documentation will, God willing, soon be available in a
91 ;; Texinfo manual.
93 ;; In the mean time `grep '^(.*ewoc-[^-]' emacs-lisp/ewoc.el' can help
94 ;; you find all the exported functions:
95 ;;
96 ;; (defun ewoc-create (pretty-printer &optional header footer)
97 ;; (defalias 'ewoc-data 'ewoc--node-data)
98 ;; (defun ewoc-enter-first (ewoc data)
99 ;; (defun ewoc-enter-last (ewoc data)
100 ;; (defun ewoc-enter-after (ewoc node data)
101 ;; (defun ewoc-enter-before (ewoc node data)
102 ;; (defun ewoc-next (ewoc node)
103 ;; (defun ewoc-prev (ewoc node)
104 ;; (defun ewoc-nth (ewoc n)
105 ;; (defun ewoc-map (map-function ewoc &rest args)
106 ;; (defun ewoc-filter (ewoc predicate &rest args)
107 ;; (defun ewoc-locate (ewoc &optional pos guess)
108 ;; (defun ewoc-invalidate (ewoc &rest nodes)
109 ;; (defun ewoc-goto-prev (ewoc arg)
110 ;; (defun ewoc-goto-next (ewoc arg)
111 ;; (defun ewoc-goto-node (ewoc node)
112 ;; (defun ewoc-refresh (ewoc)
113 ;; (defun ewoc-collect (ewoc predicate &rest args)
114 ;; (defun ewoc-buffer (ewoc)
115 ;; (defun ewoc-get-hf (ewoc)
116 ;; (defun ewoc-set-hf (ewoc header footer)
118 ;; Coding conventions
119 ;; ==================
121 ;; All functions of course start with `ewoc'. Functions and macros
122 ;; starting with the prefix `ewoc--' are meant for internal use,
123 ;; while those starting with `ewoc-' are exported for public use.
124 ;; There are currently no global or buffer-local variables used.
127 ;;; Code:
129 (eval-when-compile (require 'cl)) ;because of CL compiler macros
131 ;; The doubly linked list is implemented as a circular list
132 ;; with a dummy node first and last. The dummy node is used as
133 ;; "the dll" (or rather is the dll handle passed around).
135 (defstruct (ewoc--node
136 (:type vector) ;required for ewoc--node-branch hack
137 (:constructor ewoc--node-create (start-marker data)))
138 left right data start-marker)
140 (defalias 'ewoc--node-branch 'aref)
142 (defun ewoc--dll-create ()
143 "Create an empty doubly linked list."
144 (let ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST)))
145 (setf (ewoc--node-right dummy-node) dummy-node)
146 (setf (ewoc--node-left dummy-node) dummy-node)
147 dummy-node))
149 (defun ewoc--node-enter-before (node elemnode)
150 "Insert ELEMNODE before NODE in a DLL."
151 (assert (and (null (ewoc--node-left elemnode)) (null (ewoc--node-right elemnode))))
152 (setf (ewoc--node-left elemnode) (ewoc--node-left node))
153 (setf (ewoc--node-right elemnode) node)
154 (setf (ewoc--node-right (ewoc--node-left node)) elemnode)
155 (setf (ewoc--node-left node) elemnode))
157 (defun ewoc--node-enter-first (dll node)
158 "Add a free floating NODE first in DLL."
159 (ewoc--node-enter-before (ewoc--node-right dll) node))
161 (defun ewoc--node-enter-last (dll node)
162 "Add a free floating NODE last in DLL."
163 (ewoc--node-enter-before dll node))
165 (defun ewoc--node-next (dll node)
166 "Return the node after NODE, or nil if NODE is the last node."
167 (unless (eq (ewoc--node-right node) dll) (ewoc--node-right node)))
169 (defun ewoc--node-prev (dll node)
170 "Return the node before NODE, or nil if NODE is the first node."
171 (unless (eq (ewoc--node-left node) dll) (ewoc--node-left node)))
173 (defun ewoc--node-delete (node)
174 "Unbind NODE from its doubly linked list and return it."
175 ;; This is a no-op when applied to the dummy node. This will return
176 ;; nil if applied to the dummy node since it always contains nil.
177 (setf (ewoc--node-right (ewoc--node-left node)) (ewoc--node-right node))
178 (setf (ewoc--node-left (ewoc--node-right node)) (ewoc--node-left node))
179 (setf (ewoc--node-left node) nil)
180 (setf (ewoc--node-right node) nil)
181 node)
183 (defun ewoc--node-nth (dll n)
184 "Return the Nth node from the doubly linked list DLL.
185 N counts from zero. If DLL is not that long, nil is returned.
186 If N is negative, return the -(N+1)th last element.
187 Thus, (ewoc--node-nth dll 0) returns the first node,
188 and (ewoc--node-nth dll -1) returns the last node."
189 ;; Branch 0 ("follow left pointer") is used when n is negative.
190 ;; Branch 1 ("follow right pointer") is used otherwise.
191 (let* ((branch (if (< n 0) 0 1))
192 (node (ewoc--node-branch dll branch)))
193 (if (< n 0) (setq n (- -1 n)))
194 (while (and (not (eq dll node)) (> n 0))
195 (setq node (ewoc--node-branch node branch))
196 (setq n (1- n)))
197 (unless (eq dll node) node)))
200 ;;; The ewoc data type
202 (defstruct (ewoc
203 (:constructor nil)
204 (:constructor ewoc--create
205 (buffer pretty-printer header footer dll))
206 (:conc-name ewoc--))
207 buffer pretty-printer header footer dll last-node)
209 (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms)
210 "Execute FORMS with ewoc--buffer selected as current buffer,
211 dll bound to ewoc--dll, and VARLIST bound as in a let*.
212 dll will be bound when VARLIST is initialized, but the current
213 buffer will *not* have been changed.
214 Return value of last form in FORMS."
215 (let ((old-buffer (make-symbol "old-buffer"))
216 (hnd (make-symbol "ewoc")))
217 (` (let* (((, old-buffer) (current-buffer))
218 ((, hnd) (, ewoc))
219 (dll (ewoc--dll (, hnd)))
220 (,@ varlist))
221 (set-buffer (ewoc--buffer (, hnd)))
222 (unwind-protect
223 (progn (,@ forms))
224 (set-buffer (, old-buffer)))))))
226 (defmacro ewoc--set-buffer-bind-dll (ewoc &rest forms)
227 `(ewoc--set-buffer-bind-dll-let* ,ewoc nil ,@forms))
229 (defsubst ewoc--filter-hf-nodes (ewoc node)
230 "Evaluate NODE once and return it.
231 BUT if it is the header or the footer in EWOC return nil instead."
232 (unless (or (eq node (ewoc--header ewoc))
233 (eq node (ewoc--footer ewoc)))
234 node))
237 (defun ewoc--create-node (data pretty-printer pos)
238 "Call PRETTY-PRINTER with point set at POS in current buffer.
239 Remember the start position. Create a wrapper containing that
240 start position and the element DATA."
241 (save-excursion
242 ;; Remember the position as a number so that it doesn't move
243 ;; when we insert the string.
244 (when (markerp pos) (setq pos (marker-position pos)))
245 (goto-char pos)
246 (let ((inhibit-read-only t))
247 ;; Insert the trailing newline using insert-before-markers
248 ;; so that the start position for the next element is updated.
249 (insert-before-markers ?\n)
250 ;; Move back, and call the pretty-printer.
251 (backward-char 1)
252 (funcall pretty-printer data)
253 (ewoc--node-create (copy-marker pos) data))))
256 (defun ewoc--delete-node-internal (ewoc node)
257 "Delete a data string from EWOC.
258 Can not be used on the footer. Returns the wrapper that is deleted.
259 The start-marker in the wrapper is set to nil, so that it doesn't
260 consume any more resources."
261 (let ((dll (ewoc--dll ewoc))
262 (inhibit-read-only t))
263 ;; If we are about to delete the node pointed at by last-node,
264 ;; set last-node to nil.
265 (if (eq (ewoc--last-node ewoc) node)
266 (setf (ewoc--last-node ewoc) nil))
268 (delete-region (ewoc--node-start-marker node)
269 (ewoc--node-start-marker (ewoc--node-next dll node)))
270 (set-marker (ewoc--node-start-marker node) nil)
271 ;; Delete the node, and return the wrapper.
272 (ewoc--node-delete node)))
275 (defun ewoc--refresh-node (pp node)
276 "Redisplay the element represented by NODE using the pretty-printer PP."
277 (let ((inhibit-read-only t))
278 (save-excursion
279 ;; First, remove the string from the buffer:
280 (delete-region (ewoc--node-start-marker node)
281 (1- (marker-position
282 (ewoc--node-start-marker (ewoc--node-right node)))))
283 ;; Calculate and insert the string.
284 (goto-char (ewoc--node-start-marker node))
285 (funcall pp (ewoc--node-data node)))))
287 ;;; ===========================================================================
288 ;;; Public members of the Ewoc package
291 (defun ewoc-create (pretty-printer &optional header footer)
292 "Create an empty ewoc.
294 The ewoc will be inserted in the current buffer at the current position.
296 PRETTY-PRINTER should be a function that takes one argument, an
297 element, and inserts a string representing it in the buffer (at
298 point). The string PRETTY-PRINTER inserts may be empty or span
299 several linse. A trailing newline will always be inserted
300 automatically. The PRETTY-PRINTER should use insert, and not
301 insert-before-markers.
303 Optional third argument HEADER is a string that will always be
304 present at the top of the ewoc. HEADER should end with a
305 newline. Optionaly fourth argument FOOTER is similar, and will
306 be inserted at the bottom of the ewoc."
307 (let ((new-ewoc
308 (ewoc--create (current-buffer)
309 pretty-printer nil nil (ewoc--dll-create)))
310 (pos (point)))
311 (ewoc--set-buffer-bind-dll new-ewoc
312 ;; Set default values
313 (unless header (setq header ""))
314 (unless footer (setq footer ""))
315 (setf (ewoc--node-start-marker dll) (copy-marker pos))
316 (let ((foot (ewoc--create-node footer (lambda (x) (insert footer)) pos))
317 (head (ewoc--create-node header (lambda (x) (insert header)) pos)))
318 (ewoc--node-enter-first dll head)
319 (ewoc--node-enter-last dll foot)
320 (setf (ewoc--header new-ewoc) head)
321 (setf (ewoc--footer new-ewoc) foot)))
322 ;; Return the ewoc
323 new-ewoc))
325 (defalias 'ewoc-data 'ewoc--node-data)
327 (defun ewoc-enter-first (ewoc data)
328 "Enter DATA first in EWOC."
329 (ewoc--set-buffer-bind-dll ewoc
330 (ewoc-enter-after ewoc (ewoc--node-nth dll 0) data)))
332 (defun ewoc-enter-last (ewoc data)
333 "Enter DATA last in EWOC."
334 (ewoc--set-buffer-bind-dll ewoc
335 (ewoc-enter-before ewoc (ewoc--node-nth dll -1) data)))
338 (defun ewoc-enter-after (ewoc node data)
339 "Enter a new element DATA after NODE in EWOC."
340 (ewoc--set-buffer-bind-dll ewoc
341 (ewoc-enter-before ewoc (ewoc--node-next dll node) data)))
343 (defun ewoc-enter-before (ewoc node data)
344 "Enter a new element DATA before NODE in EWOC."
345 (ewoc--set-buffer-bind-dll ewoc
346 (ewoc--node-enter-before
347 node
348 (ewoc--create-node
349 data
350 (ewoc--pretty-printer ewoc)
351 (ewoc--node-start-marker node)))))
353 (defun ewoc-next (ewoc node)
354 "Get the next node.
355 Returns nil if NODE is nil or the last element."
356 (when node
357 (ewoc--filter-hf-nodes
358 ewoc (ewoc--node-next (ewoc--dll ewoc) node))))
360 (defun ewoc-prev (ewoc node)
361 "Get the previous node.
362 Returns nil if NODE is nil or the first element."
363 (when node
364 (ewoc--filter-hf-nodes
365 ewoc
366 (ewoc--node-prev (ewoc--dll ewoc) node))))
369 (defun ewoc-nth (ewoc n)
370 "Return the Nth node.
371 N counts from zero. Nil is returned if there is less than N elements.
372 If N is negative, return the -(N+1)th last element.
373 Thus, (ewoc-nth dll 0) returns the first node,
374 and (ewoc-nth dll -1) returns the last node.
375 Use `ewoc--node-data' to extract the data from the node."
376 ;; Skip the header (or footer, if n is negative).
377 (setq n (if (< n 0) (1- n) (1+ n)))
378 (ewoc--filter-hf-nodes ewoc
379 (ewoc--node-nth (ewoc--dll ewoc) n)))
381 (defun ewoc-map (map-function ewoc &rest args)
382 "Apply MAP-FUNCTION to all elements in EWOC.
383 MAP-FUNCTION is applied to the first element first.
384 If MAP-FUNCTION returns non-nil the element will be refreshed (its
385 pretty-printer will be called once again).
387 Note that the buffer for EWOC will be current buffer when MAP-FUNCTION
388 is called. MAP-FUNCTION must restore the current buffer to BUFFER before
389 it returns, if it changes it.
391 If more than two arguments are given, the remaining
392 arguments will be passed to MAP-FUNCTION."
393 (ewoc--set-buffer-bind-dll-let* ewoc
394 ((footer (ewoc--footer ewoc))
395 (node (ewoc--node-nth dll 1)))
396 (while (not (eq node footer))
397 (if (apply map-function (ewoc--node-data node) args)
398 (ewoc--refresh-node (ewoc--pretty-printer ewoc) node))
399 (setq node (ewoc--node-next dll node)))))
401 (defun ewoc-filter (ewoc predicate &rest args)
402 "Remove all elements in EWOC for which PREDICATE returns nil.
403 Note that the buffer for EWOC will be current-buffer when PREDICATE
404 is called. PREDICATE must restore the current buffer before it returns
405 if it changes it.
406 The PREDICATE is called with the element as its first argument. If any
407 ARGS are given they will be passed to the PREDICATE."
408 (ewoc--set-buffer-bind-dll-let* ewoc
409 ((node (ewoc--node-nth dll 1))
410 (footer (ewoc--footer ewoc))
411 (next nil))
412 (while (not (eq node footer))
413 (setq next (ewoc--node-next dll node))
414 (unless (apply predicate (ewoc--node-data node) args)
415 (ewoc--delete-node-internal ewoc node))
416 (setq node next))))
418 (defun ewoc-locate (ewoc &optional pos guess)
419 "Return the node that POS (a buffer position) is within.
420 POS may be a marker or an integer. It defaults to point.
421 GUESS should be a node that it is likely that POS is near.
423 If POS points before the first element, the first node is returned.
424 If POS points after the last element, the last node is returned.
425 If the EWOC is empty, nil is returned."
426 (unless pos (setq pos (point)))
427 (ewoc--set-buffer-bind-dll-let* ewoc
428 ((footer (ewoc--footer ewoc)))
430 (cond
431 ;; Nothing present?
432 ((eq (ewoc--node-nth dll 1) (ewoc--node-nth dll -1))
433 nil)
435 ;; Before second elem?
436 ((< pos (ewoc--node-start-marker (ewoc--node-nth dll 2)))
437 (ewoc--node-nth dll 1))
439 ;; After one-before-last elem?
440 ((>= pos (ewoc--node-start-marker (ewoc--node-nth dll -2)))
441 (ewoc--node-nth dll -2))
443 ;; We now know that pos is within a elem.
445 ;; Make an educated guess about which of the three known
446 ;; node'es (the first, the last, or GUESS) is nearest.
447 (let* ((best-guess (ewoc--node-nth dll 1))
448 (distance (abs (- pos (ewoc--node-start-marker best-guess)))))
449 (when guess
450 (let ((d (abs (- pos (ewoc--node-start-marker guess)))))
451 (when (< d distance)
452 (setq distance d)
453 (setq best-guess guess))))
455 (let* ((g (ewoc--node-nth dll -1)) ;Check the last elem
456 (d (abs (- pos (ewoc--node-start-marker g)))))
457 (when (< d distance)
458 (setq distance d)
459 (setq best-guess g)))
461 (when (ewoc--last-node ewoc) ;Check "previous".
462 (let* ((g (ewoc--last-node ewoc))
463 (d (abs (- pos (ewoc--node-start-marker g)))))
464 (when (< d distance)
465 (setq distance d)
466 (setq best-guess g))))
468 ;; best-guess is now a "best guess".
469 ;; Find the correct node. First determine in which direction
470 ;; it lies, and then move in that direction until it is found.
472 (cond
473 ;; Is pos after the guess?
474 ((>= pos
475 (ewoc--node-start-marker best-guess))
476 ;; Loop until we are exactly one node too far down...
477 (while (>= pos (ewoc--node-start-marker best-guess))
478 (setq best-guess (ewoc--node-next dll best-guess)))
479 ;; ...and return the previous node.
480 (ewoc--node-prev dll best-guess))
482 ;; Pos is before best-guess
484 (while (< pos (ewoc--node-start-marker best-guess))
485 (setq best-guess (ewoc--node-prev dll best-guess)))
486 best-guess)))))))
488 (defun ewoc-invalidate (ewoc &rest nodes)
489 "Refresh some elements.
490 The pretty-printer that for EWOC will be called for all NODES."
491 (ewoc--set-buffer-bind-dll ewoc
492 (dolist (node nodes)
493 (ewoc--refresh-node (ewoc--pretty-printer ewoc) node))))
495 (defun ewoc-goto-prev (ewoc arg)
496 "Move point to the ARGth previous element.
497 Don't move if we are at the first element, or if EWOC is empty.
498 Returns the node we moved to."
499 (ewoc--set-buffer-bind-dll-let* ewoc
500 ((node (ewoc-locate ewoc (point) (ewoc--last-node ewoc))))
501 (when node
502 ;; If we were past the last element, first jump to it.
503 (when (>= (point) (ewoc--node-start-marker (ewoc--node-right node)))
504 (setq arg (1- arg)))
505 (while (and node (> arg 0))
506 (setq arg (1- arg))
507 (setq node (ewoc--node-prev dll node)))
508 ;; Never step above the first element.
509 (unless (ewoc--filter-hf-nodes ewoc node)
510 (setq node (ewoc--node-nth dll 1)))
511 (ewoc-goto-node ewoc node))))
513 (defun ewoc-goto-next (ewoc arg)
514 "Move point to the ARGth next element.
515 Returns the node (or nil if we just passed the last node)."
516 (ewoc--set-buffer-bind-dll-let* ewoc
517 ((node (ewoc-locate ewoc (point) (ewoc--last-node ewoc))))
518 (while (and node (> arg 0))
519 (setq arg (1- arg))
520 (setq node (ewoc--node-next dll node)))
521 ;; Never step below the first element.
522 ;; (unless (ewoc--filter-hf-nodes ewoc node)
523 ;; (setq node (ewoc--node-nth dll -2)))
524 (ewoc-goto-node ewoc node)))
526 (defun ewoc-goto-node (ewoc node)
527 "Move point to NODE."
528 (ewoc--set-buffer-bind-dll ewoc
529 (goto-char (ewoc--node-start-marker node))
530 (if goal-column (move-to-column goal-column))
531 (setf (ewoc--last-node ewoc) node)))
533 (defun ewoc-refresh (ewoc)
534 "Refresh all data in EWOC.
535 The pretty-printer that was specified when the EWOC was created
536 will be called for all elements in EWOC.
537 Note that `ewoc-invalidate' is more efficient if only a small
538 number of elements needs to be refreshed."
539 (ewoc--set-buffer-bind-dll-let* ewoc
540 ((footer (ewoc--footer ewoc)))
541 (let ((inhibit-read-only t))
542 (delete-region (ewoc--node-start-marker (ewoc--node-nth dll 1))
543 (ewoc--node-start-marker footer))
544 (goto-char (ewoc--node-start-marker footer))
545 (let ((node (ewoc--node-nth dll 1)))
546 (while (not (eq node footer))
547 (set-marker (ewoc--node-start-marker node) (point))
548 (funcall (ewoc--pretty-printer ewoc)
549 (ewoc--node-data node))
550 (insert "\n")
551 (setq node (ewoc--node-next dll node)))))
552 (set-marker (ewoc--node-start-marker footer) (point))))
554 (defun ewoc-collect (ewoc predicate &rest args)
555 "Select elements from EWOC using PREDICATE.
556 Return a list of all selected data elements.
557 PREDICATE is a function that takes a data element as its first argument.
558 The elements on the returned list will appear in the same order as in
559 the buffer. You should not rely on in which order PREDICATE is
560 called.
561 Note that the buffer the EWOC is displayed in is current-buffer
562 when PREDICATE is called. If PREDICATE must restore current-buffer if
563 it changes it.
564 If more than two arguments are given the
565 remaining arguments will be passed to PREDICATE."
566 (ewoc--set-buffer-bind-dll-let* ewoc
567 ((header (ewoc--header ewoc))
568 (node (ewoc--node-nth dll -2))
569 result)
570 (while (not (eq node header))
571 (if (apply predicate (ewoc--node-data node) args)
572 (push (ewoc--node-data node) result))
573 (setq node (ewoc--node-prev dll node)))
574 result))
576 (defun ewoc-buffer (ewoc)
577 "Return the buffer that is associated with EWOC.
578 Returns nil if the buffer has been deleted."
579 (let ((buf (ewoc--buffer ewoc)))
580 (when (buffer-name buf) buf)))
582 (defun ewoc-get-hf (ewoc)
583 "Return a cons cell containing the (HEADER . FOOTER) of EWOC."
584 (cons (ewoc--node-data (ewoc--header ewoc))
585 (ewoc--node-data (ewoc--footer ewoc))))
587 (defun ewoc-set-hf (ewoc header footer)
588 "Set the HEADER and FOOTER of EWOC."
589 (setf (ewoc--node-data (ewoc--header ewoc)) header)
590 (setf (ewoc--node-data (ewoc--footer ewoc)) footer)
591 (ewoc--refresh-node (lambda (x) (insert header)) (ewoc--header ewoc))
592 (ewoc--refresh-node (lambda (x) (insert footer)) (ewoc--footer ewoc)))
595 (provide 'ewoc)
597 ;;; Local Variables:
598 ;;; eval: (put 'ewoc--set-buffer-bind-dll 'lisp-indent-hook 1)
599 ;;; eval: (put 'ewoc--set-buffer-bind-dll-let* 'lisp-indent-hook 2)
600 ;;; End:
602 ;;; ewoc.el ends here