annotate lisp/emacs-lisp/ewoc.el @ 75885:19bf7ffe644e

(Fcolor_distance): Don't continue checking a color for errors after it has been correctly parsed as an RGB list.
author Juanma Barranquero <lekktu@gmail.com>
date Wed, 14 Feb 2007 15:47:51 +0000
parents 7a3f13e2dd57
children baac37af5483 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 34304
diff changeset
1 ;;; ewoc.el --- utility to maintain a view of a list of objects in a buffer
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
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,
75346
7a3f13e2dd57 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74466
diff changeset
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; any later version.
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
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63325
diff changeset
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63325
diff changeset
27 ;; Boston, MA 02110-1301, USA.
28088
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 ;;; Commentary:
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 ;; Ewoc Was Once Cookie
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;; But now it's Emacs' Widget for Object Collections
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; 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
35 ;; of Elib). The changes are pervasive though mostly superficial:
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
37 ;; - uses CL (and its `defstruct')
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; - separate from Elib.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 ;; - 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
40 ;; 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
41 ;; - 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
42 ;; time of writing)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 ;; - removing unused arguments
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 ;; - renaming:
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45 ;; elib-node ==> ewoc--node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 ;; collection ==> ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47 ;; tin ==> ewoc--node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 ;; cookie ==> data or element or elem
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 ;; Introduction
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 ;; ============
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 ;; Ewoc is a package that implements a connection between an
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 ;; dll (a doubly linked list) and the contents of a buffer.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 ;; 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
56 ;; buffer-list, kom-prioritize (in the LysKOM elisp client) and
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 ;; others. pcl-cvs.el uses ewoc.el.
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 ;; 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
60 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 ;; 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
62 ;; package you specify a pretty-printer, a function that inserts
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 ;; a printable representation of the element in the buffer. (The
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 ;; pretty-printer should use "insert" and not
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 ;; "insert-before-markers").
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 ;; A `ewoc' consists of a doubly linked list of elements, a
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 ;; 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
69 ;; certain point in a certain buffer. (The buffer and point are
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 ;; fixed when the ewoc is created). The header and the footer
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 ;; are constant strings. They appear before and after the elements.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 ;; 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
74 ;; merely makes it easy to connect an underlying data representation
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 ;; to the buffer contents.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 ;; 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
78 ;; 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
79 ;; 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
80 ;; 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
81 ;; 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
82 ;; 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
83 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 ;; 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
85 ;; 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
86 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87 ;; Remember that an element can be anything. Your imagination is the
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 ;; limit! It is even possible to have another ewoc as an
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 ;; 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
90 ;;
71012
04ef040bae36 Commentary and whitespace munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 71006
diff changeset
91 ;; 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
92
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 ;; Coding conventions
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 ;; ==================
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 ;;
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 ;; All functions of course start with `ewoc'. Functions and macros
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 ;; starting with the prefix `ewoc--' are meant for internal use,
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 ;; while those starting with `ewoc-' are exported for public use.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 ;;; Code:
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
102 (eval-when-compile (require 'cl))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
104 ;; 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
105 ;; 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
106 (defstruct (ewoc--node
70994
d3750d5046d7 (ewoc--node-branch): Merge into unique caller.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70992
diff changeset
107 (: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
108 (:constructor nil)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 (:constructor ewoc--node-create (start-marker data)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 left right data start-marker)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
112 (defun ewoc--node-next (dll node)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 "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
114 (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
115 (unless (eq dll R) R)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
117 (defun ewoc--node-prev (dll node)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 "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
119 (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
120 (unless (eq dll L) L)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
122 (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
123 "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
124 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
125 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
126 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
127 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
128 ;; 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
129 ;; Branch 0 ("follow left pointer") is used when n is negative.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
130 ;; Branch 1 ("follow right pointer") is used otherwise.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 (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
132 (node (aref dll branch)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133 (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
134 (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
135 (setq node (aref node branch))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
136 (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
137 (unless (eq dll node) node)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
139 (defun ewoc-location (node)
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
140 "Return the start location of NODE."
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
141 (ewoc--node-start-marker node))
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
142
28088
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 ;;; The ewoc data type
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 (defstruct (ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 (:constructor nil)
70990
c54570f9431a (ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70956
diff changeset
148 (:constructor ewoc--create (buffer pretty-printer dll))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149 (:conc-name ewoc--))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
150 buffer pretty-printer header footer dll last-node hf-pp)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153 "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
154 `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
155 `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
156 the current buffer will *not* have been changed.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 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
158 (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
159 `(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
160 (dll (ewoc--dll ,hnd))
41608
45db352a0971 Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents: 38436
diff changeset
161 ,@varlist)
70523
bc300a06815f (ewoc--set-buffer-bind-dll-let*): Use `with-current-buffer'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70413
diff changeset
162 (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
163 ,@forms))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 (defmacro ewoc--set-buffer-bind-dll (ewoc &rest forms)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 `(ewoc--set-buffer-bind-dll-let* ,ewoc nil ,@forms))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 (defsubst ewoc--filter-hf-nodes (ewoc node)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 "Evaluate NODE once and return it.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 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
171 (unless (or (eq node (ewoc--header ewoc))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 (eq node (ewoc--footer ewoc)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 node))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
175 (defun ewoc--adjust (beg end node dll)
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
176 ;; "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
177 ;; 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
178 ;; 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
179 ;; neighbor. This operation is functionally equivalent to temporarily
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
180 ;; 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
181 ;; 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
182 ;; to nil.
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
183 (when (< beg end)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
184 (let (m)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
185 (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
186 ;; 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
187 ;; 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
188 ;; *after* reseating the marker.
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
189 (progn
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
190 (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
191 (not (eq dll node))))
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
192 (setq node (ewoc--node-right node))))))
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
193
70613
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
194 (defun ewoc--insert-new-node (node data pretty-printer)
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
195 "Insert before NODE a new node for DATA, displayed by PRETTY-PRINTER.
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
196 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
197 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
198 (save-excursion
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
199 (let ((elemnode (ewoc--node-create
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
200 (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
201 (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
202 (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
203 (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
204 (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
205 (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
206 elemnode)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
208 (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
209 "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
210 (let ((inhibit-read-only t)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
211 (m (ewoc--node-start-marker node))
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
212 (R (ewoc--node-right node)))
70582
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
213 ;; First, remove the string from the buffer:
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
214 (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
215 ;; Calculate and insert the string.
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
216 (goto-char m)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
217 (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
218 (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
219
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
220 (defun ewoc--wrap (func)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
221 (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
222 (lambda (data)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
223 (funcall ewoc--user-pp data)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
224 (insert "\n"))))
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
225
28088
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 ;;; ===========================================================================
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
228 ;;; Public members of the Ewoc package
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229
70824
9ce3cc1e5e89 (ewoc-create): Add autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70707
diff changeset
230 ;;;###autoload
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
231 (defun ewoc-create (pretty-printer &optional header footer nosep)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232 "Create an empty ewoc.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233
28256
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
234 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
235
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 PRETTY-PRINTER should be a function that takes one argument, an
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 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
238 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
239 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
240 `insert-before-markers'.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
242 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
243 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
244 respectively, of the ewoc.
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
245
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
246 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
247 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
248 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
249 (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
250 (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
251 (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
252 dummy-node))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
253 (wrap (if nosep 'identity 'ewoc--wrap))
70990
c54570f9431a (ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70956
diff changeset
254 (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
255 (funcall wrap pretty-printer)
70990
c54570f9431a (ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70956
diff changeset
256 dll))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
257 (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
258 (pos (point))
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
259 head foot)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (ewoc--set-buffer-bind-dll new-ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 ;; Set default values
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 (unless header (setq header ""))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (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
264 (setf (ewoc--node-start-marker dll) (copy-marker pos)
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
265 foot (ewoc--insert-new-node dll footer hf-pp)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
266 head (ewoc--insert-new-node foot header hf-pp)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
267 (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
268 (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
269 (ewoc--header new-ewoc) head))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 ;; Return the ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 new-ewoc))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272
70685
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
273 (defalias 'ewoc-data 'ewoc--node-data
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
274 "Extract the data encapsulated by NODE and return it.
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
275
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
276 \(fn NODE)")
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277
70835
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
278 (defun ewoc-set-data (node data)
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
279 "Set NODE to encapsulate DATA."
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
280 (setf (ewoc--node-data node) data))
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
281
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 (defun ewoc-enter-first (ewoc data)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
283 "Enter DATA first in EWOC.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
284 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 (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
286 (ewoc-enter-after ewoc (ewoc--node-nth dll 0) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288 (defun ewoc-enter-last (ewoc data)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
289 "Enter DATA last in EWOC.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
290 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 (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
292 (ewoc-enter-before ewoc (ewoc--node-nth dll -1) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 (defun ewoc-enter-after (ewoc node data)
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
295 "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
296 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 (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
298 (ewoc-enter-before ewoc (ewoc--node-next dll node) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (defun ewoc-enter-before (ewoc node data)
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
301 "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
302 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (ewoc--set-buffer-bind-dll ewoc
70613
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
304 (ewoc--insert-new-node node data (ewoc--pretty-printer ewoc))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 (defun ewoc-next (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
307 "Return the node in EWOC that follows NODE.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
308 Return nil if NODE is nil or the last element."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 (when node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (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
311 ewoc (ewoc--node-next (ewoc--dll ewoc) node))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 (defun ewoc-prev (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
314 "Return the node in EWOC that precedes NODE.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
315 Return nil if NODE is nil or the first element."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 (when node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (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
318 ewoc (ewoc--node-prev (ewoc--dll ewoc) node))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320 (defun ewoc-nth (ewoc n)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 "Return the Nth node.
42206
0f4506820432 Doc fix.
Pavel Janík <Pavel@Janik.cz>
parents: 41608
diff changeset
322 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
323 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
324 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
325 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
326 Use `ewoc-data' to extract the data from the node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 ;; Skip the header (or footer, if n is negative).
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (setq n (if (< n 0) (1- n) (1+ n)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (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
330 (ewoc--node-nth (ewoc--dll ewoc) n)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (defun ewoc-map (map-function ewoc &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 "Apply MAP-FUNCTION to all elements in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 MAP-FUNCTION is applied to the first element first.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 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
336 pretty-printer will be called once again).
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337
56140
f1046f262259 (ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
338 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
339 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
340 buffer before it returns, if it changes it.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 If more than two arguments are given, the remaining
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 arguments will be passed to MAP-FUNCTION."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 (ewoc--set-buffer-bind-dll-let* ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 ((footer (ewoc--footer ewoc))
70687
9d6a9b899f95 (ewoc-map, ewoc-invalidate): Compute PP before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70685
diff changeset
346 (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
347 (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
348 (save-excursion
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
349 (while (not (eq node footer))
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
350 (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
351 (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
352 (setq node (ewoc--node-next dll node))))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
354 (defun ewoc-delete (ewoc &rest nodes)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
355 "Delete NODES from EWOC."
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
356 (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
357 ((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
358 (dolist (node nodes)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
359 ;; 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
360 ;; 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
361 (when (eq last node)
dcab6d42213c (ewoc-delete): Compute last node once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70990
diff changeset
362 (setf last nil (ewoc--last-node ewoc) nil))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
363 (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
364 (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
365 (set-marker (ewoc--node-start-marker node) nil)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
366 (setf L (ewoc--node-left node)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
367 R (ewoc--node-right node)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
368 ;; Link neighbors to each other.
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
369 (ewoc--node-right L) R
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
370 (ewoc--node-left R) L
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
371 ;; Forget neighbors.
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
372 (ewoc--node-left node) nil
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
373 (ewoc--node-right node) nil))))
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
374
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375 (defun ewoc-filter (ewoc predicate &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 "Remove all elements in EWOC for which PREDICATE returns nil.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47549
diff changeset
377 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
378 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
379 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
380 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
381 ARGS are given they will be passed to the PREDICATE."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 (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
383 ((node (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 (footer (ewoc--footer ewoc))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
385 (goodbye nil)
70557
84297e870585 (ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70523
diff changeset
386 (inhibit-read-only t))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (while (not (eq node footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 (unless (apply predicate (ewoc--node-data node) args)
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
389 (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
390 (setq node (ewoc--node-next dll node)))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
391 (apply 'ewoc-delete ewoc goodbye)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
393 (defun ewoc-locate (ewoc &optional pos guess)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 "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
395 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
396 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
397
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398 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
399 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
400 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
401 (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
402 (ewoc--set-buffer-bind-dll ewoc
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 (cond
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 ;; 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
406 ((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
407 nil)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 ;; 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
410 ((< 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
411 (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
412
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413 ;; 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
414 ((>= 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
415 (ewoc--node-nth dll -2))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
416
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
417 ;; We now know that pos is within a elem.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 (t
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 ;; Make an educated guess about which of the three known
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420 ;; 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
421 (let* ((best-guess (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
422 (distance (abs (- pos (ewoc--node-start-marker best-guess)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 (when guess
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 (let ((d (abs (- pos (ewoc--node-start-marker guess)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
426 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (setq best-guess guess))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
429 (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
430 (d (abs (- pos (ewoc--node-start-marker g)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
431 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433 (setq best-guess g)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434
70956
5fd02ab03d96 (ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70851
diff changeset
435 (when (ewoc--last-node ewoc) ;Check "previous".
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436 (let* ((g (ewoc--last-node ewoc))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 (d (abs (- pos (ewoc--node-start-marker g)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (setq best-guess g))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 ;; best-guess is now a "best guess".
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 ;; Find the correct node. First determine in which direction
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 ;; 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
445
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446 (cond
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 ;; Is pos after the guess?
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 ((>= pos
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 (ewoc--node-start-marker best-guess))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 ;; Loop until we are exactly one node too far down...
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 (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
452 (setq best-guess (ewoc--node-next dll best-guess)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453 ;; ...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
454 (ewoc--node-prev dll best-guess))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456 ;; Pos is before best-guess
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 (t
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458 (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
459 (setq best-guess (ewoc--node-prev dll best-guess)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
460 best-guess)))))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462 (defun ewoc-invalidate (ewoc &rest nodes)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
463 "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
464 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
465 (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
466 ((pp (ewoc--pretty-printer ewoc)))
70582
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
467 (save-excursion
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
468 (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
469 (ewoc--refresh-node pp node dll)))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
470
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
471 (defun ewoc-goto-prev (ewoc arg)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
472 "Move point to the ARGth previous element in EWOC.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 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
474 Return the node we moved to."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 (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
476 ((node (ewoc-locate ewoc (point))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 (when node
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
478 ;; 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
479 (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
480 (setq arg (1- arg)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 (while (and node (> arg 0))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 (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
483 (setq node (ewoc--node-prev dll node)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 ;; Never step above the first element.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 (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
486 (setq node (ewoc--node-nth dll 1)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 (ewoc-goto-node ewoc node))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
489 (defun ewoc-goto-next (ewoc arg)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
490 "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
491 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
492 (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
493 ((node (ewoc-locate ewoc (point))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 (while (and node (> arg 0))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 (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
496 (setq node (ewoc--node-next dll node)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 ;; 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
498 ;; (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
499 ;; (setq node (ewoc--node-nth dll -2)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 (ewoc-goto-node ewoc node)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 (defun ewoc-goto-node (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
503 "Move point to NODE in EWOC."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (ewoc--set-buffer-bind-dll ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (goto-char (ewoc--node-start-marker node))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 (if goal-column (move-to-column goal-column))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 (setf (ewoc--last-node ewoc) node)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 (defun ewoc-refresh (ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 "Refresh all data in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 The pretty-printer that was specified when the EWOC was created
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 will be called for all elements in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 Note that `ewoc-invalidate' is more efficient if only a small
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 number of elements needs to be refreshed."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 (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
516 ((footer (ewoc--footer ewoc)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 (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
518 (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
519 (ewoc--node-start-marker footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (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
521 (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
522 (node (ewoc--node-nth dll 1)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
523 (while (not (eq node footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 (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
525 (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
526 (setq node (ewoc--node-next dll node)))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
527 (set-marker (ewoc--node-start-marker footer) (point))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529 (defun ewoc-collect (ewoc predicate &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 "Select elements from EWOC using PREDICATE.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 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
532 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
533 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
534 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
535 calls to PREDICATE.
f1046f262259 (ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
536 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
537 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
538 changes it.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
539 If more than two arguments are given the
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 remaining arguments will be passed to PREDICATE."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 (ewoc--set-buffer-bind-dll-let* ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 ((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
543 (node (ewoc--node-nth dll -2))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
544 result)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 (while (not (eq node header))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 (if (apply predicate (ewoc--node-data node) args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 (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
548 (setq node (ewoc--node-prev dll node)))
33233
c12aa82daf99 (ewoc-goto-prev, ewoc-goto-next):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32487
diff changeset
549 (nreverse result)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 (defun ewoc-buffer (ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 "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
553 Return nil if the buffer has been deleted."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 (let ((buf (ewoc--buffer ewoc)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 (when (buffer-name buf) buf)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556
28256
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
557 (defun ewoc-get-hf (ewoc)
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
558 "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
559 (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
560 (ewoc--node-data (ewoc--footer ewoc))))
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
561
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
562 (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
563 "Set the HEADER and FOOTER of EWOC."
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
564 (ewoc--set-buffer-bind-dll-let* ewoc
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
565 ((head (ewoc--header ewoc))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
566 (foot (ewoc--footer ewoc))
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
567 (hf-pp (ewoc--hf-pp ewoc)))
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
568 (setf (ewoc--node-data head) header
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
569 (ewoc--node-data foot) footer)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
570 (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
571 (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
572 (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
573
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
574
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 (provide 'ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
577 ;; Local Variables:
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 'lisp-indent-hook 1)
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
579 ;; 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
580 ;; End:
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
582 ;; arch-tag: d78915b9-9a07-44bf-aac6-04a1fc1bd6d4
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
583 ;;; ewoc.el ends here