annotate lisp/emacs-lisp/ewoc.el @ 94559:687d0af3b0f3

(dired-read-dir-and-switches): Set minibuffer-completing-file-name and call substitute-in-file-name.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 02 May 2008 17:20:07 +0000
parents 7f73d8c73d92
children 90a2847062be
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,
79704
78ee6fae0e41 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78217
diff changeset
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Author: Per Cederqvist <ceder@lysator.liu.se>
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Inge Wallin <inge@lysator.liu.se>
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 ;; Maintainer: monnier@gnu.org
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9 ;; Created: 3 Aug 1992
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10 ;; Keywords: extensions, lisp
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; This file is part of GNU Emacs.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13
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
78217
935157c0b596 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76805
diff changeset
16 ;; the Free Software Foundation; either version 3, or (at your option)
28088
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
76805
baac37af5483 (ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 75346
diff changeset
194 (defun ewoc--insert-new-node (node data pretty-printer dll)
70613
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
195 "Insert before NODE a new node for DATA, displayed by PRETTY-PRINTER.
76805
baac37af5483 (ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 75346
diff changeset
196 Fourth arg DLL -- from `(ewoc--dll EWOC)' -- is for internal purposes.
70613
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
197 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
198 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
199 (save-excursion
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
200 (let ((elemnode (ewoc--node-create
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
201 (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
202 (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
203 (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
204 (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
205 (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
206 (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
207 elemnode)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
209 (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
210 "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
211 (let ((inhibit-read-only t)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
212 (m (ewoc--node-start-marker node))
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
213 (R (ewoc--node-right node)))
70582
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
214 ;; First, remove the string from the buffer:
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
215 (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
216 ;; Calculate and insert the string.
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
217 (goto-char m)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
218 (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
219 (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
220
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
221 (defun ewoc--wrap (func)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
222 (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
223 (lambda (data)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
224 (funcall ewoc--user-pp data)
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
225 (insert "\n"))))
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
226
28088
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 ;;; ===========================================================================
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229 ;;; Public members of the Ewoc package
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
230
70824
9ce3cc1e5e89 (ewoc-create): Add autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70707
diff changeset
231 ;;;###autoload
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
232 (defun ewoc-create (pretty-printer &optional header footer nosep)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233 "Create an empty ewoc.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234
28256
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
235 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
236
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 PRETTY-PRINTER should be a function that takes one argument, an
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 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
239 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
240 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
241 `insert-before-markers'.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
243 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
244 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
245 respectively, of the ewoc.
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
246
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
247 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
248 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
249 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
250 (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
251 (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
252 (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
253 dummy-node))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
254 (wrap (if nosep 'identity 'ewoc--wrap))
70990
c54570f9431a (ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70956
diff changeset
255 (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
256 (funcall wrap pretty-printer)
70990
c54570f9431a (ewoc--create): No longer take
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70956
diff changeset
257 dll))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
258 (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
259 (pos (point))
3441bcebaad1 (ewoc--node-enter-before, ewoc--create-node): Delete funcs.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70601
diff changeset
260 head foot)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 (ewoc--set-buffer-bind-dll new-ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 ;; Set default values
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (unless header (setq header ""))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (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
265 (setf (ewoc--node-start-marker dll) (copy-marker pos)
76805
baac37af5483 (ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 75346
diff changeset
266 foot (ewoc--insert-new-node dll footer hf-pp dll)
baac37af5483 (ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 75346
diff changeset
267 head (ewoc--insert-new-node foot header hf-pp dll)
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
268 (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
269 (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
270 (ewoc--header new-ewoc) head))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 ;; Return the ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 new-ewoc))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273
70685
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
274 (defalias 'ewoc-data 'ewoc--node-data
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
275 "Extract the data encapsulated by NODE and return it.
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
276
308a4824e11b (ewoc-data): Add docstring.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70613
diff changeset
277 \(fn NODE)")
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278
70835
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
279 (defun ewoc-set-data (node data)
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
280 "Set NODE to encapsulate DATA."
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
281 (setf (ewoc--node-data node) data))
fd87105a0d34 (ewoc-set-data): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70824
diff changeset
282
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 (defun ewoc-enter-first (ewoc data)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
284 "Enter DATA first in EWOC.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
285 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 (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
287 (ewoc-enter-after ewoc (ewoc--node-nth dll 0) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (defun ewoc-enter-last (ewoc data)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
290 "Enter DATA last in EWOC.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
291 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292 (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
293 (ewoc-enter-before ewoc (ewoc--node-nth dll -1) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (defun ewoc-enter-after (ewoc node data)
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
296 "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
297 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (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
299 (ewoc-enter-before ewoc (ewoc--node-next dll node) data)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 (defun ewoc-enter-before (ewoc node data)
32487
d5d7a3fbf10c (ewoc-location): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30879
diff changeset
302 "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
303 Return the new node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 (ewoc--set-buffer-bind-dll ewoc
76805
baac37af5483 (ewoc--insert-new-node): Take additional arg DLL.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 75346
diff changeset
305 (ewoc--insert-new-node node data (ewoc--pretty-printer ewoc) dll)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 (defun ewoc-next (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
308 "Return the node in EWOC that follows NODE.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
309 Return nil if NODE is nil or the last element."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (when node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 (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
312 ewoc (ewoc--node-next (ewoc--dll ewoc) node))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314 (defun ewoc-prev (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
315 "Return the node in EWOC that precedes NODE.
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
316 Return nil if NODE is nil or the first element."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (when node
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (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
319 ewoc (ewoc--node-prev (ewoc--dll ewoc) node))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 (defun ewoc-nth (ewoc n)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322 "Return the Nth node.
42206
0f4506820432 Doc fix.
Pavel Janík <Pavel@Janik.cz>
parents: 41608
diff changeset
323 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
324 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
325 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
326 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
327 Use `ewoc-data' to extract the data from the node."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 ;; Skip the header (or footer, if n is negative).
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (setq n (if (< n 0) (1- n) (1+ n)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330 (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
331 (ewoc--node-nth (ewoc--dll ewoc) n)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (defun ewoc-map (map-function ewoc &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 "Apply MAP-FUNCTION to all elements in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 MAP-FUNCTION is applied to the first element first.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 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
337 pretty-printer will be called once again).
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338
56140
f1046f262259 (ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
339 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
340 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
341 buffer before it returns, if it changes it.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 If more than two arguments are given, the remaining
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 arguments will be passed to MAP-FUNCTION."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (ewoc--set-buffer-bind-dll-let* ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 ((footer (ewoc--footer ewoc))
70687
9d6a9b899f95 (ewoc-map, ewoc-invalidate): Compute PP before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70685
diff changeset
347 (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
348 (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
349 (save-excursion
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
350 (while (not (eq node footer))
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
351 (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
352 (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
353 (setq node (ewoc--node-next dll node))))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
355 (defun ewoc-delete (ewoc &rest nodes)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
356 "Delete NODES from EWOC."
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
357 (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
358 ((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
359 (dolist (node nodes)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
360 ;; 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
361 ;; 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
362 (when (eq last node)
dcab6d42213c (ewoc-delete): Compute last node once before looping.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70990
diff changeset
363 (setf last nil (ewoc--last-node ewoc) nil))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
364 (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
365 (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
366 (set-marker (ewoc--node-start-marker node) nil)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
367 (setf L (ewoc--node-left node)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
368 R (ewoc--node-right node)
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
369 ;; Link neighbors to each other.
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
370 (ewoc--node-right L) R
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
371 (ewoc--node-left R) L
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
372 ;; Forget neighbors.
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
373 (ewoc--node-left node) nil
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
374 (ewoc--node-right node) nil))))
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
375
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 (defun ewoc-filter (ewoc predicate &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
377 "Remove all elements in EWOC for which PREDICATE returns nil.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47549
diff changeset
378 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
379 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
380 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
381 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
382 ARGS are given they will be passed to the PREDICATE."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 (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
384 ((node (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 (footer (ewoc--footer ewoc))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
386 (goodbye nil)
70557
84297e870585 (ewoc--dll-create, ewoc--node-delete)
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70523
diff changeset
387 (inhibit-read-only t))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 (while (not (eq node footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (unless (apply predicate (ewoc--node-data node) args)
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
390 (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
391 (setq node (ewoc--node-next dll node)))
70851
9119e54a8121 (ewoc-delete): New function.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70835
diff changeset
392 (apply 'ewoc-delete ewoc goodbye)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
394 (defun ewoc-locate (ewoc &optional pos guess)
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 "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
396 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
397 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
398
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 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
400 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
401 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
402 (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
403 (ewoc--set-buffer-bind-dll ewoc
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 (cond
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 ;; 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
407 ((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
408 nil)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 ;; 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
411 ((< 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
412 (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414 ;; 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
415 ((>= 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
416 (ewoc--node-nth dll -2))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
417
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 ;; We now know that pos is within a elem.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 (t
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420 ;; Make an educated guess about which of the three known
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
421 ;; 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
422 (let* ((best-guess (ewoc--node-nth dll 1))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 (distance (abs (- pos (ewoc--node-start-marker best-guess)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 (when guess
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 (let ((d (abs (- pos (ewoc--node-start-marker guess)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
426 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428 (setq best-guess guess))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429
71052
529644115612 (ewoc--current-dll): Remove. Basically undo the change of 2006-05-26:
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71051
diff changeset
430 (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
431 (d (abs (- pos (ewoc--node-start-marker g)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434 (setq best-guess g)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
435
70956
5fd02ab03d96 (ewoc--current-dll): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70851
diff changeset
436 (when (ewoc--last-node ewoc) ;Check "previous".
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 (let* ((g (ewoc--last-node ewoc))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (d (abs (- pos (ewoc--node-start-marker g)))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439 (when (< d distance)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (setq distance d)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (setq best-guess g))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 ;; best-guess is now a "best guess".
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 ;; Find the correct node. First determine in which direction
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 ;; 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
446
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 (cond
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 ;; Is pos after the guess?
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 ((>= pos
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 (ewoc--node-start-marker best-guess))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 ;; Loop until we are exactly one node too far down...
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452 (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
453 (setq best-guess (ewoc--node-next dll best-guess)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
454 ;; ...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
455 (ewoc--node-prev dll best-guess))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 ;; Pos is before best-guess
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458 (t
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
459 (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
460 (setq best-guess (ewoc--node-prev dll best-guess)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461 best-guess)))))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
463 (defun ewoc-invalidate (ewoc &rest nodes)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
464 "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
465 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
466 (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
467 ((pp (ewoc--pretty-printer ewoc)))
70582
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
468 (save-excursion
f2d7dbf603c5 (ewoc--refresh-node): No longer save-excursion.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70557
diff changeset
469 (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
470 (ewoc--refresh-node pp node dll)))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
472 (defun ewoc-goto-prev (ewoc arg)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
473 "Move point to the ARGth previous element in EWOC.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 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
475 Return the node we moved to."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
476 (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
477 ((node (ewoc-locate ewoc (point))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478 (when node
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
479 ;; 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
480 (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
481 (setq arg (1- arg)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 (while (and node (> arg 0))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 (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
484 (setq node (ewoc--node-prev dll node)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 ;; Never step above the first element.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
486 (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
487 (setq node (ewoc--node-nth dll 1)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 (ewoc-goto-node ewoc node))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489
30879
3a1ff1caafe2 * emacs-lisp/ewoc.el (ewoc-locate): Default POS to (point).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28256
diff changeset
490 (defun ewoc-goto-next (ewoc arg)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
491 "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
492 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
493 (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
494 ((node (ewoc-locate ewoc (point))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 (while (and node (> arg 0))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (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
497 (setq node (ewoc--node-next dll node)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 ;; 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
499 ;; (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
500 ;; (setq node (ewoc--node-nth dll -2)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 (ewoc-goto-node ewoc node)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 (defun ewoc-goto-node (ewoc node)
63325
d4230208a300 Doc fixes for public funcs:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 56140
diff changeset
504 "Move point to NODE in EWOC."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (ewoc--set-buffer-bind-dll ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 (goto-char (ewoc--node-start-marker node))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 (if goal-column (move-to-column goal-column))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 (setf (ewoc--last-node ewoc) node)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 (defun ewoc-refresh (ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 "Refresh all data in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 The pretty-printer that was specified when the EWOC was created
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 will be called for all elements in EWOC.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 Note that `ewoc-invalidate' is more efficient if only a small
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 number of elements needs to be refreshed."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
516 (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
517 ((footer (ewoc--footer ewoc)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 (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
519 (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
520 (ewoc--node-start-marker footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 (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
522 (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
523 (node (ewoc--node-nth dll 1)))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 (while (not (eq node footer))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 (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
526 (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
527 (setq node (ewoc--node-next dll node)))))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 (set-marker (ewoc--node-start-marker footer) (point))))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 (defun ewoc-collect (ewoc predicate &rest args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 "Select elements from EWOC using PREDICATE.
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
532 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
533 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
534 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
535 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
536 calls to PREDICATE.
f1046f262259 (ewoc-create, ewoc-map, ewoc-locate, ewoc-invalidate, ewoc-collect):
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
537 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
538 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
539 changes it.
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 If more than two arguments are given the
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 remaining arguments will be passed to PREDICATE."
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 (ewoc--set-buffer-bind-dll-let* ewoc
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
543 ((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
544 (node (ewoc--node-nth dll -2))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 result)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 (while (not (eq node header))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 (if (apply predicate (ewoc--node-data node) args)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 (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
549 (setq node (ewoc--node-prev dll node)))
93933
7f73d8c73d92 (ewoc-collect): Return results in the correct order.
Alexandre Julliard <julliard@winehq.org>
parents: 79704
diff changeset
550 result))
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 (defun ewoc-buffer (ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 "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
554 Return nil if the buffer has been deleted."
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 (let ((buf (ewoc--buffer ewoc)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 (when (buffer-name buf) buf)))
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557
28256
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
558 (defun ewoc-get-hf (ewoc)
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
559 "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
560 (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
561 (ewoc--node-data (ewoc--footer ewoc))))
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
562
06cfa273543d * pcvs.el: Add a minimal leading commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28088
diff changeset
563 (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
564 "Set the HEADER and FOOTER of EWOC."
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
565 (ewoc--set-buffer-bind-dll-let* ewoc
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
566 ((head (ewoc--header ewoc))
71006
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
567 (foot (ewoc--footer ewoc))
103ed71d4639 (ewoc): Add member `hf-pp' to this structure.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70997
diff changeset
568 (hf-pp (ewoc--hf-pp ewoc)))
70707
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
569 (setf (ewoc--node-data head) header
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
570 (ewoc--node-data foot) footer)
346a9c09f370 (ewoc--adjust): New func.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 70687
diff changeset
571 (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
572 (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
573 (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
574
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 (provide 'ewoc)
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
578 ;; Local Variables:
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 'lisp-indent-hook 1)
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
580 ;; 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
581 ;; End:
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
582
71051
bf1f0ff1e25e (ewoc--insert-new-node): Use ewoc--refresh-node.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71012
diff changeset
583 ;; arch-tag: d78915b9-9a07-44bf-aac6-04a1fc1bd6d4
28088
b442dfc3cef0 *** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
584 ;;; ewoc.el ends here