Mercurial > emacs
annotate lisp/emacs-lisp/ewoc.el @ 99054:731804a3fbe8
* frame.el (make-frame-command): Doc fix. Use display-graphic-p.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Wed, 22 Oct 2008 21:06:55 +0000 |
parents | 595265f1ca2d |
children | a9dc0e7c3f2b |
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 |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
79704 | 4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Author: Per Cederqvist <ceder@lysator.liu.se> |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;; Inge Wallin <inge@lysator.liu.se> |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; Maintainer: monnier@gnu.org |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 ;; Created: 3 Aug 1992 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; Keywords: extensions, lisp |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; This file is part of GNU Emacs. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93933
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93933
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93933
diff
changeset
|
17 ;; (at your option) any later version. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; 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
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; GNU General Public License for more details. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93933
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 ;;; Commentary: |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;; Ewoc Was Once Cookie |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;; But now it's Emacs' Widget for Object Collections |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;; 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
|
33 ;; of Elib). The changes are pervasive though mostly superficial: |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 |
32487
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
35 ;; - uses CL (and its `defstruct') |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;; - separate from Elib. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; - 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
|
38 ;; 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
|
39 ;; - 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
|
40 ;; time of writing) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 ;; - removing unused arguments |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 ;; - renaming: |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 ;; elib-node ==> ewoc--node |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;; collection ==> ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 ;; tin ==> ewoc--node |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 ;; cookie ==> data or element or elem |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 ;; Introduction |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 ;; ============ |
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 ;; Ewoc is a package that implements a connection between an |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 ;; dll (a doubly linked list) and the contents of a buffer. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 ;; 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
|
54 ;; buffer-list, kom-prioritize (in the LysKOM elisp client) and |
94825
595265f1ca2d
Note that vc.el now uses this.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
94655
diff
changeset
|
55 ;; others. pcl-cvs.el and vc.el use ewoc.el. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 ;; 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
|
58 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 ;; 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
|
60 ;; package you specify a pretty-printer, a function that inserts |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 ;; a printable representation of the element in the buffer. (The |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 ;; pretty-printer should use "insert" and not |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 ;; "insert-before-markers"). |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 ;; A `ewoc' consists of a doubly linked list of elements, a |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 ;; 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
|
67 ;; certain point in a certain buffer. (The buffer and point are |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 ;; fixed when the ewoc is created). The header and the footer |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 ;; are constant strings. They appear before and after the elements. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 ;; 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
|
72 ;; merely makes it easy to connect an underlying data representation |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 ;; to the buffer contents. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 ;; 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
|
76 ;; 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
|
77 ;; 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
|
78 ;; 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
|
79 ;; 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
|
80 ;; 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
|
81 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 ;; 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
|
83 ;; 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
|
84 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 ;; Remember that an element can be anything. Your imagination is the |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 ;; limit! It is even possible to have another ewoc as an |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 ;; 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
|
88 ;; |
71012
04ef040bae36
Commentary and whitespace munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
71006
diff
changeset
|
89 ;; The Emacs Lisp Reference Manual documents ewoc.el's "public interface". |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 ;; Coding conventions |
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 ;; |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 ;; All functions of course start with `ewoc'. Functions and macros |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 ;; starting with the prefix `ewoc--' are meant for internal use, |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 ;; while those starting with `ewoc-' are exported for public use. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 ;;; Code: |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 |
71051
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
100 (eval-when-compile (require 'cl)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
102 ;; The doubly linked list is implemented as a circular list with a dummy |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
103 ;; node first and last. The dummy node is used as "the dll". |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (defstruct (ewoc--node |
70994
d3750d5046d7
(ewoc--node-branch): Merge into unique caller.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70992
diff
changeset
|
105 (:type vector) ;ewoc--node-nth needs this |
70997
9a4ed4323ed7
(ewoc--node): Don't define constructor
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70994
diff
changeset
|
106 (:constructor nil) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (:constructor ewoc--node-create (start-marker data))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 left right data start-marker) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
110 (defun ewoc--node-next (dll node) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 "Return the node after NODE, or nil if NODE is the last node." |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
112 (let ((R (ewoc--node-right node))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
113 (unless (eq dll R) R))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
115 (defun ewoc--node-prev (dll node) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 "Return the node before NODE, or nil if NODE is the first node." |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
117 (let ((L (ewoc--node-left node))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
118 (unless (eq dll L) L))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
120 (defun ewoc--node-nth (dll n) |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
121 "Return the Nth node from the doubly linked list `dll'. |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
122 N counts from zero. If N is negative, return the -(N+1)th last element. |
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
123 If N is out of range, return nil. |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
124 Thus, (ewoc--node-nth dll 0) returns the first node, |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
125 and (ewoc--node-nth dll -1) returns the last node." |
70994
d3750d5046d7
(ewoc--node-branch): Merge into unique caller.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70992
diff
changeset
|
126 ;; Presuming a node is ":type vector", starting with `left' and `right': |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 ;; Branch 0 ("follow left pointer") is used when n is negative. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 ;; Branch 1 ("follow right pointer") is used otherwise. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 (let* ((branch (if (< n 0) 0 1)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
130 (node (aref dll branch))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 (if (< n 0) (setq n (- -1 n))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
132 (while (and (not (eq dll node)) (> n 0)) |
70994
d3750d5046d7
(ewoc--node-branch): Merge into unique caller.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70992
diff
changeset
|
133 (setq node (aref node branch)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 (setq n (1- n))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
135 (unless (eq dll node) node))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 |
32487
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
137 (defun ewoc-location (node) |
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
138 "Return the start location of NODE." |
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
139 (ewoc--node-start-marker node)) |
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
140 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 ;;; The ewoc data type |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 (defstruct (ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 (:constructor nil) |
70990
c54570f9431a
(ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70956
diff
changeset
|
146 (:constructor ewoc--create (buffer pretty-printer dll)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 (:conc-name ewoc--)) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
148 buffer pretty-printer header footer dll last-node hf-pp) |
28088
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 (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 "Execute FORMS with ewoc--buffer selected as current buffer, |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
152 `dll' bound to the dll, and VARLIST bound as in a let*. |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
153 `dll' will be bound when VARLIST is initialized, but |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
154 the current buffer will *not* have been changed. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 Return value of last form in FORMS." |
70523
bc300a06815f
(ewoc--set-buffer-bind-dll-let*): Use `with-current-buffer'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70413
diff
changeset
|
156 (let ((hnd (make-symbol "ewoc"))) |
bc300a06815f
(ewoc--set-buffer-bind-dll-let*): Use `with-current-buffer'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70413
diff
changeset
|
157 `(let* ((,hnd ,ewoc) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
158 (dll (ewoc--dll ,hnd)) |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
38436
diff
changeset
|
159 ,@varlist) |
70523
bc300a06815f
(ewoc--set-buffer-bind-dll-let*): Use `with-current-buffer'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70413
diff
changeset
|
160 (with-current-buffer (ewoc--buffer ,hnd) |
bc300a06815f
(ewoc--set-buffer-bind-dll-let*): Use `with-current-buffer'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70413
diff
changeset
|
161 ,@forms)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163 (defmacro ewoc--set-buffer-bind-dll (ewoc &rest forms) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 `(ewoc--set-buffer-bind-dll-let* ,ewoc nil ,@forms)) |
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 (defsubst ewoc--filter-hf-nodes (ewoc node) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 "Evaluate NODE once and return it. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 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
|
169 (unless (or (eq node (ewoc--header ewoc)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 (eq node (ewoc--footer ewoc))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 node)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
173 (defun ewoc--adjust (beg end node dll) |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
174 ;; "Manually reseat" markers for NODE and its successors (including footer |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
175 ;; and dll), in the case where they originally shared start position with |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
176 ;; BEG, to END. BEG and END are buffer positions describing NODE's left |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
177 ;; neighbor. This operation is functionally equivalent to temporarily |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
178 ;; setting these nodes' markers' insertion type to t around the pretty-print |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
179 ;; call that precedes the call to `ewoc--adjust', and then changing them back |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
180 ;; to nil. |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
181 (when (< beg end) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
182 (let (m) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
183 (while (and (= beg (setq m (ewoc--node-start-marker node))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
184 ;; The "dummy" node `dll' actually holds the marker that |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
185 ;; points to the end of the footer, so we check `dll' |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
186 ;; *after* reseating the marker. |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
187 (progn |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
188 (set-marker m end) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
189 (not (eq dll node)))) |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
190 (setq node (ewoc--node-right node)))))) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
191 |
76805
baac37af5483
(ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75346
diff
changeset
|
192 (defun ewoc--insert-new-node (node data pretty-printer dll) |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
193 "Insert before NODE a new node for DATA, displayed by PRETTY-PRINTER. |
76805
baac37af5483
(ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75346
diff
changeset
|
194 Fourth arg DLL -- from `(ewoc--dll EWOC)' -- is for internal purposes. |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
195 Call PRETTY-PRINTER with point at NODE's start, thus pushing back |
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
196 NODE and leaving the new node's start there. Return the new node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 (save-excursion |
71051
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
198 (let ((elemnode (ewoc--node-create |
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
199 (copy-marker (ewoc--node-start-marker node)) data))) |
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
200 (setf (ewoc--node-left elemnode) (ewoc--node-left node) |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
201 (ewoc--node-right elemnode) node |
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
202 (ewoc--node-right (ewoc--node-left node)) elemnode |
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
203 (ewoc--node-left node) elemnode) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
204 (ewoc--refresh-node pretty-printer elemnode dll) |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
205 elemnode))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
207 (defun ewoc--refresh-node (pp node dll) |
28256
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
208 "Redisplay the element represented by NODE using the pretty-printer PP." |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
209 (let ((inhibit-read-only t) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
210 (m (ewoc--node-start-marker node)) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
211 (R (ewoc--node-right node))) |
70582
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
212 ;; First, remove the string from the buffer: |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
213 (delete-region m (ewoc--node-start-marker R)) |
70582
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
214 ;; Calculate and insert the string. |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
215 (goto-char m) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
216 (funcall pp (ewoc--node-data node)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
217 (ewoc--adjust m (point) R dll))) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
218 |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
219 (defun ewoc--wrap (func) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
220 (lexical-let ((ewoc--user-pp func)) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
221 (lambda (data) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
222 (funcall ewoc--user-pp data) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
223 (insert "\n")))) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
224 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 ;;; =========================================================================== |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227 ;;; Public members of the Ewoc package |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228 |
70824
9ce3cc1e5e89
(ewoc-create): Add autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70707
diff
changeset
|
229 ;;;###autoload |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
230 (defun ewoc-create (pretty-printer &optional header footer nosep) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
231 "Create an empty ewoc. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
232 |
28256
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
233 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
|
234 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 PRETTY-PRINTER should be a function that takes one argument, an |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 element, and inserts a string representing it in the buffer (at |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
237 point). The string PRETTY-PRINTER inserts may be empty or span |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
238 several lines. The PRETTY-PRINTER should use `insert', and not |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
239 `insert-before-markers'. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
240 |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
241 Optional second and third arguments HEADER and FOOTER are strings, |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
242 possibly empty, that will always be present at the top and bottom, |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
243 respectively, of the ewoc. |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
244 |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
245 Normally, a newline is automatically inserted after the header, |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
246 the footer and every node's printed representation. Optional |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
247 fourth arg NOSEP non-nil inhibits this." |
70557
84297e870585
(ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70523
diff
changeset
|
248 (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST)) |
84297e870585
(ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70523
diff
changeset
|
249 (dll (progn (setf (ewoc--node-right dummy-node) dummy-node) |
84297e870585
(ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70523
diff
changeset
|
250 (setf (ewoc--node-left dummy-node) dummy-node) |
84297e870585
(ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70523
diff
changeset
|
251 dummy-node)) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
252 (wrap (if nosep 'identity 'ewoc--wrap)) |
70990
c54570f9431a
(ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70956
diff
changeset
|
253 (new-ewoc (ewoc--create (current-buffer) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
254 (funcall wrap pretty-printer) |
70990
c54570f9431a
(ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70956
diff
changeset
|
255 dll)) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
256 (hf-pp (funcall wrap 'insert)) |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
257 (pos (point)) |
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
258 head foot) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
259 (ewoc--set-buffer-bind-dll new-ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
260 ;; Set default values |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
261 (unless header (setq header "")) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
262 (unless footer (setq footer "")) |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
263 (setf (ewoc--node-start-marker dll) (copy-marker pos) |
76805
baac37af5483
(ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75346
diff
changeset
|
264 foot (ewoc--insert-new-node dll footer hf-pp dll) |
baac37af5483
(ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75346
diff
changeset
|
265 head (ewoc--insert-new-node foot header hf-pp dll) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
266 (ewoc--hf-pp new-ewoc) hf-pp |
70613
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
267 (ewoc--footer new-ewoc) foot |
3441bcebaad1
(ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70601
diff
changeset
|
268 (ewoc--header new-ewoc) head)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
269 ;; Return the ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
270 new-ewoc)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271 |
70685
308a4824e11b
(ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70613
diff
changeset
|
272 (defalias 'ewoc-data 'ewoc--node-data |
308a4824e11b
(ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70613
diff
changeset
|
273 "Extract the data encapsulated by NODE and return it. |
308a4824e11b
(ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70613
diff
changeset
|
274 |
308a4824e11b
(ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70613
diff
changeset
|
275 \(fn NODE)") |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276 |
70835
fd87105a0d34
(ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70824
diff
changeset
|
277 (defun ewoc-set-data (node data) |
fd87105a0d34
(ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70824
diff
changeset
|
278 "Set NODE to encapsulate DATA." |
fd87105a0d34
(ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70824
diff
changeset
|
279 (setf (ewoc--node-data node) data)) |
fd87105a0d34
(ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70824
diff
changeset
|
280 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
281 (defun ewoc-enter-first (ewoc data) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
282 "Enter DATA first in EWOC. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
283 Return the new node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284 (ewoc--set-buffer-bind-dll ewoc |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
285 (ewoc-enter-after ewoc (ewoc--node-nth dll 0) data))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
287 (defun ewoc-enter-last (ewoc data) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
288 "Enter DATA last in EWOC. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
289 Return the new node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290 (ewoc--set-buffer-bind-dll ewoc |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
291 (ewoc-enter-before ewoc (ewoc--node-nth dll -1) data))) |
28088
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 (defun ewoc-enter-after (ewoc node data) |
32487
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
294 "Enter a new element DATA after NODE in EWOC. |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
295 Return the new node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 (ewoc--set-buffer-bind-dll ewoc |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
297 (ewoc-enter-before ewoc (ewoc--node-next dll node) data))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 (defun ewoc-enter-before (ewoc node data) |
32487
d5d7a3fbf10c
(ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30879
diff
changeset
|
300 "Enter a new element DATA before NODE in EWOC. |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
301 Return the new node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 (ewoc--set-buffer-bind-dll ewoc |
76805
baac37af5483
(ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75346
diff
changeset
|
303 (ewoc--insert-new-node node data (ewoc--pretty-printer ewoc) dll))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 (defun ewoc-next (ewoc node) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
306 "Return the node in EWOC that follows NODE. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
307 Return nil if NODE is nil or the last element." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 (when node |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309 (ewoc--filter-hf-nodes |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
310 ewoc (ewoc--node-next (ewoc--dll ewoc) node)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
311 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
312 (defun ewoc-prev (ewoc node) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
313 "Return the node in EWOC that precedes NODE. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
314 Return nil if NODE is nil or the first element." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
315 (when node |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
316 (ewoc--filter-hf-nodes |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
317 ewoc (ewoc--node-prev (ewoc--dll ewoc) node)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
318 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
319 (defun ewoc-nth (ewoc n) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
320 "Return the Nth node. |
42206 | 321 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
|
322 If N is negative, return the -(N+1)th last element. |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
323 Thus, (ewoc-nth ewoc 0) returns the first node, |
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
324 and (ewoc-nth ewoc -1) returns the last node. |
70685
308a4824e11b
(ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70613
diff
changeset
|
325 Use `ewoc-data' to extract the data from the node." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 ;; Skip the header (or footer, if n is negative). |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 (setq n (if (< n 0) (1- n) (1+ n))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 (ewoc--filter-hf-nodes ewoc |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
329 (ewoc--node-nth (ewoc--dll ewoc) n))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
331 (defun ewoc-map (map-function ewoc &rest args) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
332 "Apply MAP-FUNCTION to all elements in EWOC. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
333 MAP-FUNCTION is applied to the first element first. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
334 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
|
335 pretty-printer will be called once again). |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
337 Note that the buffer for EWOC will be the current buffer when |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
338 MAP-FUNCTION is called. MAP-FUNCTION must restore the current |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
339 buffer before it returns, if it changes it. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
341 If more than two arguments are given, the remaining |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
342 arguments will be passed to MAP-FUNCTION." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
343 (ewoc--set-buffer-bind-dll-let* ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
344 ((footer (ewoc--footer ewoc)) |
70687
9d6a9b899f95
(ewoc-map, ewoc-invalidate): Compute PP before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70685
diff
changeset
|
345 (pp (ewoc--pretty-printer ewoc)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
346 (node (ewoc--node-nth dll 1))) |
70582
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
347 (save-excursion |
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
348 (while (not (eq node footer)) |
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
349 (if (apply map-function (ewoc--node-data node) args) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
350 (ewoc--refresh-node pp node dll)) |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
351 (setq node (ewoc--node-next dll node)))))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
352 |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
353 (defun ewoc-delete (ewoc &rest nodes) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
354 "Delete NODES from EWOC." |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
355 (ewoc--set-buffer-bind-dll-let* ewoc |
70992
dcab6d42213c
(ewoc-delete): Compute last node once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70990
diff
changeset
|
356 ((L nil) (R nil) (last (ewoc--last-node ewoc))) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
357 (dolist (node nodes) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
358 ;; If we are about to delete the node pointed at by last-node, |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
359 ;; set last-node to nil. |
70992
dcab6d42213c
(ewoc-delete): Compute last node once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70990
diff
changeset
|
360 (when (eq last node) |
dcab6d42213c
(ewoc-delete): Compute last node once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70990
diff
changeset
|
361 (setf last nil (ewoc--last-node ewoc) nil)) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
362 (delete-region (ewoc--node-start-marker node) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
363 (ewoc--node-start-marker (ewoc--node-next dll node))) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
364 (set-marker (ewoc--node-start-marker node) nil) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
365 (setf L (ewoc--node-left node) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
366 R (ewoc--node-right node) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
367 ;; Link neighbors to each other. |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
368 (ewoc--node-right L) R |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
369 (ewoc--node-left R) L |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
370 ;; Forget neighbors. |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
371 (ewoc--node-left node) nil |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
372 (ewoc--node-right node) nil)))) |
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
373 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
374 (defun ewoc-filter (ewoc predicate &rest args) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 "Remove all elements in EWOC for which PREDICATE returns nil. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47549
diff
changeset
|
376 Note that the buffer for EWOC will be current-buffer when PREDICATE |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
377 is called. PREDICATE must restore the current buffer before it returns |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
378 if it changes it. |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
379 The PREDICATE is called with the element as its first argument. If any |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
380 ARGS are given they will be passed to the PREDICATE." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
381 (ewoc--set-buffer-bind-dll-let* ewoc |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
382 ((node (ewoc--node-nth dll 1)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
383 (footer (ewoc--footer ewoc)) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
384 (goodbye nil) |
70557
84297e870585
(ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70523
diff
changeset
|
385 (inhibit-read-only t)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
386 (while (not (eq node footer)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
387 (unless (apply predicate (ewoc--node-data node) args) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
388 (push node goodbye)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
389 (setq node (ewoc--node-next dll node))) |
70851
9119e54a8121
(ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70835
diff
changeset
|
390 (apply 'ewoc-delete ewoc goodbye))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
391 |
30879
3a1ff1caafe2
* emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28256
diff
changeset
|
392 (defun ewoc-locate (ewoc &optional pos guess) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
393 "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
|
394 POS may be a marker or an integer. It defaults to point. |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
395 GUESS should be a node that it is likely to be near POS. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
396 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 (unless pos (setq pos (point))) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
401 (ewoc--set-buffer-bind-dll ewoc |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
402 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
403 (cond |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
404 ;; Nothing present? |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
405 ((eq (ewoc--node-nth dll 1) (ewoc--node-nth dll -1)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
406 nil) |
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 ;; Before second elem? |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
409 ((< pos (ewoc--node-start-marker (ewoc--node-nth dll 2))) |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
410 (ewoc--node-nth dll 1)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
411 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
412 ;; After one-before-last elem? |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
413 ((>= pos (ewoc--node-start-marker (ewoc--node-nth dll -2))) |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
414 (ewoc--node-nth dll -2)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
415 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
416 ;; We now know that pos is within a elem. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
417 (t |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
418 ;; Make an educated guess about which of the three known |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
419 ;; node'es (the first, the last, or GUESS) is nearest. |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
420 (let* ((best-guess (ewoc--node-nth dll 1)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
421 (distance (abs (- pos (ewoc--node-start-marker best-guess))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
422 (when guess |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
423 (let ((d (abs (- pos (ewoc--node-start-marker guess))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
424 (when (< d distance) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
425 (setq distance d) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
426 (setq best-guess guess)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
427 |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
428 (let* ((g (ewoc--node-nth dll -1)) ;Check the last elem |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
429 (d (abs (- pos (ewoc--node-start-marker g))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
430 (when (< d distance) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
431 (setq distance d) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
432 (setq best-guess g))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
433 |
70956
5fd02ab03d96
(ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70851
diff
changeset
|
434 (when (ewoc--last-node ewoc) ;Check "previous". |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
435 (let* ((g (ewoc--last-node ewoc)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
436 (d (abs (- pos (ewoc--node-start-marker g))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
437 (when (< d distance) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
438 (setq distance d) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
439 (setq best-guess g)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
440 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
441 ;; best-guess is now a "best guess". |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
442 ;; Find the correct node. First determine in which direction |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
443 ;; it lies, and then move in that direction until it is found. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47549
diff
changeset
|
444 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
445 (cond |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
446 ;; Is pos after the guess? |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
447 ((>= pos |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
448 (ewoc--node-start-marker best-guess)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
449 ;; Loop until we are exactly one node too far down... |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
450 (while (>= pos (ewoc--node-start-marker best-guess)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
451 (setq best-guess (ewoc--node-next dll best-guess))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
452 ;; ...and return the previous node. |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
453 (ewoc--node-prev dll best-guess)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
454 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
455 ;; Pos is before best-guess |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
456 (t |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
457 (while (< pos (ewoc--node-start-marker best-guess)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
458 (setq best-guess (ewoc--node-prev dll best-guess))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
459 best-guess))))))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
460 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
461 (defun ewoc-invalidate (ewoc &rest nodes) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
462 "Call EWOC's pretty-printer for each element in NODES. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
463 Delete current text first, thus effecting a \"refresh\"." |
70687
9d6a9b899f95
(ewoc-map, ewoc-invalidate): Compute PP before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70685
diff
changeset
|
464 (ewoc--set-buffer-bind-dll-let* ewoc |
9d6a9b899f95
(ewoc-map, ewoc-invalidate): Compute PP before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70685
diff
changeset
|
465 ((pp (ewoc--pretty-printer ewoc))) |
70582
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
466 (save-excursion |
f2d7dbf603c5
(ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70557
diff
changeset
|
467 (dolist (node nodes) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
468 (ewoc--refresh-node pp node dll))))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
469 |
30879
3a1ff1caafe2
* emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28256
diff
changeset
|
470 (defun ewoc-goto-prev (ewoc arg) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
471 "Move point to the ARGth previous element in EWOC. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
472 Don't move if we are at the first element, or if EWOC is empty. |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
473 Return the node we moved to." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
474 (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
|
475 ((node (ewoc-locate ewoc (point)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
476 (when node |
30879
3a1ff1caafe2
* emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28256
diff
changeset
|
477 ;; 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
|
478 (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
|
479 (setq arg (1- arg))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
480 (while (and node (> arg 0)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
481 (setq arg (1- arg)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
482 (setq node (ewoc--node-prev dll node))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
483 ;; Never step above the first element. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
484 (unless (ewoc--filter-hf-nodes ewoc node) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
485 (setq node (ewoc--node-nth dll 1))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
486 (ewoc-goto-node ewoc node)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
487 |
30879
3a1ff1caafe2
* emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28256
diff
changeset
|
488 (defun ewoc-goto-next (ewoc arg) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
489 "Move point to the ARGth next element in EWOC. |
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
490 Return 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
|
491 (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
|
492 ((node (ewoc-locate ewoc (point)))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
493 (while (and node (> arg 0)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
494 (setq arg (1- arg)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
495 (setq node (ewoc--node-next dll node))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
496 ;; 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
|
497 ;; (unless (ewoc--filter-hf-nodes ewoc node) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
498 ;; (setq node (ewoc--node-nth dll -2))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
499 (ewoc-goto-node ewoc node))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
500 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
501 (defun ewoc-goto-node (ewoc node) |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
502 "Move point to NODE in EWOC." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
503 (ewoc--set-buffer-bind-dll ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
504 (goto-char (ewoc--node-start-marker node)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
505 (if goal-column (move-to-column goal-column)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
506 (setf (ewoc--last-node ewoc) node))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
507 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
508 (defun ewoc-refresh (ewoc) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
509 "Refresh all data in EWOC. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
510 The pretty-printer that was specified when the EWOC was created |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
511 will be called for all elements in EWOC. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
512 Note that `ewoc-invalidate' is more efficient if only a small |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
513 number of elements needs to be refreshed." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
514 (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
|
515 ((footer (ewoc--footer ewoc))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
516 (let ((inhibit-read-only t)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
517 (delete-region (ewoc--node-start-marker (ewoc--node-nth dll 1)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
518 (ewoc--node-start-marker footer)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
519 (goto-char (ewoc--node-start-marker footer)) |
70601
77ae8497591f
(ewoc-refresh): Compute PP once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70582
diff
changeset
|
520 (let ((pp (ewoc--pretty-printer ewoc)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
521 (node (ewoc--node-nth dll 1))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
522 (while (not (eq node footer)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
523 (set-marker (ewoc--node-start-marker node) (point)) |
70601
77ae8497591f
(ewoc-refresh): Compute PP once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70582
diff
changeset
|
524 (funcall pp (ewoc--node-data node)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
525 (setq node (ewoc--node-next dll node))))) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
526 (set-marker (ewoc--node-start-marker footer) (point)))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
527 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
528 (defun ewoc-collect (ewoc predicate &rest args) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
529 "Select elements from EWOC using PREDICATE. |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
530 Return a list of all selected data elements. |
56140
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
531 PREDICATE is a function that takes a data element as its first |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
532 argument. The elements on the returned list will appear in the |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
533 same order as in the buffer. You should not rely on the order of |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
534 calls to PREDICATE. |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
535 Note that the buffer the EWOC is displayed in is the current |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
536 buffer when PREDICATE is called. PREDICATE must restore it if it |
f1046f262259
(ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
537 changes it. |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
538 If more than two arguments are given the |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
539 remaining arguments will be passed to PREDICATE." |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
540 (ewoc--set-buffer-bind-dll-let* ewoc |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
541 ((header (ewoc--header ewoc)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
542 (node (ewoc--node-nth dll -2)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
543 result) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
544 (while (not (eq node header)) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 (if (apply predicate (ewoc--node-data node) args) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
546 (push (ewoc--node-data node) result)) |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
547 (setq node (ewoc--node-prev dll node))) |
93933
7f73d8c73d92
(ewoc-collect): Return results in the correct order.
Alexandre Julliard <julliard@winehq.org>
parents:
79704
diff
changeset
|
548 result)) |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
549 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
550 (defun ewoc-buffer (ewoc) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
551 "Return the buffer that is associated with EWOC. |
63325
d4230208a300
Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
56140
diff
changeset
|
552 Return nil if the buffer has been deleted." |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
553 (let ((buf (ewoc--buffer ewoc))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
554 (when (buffer-name buf) buf))) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
555 |
28256
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
556 (defun ewoc-get-hf (ewoc) |
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
557 "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
|
558 (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
|
559 (ewoc--node-data (ewoc--footer ewoc)))) |
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
560 |
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
561 (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
|
562 "Set the HEADER and FOOTER of EWOC." |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
563 (ewoc--set-buffer-bind-dll-let* ewoc |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
564 ((head (ewoc--header ewoc)) |
71006
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
565 (foot (ewoc--footer ewoc)) |
103ed71d4639
(ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70997
diff
changeset
|
566 (hf-pp (ewoc--hf-pp ewoc))) |
70707
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
567 (setf (ewoc--node-data head) header |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
568 (ewoc--node-data foot) footer) |
346a9c09f370
(ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
70687
diff
changeset
|
569 (save-excursion |
71052
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
570 (ewoc--refresh-node hf-pp head dll) |
529644115612
(ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71051
diff
changeset
|
571 (ewoc--refresh-node hf-pp foot dll)))) |
28256
06cfa273543d
* pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28088
diff
changeset
|
572 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
573 |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
574 (provide 'ewoc) |
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
575 |
71051
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
576 ;; Local Variables: |
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
577 ;; eval: (put 'ewoc--set-buffer-bind-dll 'lisp-indent-hook 1) |
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
578 ;; eval: (put 'ewoc--set-buffer-bind-dll-let* 'lisp-indent-hook 2) |
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
579 ;; End: |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
580 |
71051
bf1f0ff1e25e
(ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71012
diff
changeset
|
581 ;; arch-tag: d78915b9-9a07-44bf-aac6-04a1fc1bd6d4 |
28088
b442dfc3cef0
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
582 ;;; ewoc.el ends here |