annotate lisp/emacs-lisp/ewoc.el @ 45276:51bf5310b422

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