1 |
;;; ewoc.el --- utility to maintain a view of a list of objects in a buffer |
;;; ewoc.el --- utility to maintain a view of a list of objects in a buffer |
2 |
|
|
3 |
;; Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation |
;; Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 04 |
4 |
|
;; Free Software Foundation |
5 |
|
|
6 |
;; Author: Per Cederqvist <ceder@lysator.liu.se> |
;; Author: Per Cederqvist <ceder@lysator.liu.se> |
7 |
;; Inge Wallin <inge@lysator.liu.se> |
;; Inge Wallin <inge@lysator.liu.se> |
245 |
|
|
246 |
(defun ewoc--create-node (data pretty-printer pos) |
(defun ewoc--create-node (data pretty-printer pos) |
247 |
"Call PRETTY-PRINTER with point set at POS in current buffer. |
"Call PRETTY-PRINTER with point set at POS in current buffer. |
248 |
Remember the start position. Create a wrapper containing that |
Remember the start position. Create a wrapper containing that |
249 |
start position and the element DATA." |
start position and the element DATA." |
250 |
(save-excursion |
(save-excursion |
251 |
;; Remember the position as a number so that it doesn't move |
;; Remember the position as a number so that it doesn't move |
264 |
|
|
265 |
(defun ewoc--delete-node-internal (ewoc node) |
(defun ewoc--delete-node-internal (ewoc node) |
266 |
"Delete a data string from EWOC. |
"Delete a data string from EWOC. |
267 |
Can not be used on the footer. Returns the wrapper that is deleted. |
Can not be used on the footer. Returns the wrapper that is deleted. |
268 |
The start-marker in the wrapper is set to nil, so that it doesn't |
The start-marker in the wrapper is set to nil, so that it doesn't |
269 |
consume any more resources." |
consume any more resources." |
270 |
(let ((dll (ewoc--dll ewoc)) |
(let ((dll (ewoc--dll ewoc)) |
304 |
|
|
305 |
PRETTY-PRINTER should be a function that takes one argument, an |
PRETTY-PRINTER should be a function that takes one argument, an |
306 |
element, and inserts a string representing it in the buffer (at |
element, and inserts a string representing it in the buffer (at |
307 |
point). The string PRETTY-PRINTER inserts may be empty or span |
point). The string PRETTY-PRINTER inserts may be empty or span |
308 |
several linse. A trailing newline will always be inserted |
several lines. A trailing newline will always be inserted |
309 |
automatically. The PRETTY-PRINTER should use insert, and not |
automatically. The PRETTY-PRINTER should use `insert', and not |
310 |
insert-before-markers. |
`insert-before-markers'. |
311 |
|
|
312 |
Optional third argument HEADER is a string that will always be |
Optional second argument HEADER is a string that will always be |
313 |
present at the top of the ewoc. HEADER should end with a |
present at the top of the ewoc. HEADER should end with a |
314 |
newline. Optionaly fourth argument FOOTER is similar, and will |
newline. Optional third argument FOOTER is similar, and will |
315 |
be inserted at the bottom of the ewoc." |
be inserted at the bottom of the ewoc." |
316 |
(let ((new-ewoc |
(let ((new-ewoc |
317 |
(ewoc--create (current-buffer) |
(ewoc--create (current-buffer) |
395 |
If MAP-FUNCTION returns non-nil the element will be refreshed (its |
If MAP-FUNCTION returns non-nil the element will be refreshed (its |
396 |
pretty-printer will be called once again). |
pretty-printer will be called once again). |
397 |
|
|
398 |
Note that the buffer for EWOC will be current buffer when MAP-FUNCTION |
Note that the buffer for EWOC will be the current buffer when |
399 |
is called. MAP-FUNCTION must restore the current buffer to BUFFER before |
MAP-FUNCTION is called. MAP-FUNCTION must restore the current |
400 |
it returns, if it changes it. |
buffer before it returns, if it changes it. |
401 |
|
|
402 |
If more than two arguments are given, the remaining |
If more than two arguments are given, the remaining |
403 |
arguments will be passed to MAP-FUNCTION." |
arguments will be passed to MAP-FUNCTION." |
412 |
(defun ewoc-filter (ewoc predicate &rest args) |
(defun ewoc-filter (ewoc predicate &rest args) |
413 |
"Remove all elements in EWOC for which PREDICATE returns nil. |
"Remove all elements in EWOC for which PREDICATE returns nil. |
414 |
Note that the buffer for EWOC will be current-buffer when PREDICATE |
Note that the buffer for EWOC will be current-buffer when PREDICATE |
415 |
is called. PREDICATE must restore the current buffer before it returns |
is called. PREDICATE must restore the current buffer before it returns |
416 |
if it changes it. |
if it changes it. |
417 |
The PREDICATE is called with the element as its first argument. If any |
The PREDICATE is called with the element as its first argument. If any |
418 |
ARGS are given they will be passed to the PREDICATE." |
ARGS are given they will be passed to the PREDICATE." |
419 |
(ewoc--set-buffer-bind-dll-let* ewoc |
(ewoc--set-buffer-bind-dll-let* ewoc |
420 |
((node (ewoc--node-nth dll 1)) |
((node (ewoc--node-nth dll 1)) |
429 |
(defun ewoc-locate (ewoc &optional pos guess) |
(defun ewoc-locate (ewoc &optional pos guess) |
430 |
"Return the node that POS (a buffer position) is within. |
"Return the node that POS (a buffer position) is within. |
431 |
POS may be a marker or an integer. It defaults to point. |
POS may be a marker or an integer. It defaults to point. |
432 |
GUESS should be a node that it is likely that POS is near. |
GUESS should be a node that it is likely to be near POS. |
433 |
|
|
434 |
If POS points before the first element, the first node is returned. |
If POS points before the first element, the first node is returned. |
435 |
If POS points after the last element, the last node is returned. |
If POS points after the last element, the last node is returned. |
498 |
|
|
499 |
(defun ewoc-invalidate (ewoc &rest nodes) |
(defun ewoc-invalidate (ewoc &rest nodes) |
500 |
"Refresh some elements. |
"Refresh some elements. |
501 |
The pretty-printer that for EWOC will be called for all NODES." |
The pretty-printer set for EWOC will be called for all NODES." |
502 |
(ewoc--set-buffer-bind-dll ewoc |
(ewoc--set-buffer-bind-dll ewoc |
503 |
(dolist (node nodes) |
(dolist (node nodes) |
504 |
(ewoc--refresh-node (ewoc--pretty-printer ewoc) node)))) |
(ewoc--refresh-node (ewoc--pretty-printer ewoc) node)))) |
565 |
(defun ewoc-collect (ewoc predicate &rest args) |
(defun ewoc-collect (ewoc predicate &rest args) |
566 |
"Select elements from EWOC using PREDICATE. |
"Select elements from EWOC using PREDICATE. |
567 |
Return a list of all selected data elements. |
Return a list of all selected data elements. |
568 |
PREDICATE is a function that takes a data element as its first argument. |
PREDICATE is a function that takes a data element as its first |
569 |
The elements on the returned list will appear in the same order as in |
argument. The elements on the returned list will appear in the |
570 |
the buffer. You should not rely on in which order PREDICATE is |
same order as in the buffer. You should not rely on the order of |
571 |
called. |
calls to PREDICATE. |
572 |
Note that the buffer the EWOC is displayed in is current-buffer |
Note that the buffer the EWOC is displayed in is the current |
573 |
when PREDICATE is called. If PREDICATE must restore current-buffer if |
buffer when PREDICATE is called. PREDICATE must restore it if it |
574 |
it changes it. |
changes it. |
575 |
If more than two arguments are given the |
If more than two arguments are given the |
576 |
remaining arguments will be passed to PREDICATE." |
remaining arguments will be passed to PREDICATE." |
577 |
(ewoc--set-buffer-bind-dll-let* ewoc |
(ewoc--set-buffer-bind-dll-let* ewoc |