annotate lisp/pcl-cvs/cookie.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; $Id: cookie.el,v 1.1.1.1 1996/12/18 03:32:25 steve Exp $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; cookie.el -- Utility to display cookies in buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1991-1995 Free Software Foundation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Per Cederqvist <ceder@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Inge Wallin <inge@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Maintainer: elib-maintainers@lysator.liu.se
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Created: 3 Aug 1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Keywords: extensions, lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; the Free Software Foundation; either version 2 of the License, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; along with GNU Elib; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Boston, MA 02111-1307, USA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; ============
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Cookie is a package that implements a connection between an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; dll (a doubly linked list) and the contents of a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Possible uses are dired (have all files in a list, and show them),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; buffer-list, kom-prioritize (in the LysKOM elisp client) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; others. pcl-cvs.el uses cookie.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; A `cookie' can be any lisp object. When you use the cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; package you specify a pretty-printer, a function that inserts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; a printable representation of the cookie in the buffer. (The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; pretty-printer should use "insert" and not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; "insert-before-markers").
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; A `collection' consists of a doubly linked list of cookies, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; header, a footer and a pretty-printer. It is displayed at a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; certain point in a certain buffer. (The buffer and point are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; fixed when the collection is created). The header and the footer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; are constant strings. They appear before and after the cookies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; (Currently, once set, they can not be changed).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; Cookie does not affect the mode of the buffer in any way. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; merely makes it easy to connect an underlying data representation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; to the buffer contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; A `tin' is an object that contains one cookie. There are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; functions in this package that given a tin extracts the cookie, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; gives the next or previous tin. (All tins are linked together in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; a doubly linked list. The 'previous' tin is the one that appears
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; before the other in the buffer.) You should not do anything with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; a tin except pass it to the functions in this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; A collection is a very dynamic thing. You can easily add or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; delete cookies. You can sort all cookies in a collection (you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; have to supply a function that compares two cookies). You can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; apply a function to all cookies in a collection, et c, et c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; Remember that a cookie can be anything. Your imagination is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; limit! It is even possible to have another collection as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; cookie. In that way some kind of tree hierarchy can be created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; Full documentation will, God willing, soon be available in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; Texinfo manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; Coding conventions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; ==================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; All functions that are intended for external use begin with one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; the prefixes "cookie-", "collection-" or "tin-". The prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; "elib-" is used for internal functions and macros. There are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; currently no global or buffer-local variables used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; Many function operate on `tins' instead of `cookies'. To avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; confusion most of the function names include the string "cookie"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; or "tin" to show this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; Most doc-strings contains an "Args:" line that lists the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; The internal functions don't contain any doc-strings. RMS thinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; this is a good way to save space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; INTERNAL DOCUMENTATION (Your understanding of this package might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;; increase if you read it, but you should not exploit the knowledge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; you gain. The internal details might change without notice).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; A collection is implemented as an dll (a doubly linked list).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; The first and last element on the list are always the header and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; footer (as strings). Any remaining entries are `wrappers'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; At the implementation level a `tin' is really an elib-node that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; consists of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; left Pointer to previous tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; right Pointer to next tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; data Holder of a `wrapper'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;; These internals of an elib-node are in fact unknown to cookie.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; It uses dll.el to handle everything that deals with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; doubly linked list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; The wrapper data type contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; start-marker Position of the printed representation of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; cookie in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; cookie The user-supplied cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; The wrapper is not accessible to the user of this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (require 'dll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (provide 'cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;; ================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;; Internal macros for use in the cookie package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (put 'elib-set-buffer-bind-dll 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defmacro elib-set-buffer-bind-dll (collection &rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; Execute FORMS with collection->buffer selected as current buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; and dll bound to collection->dll.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; Return value of last form in FORMS. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (let ((old-buffer (make-symbol "old-buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (hnd (make-symbol "collection")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (` (let* (((, old-buffer) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ((, hnd) (, collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (dll (elib-collection->dll (, hnd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (set-buffer (elib-collection->buffer (, hnd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (progn (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (set-buffer (, old-buffer)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (put 'elib-set-buffer-bind-dll-let* 'lisp-indent-hook 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (defmacro elib-set-buffer-bind-dll-let* (collection varlist &rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; Execute FORMS with collection->buffer selected as current buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; dll bound to collection->dll, and VARLIST bound as in a let*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; dll will be bound when VARLIST is initialized, but the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; buffer will *not* have been changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; Return value of last form in FORMS. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let ((old-buffer (make-symbol "old-buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (hnd (make-symbol "collection")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (` (let* (((, old-buffer) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ((, hnd) (, collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (dll (elib-collection->dll (, hnd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (,@ varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-buffer (elib-collection->buffer (, hnd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (progn (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (set-buffer (, old-buffer)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defmacro elib-filter-hf (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; Evaluate TIN once and return it. BUT if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; the header or the footer in COLLECTION return nil instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; Args: COLLECTION TIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((tempvar (make-symbol "tin"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (tmpcoll (make-symbol "tmpcollection")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (` (let (((, tempvar) (, tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ((, tmpcoll) (, collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (or (eq (, tempvar) (elib-collection->header (, tmpcoll)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (eq (, tempvar) (elib-collection->footer (, tmpcoll))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (, tempvar))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; ================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;; Internal data types for use in the cookie package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;; Yes, I know about cl.el, but I don't like it. /ceder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;; The wrapper data type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defun elib-create-wrapper (start-marker cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; Create a wrapper. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (cons 'WRAPPER (vector start-marker cookie)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun elib-wrapper->start-marker (wrapper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Get start-marker from wrapper. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (elt (cdr wrapper) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (defun elib-wrapper->cookie-safe (wrapper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; Get cookie from wrapper. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; Returns nil if given nil as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Since (elt nil 1) returns nil in emacs version 18.57 and 18.58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; this can be defined in this way. The documentation in the info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; file says that elt should signal an error in that case. I think
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; it is the documentation that is buggy. (The bug is reported).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (elt (cdr wrapper) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun elib-wrapper->cookie (wrapper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; Get cookie from wrapper. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (elt (cdr wrapper) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; The collection data type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun elib-create-collection (buffer pretty-printer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 header-wrapper footer-wrapper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 dll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; Create a collection. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (cons 'COLLECTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; The last element is a pointer to the last tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; the cursor was at, or nil if that is unknown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (vector buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 pretty-printer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 header-wrapper footer-wrapper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 dll nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun elib-collection->buffer (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; Get buffer from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (elt (cdr collection) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun elib-collection->pretty-printer (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;; Get pretty-printer from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (elt (cdr collection) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun elib-collection->header (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; Get header from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (elt (cdr collection) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (defun elib-collection->footer (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; Get footer from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (elt (cdr collection) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defun elib-collection->dll (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; Get dll from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (elt (cdr collection) 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defun elib-collection->last-tin (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; Get last-tin from COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (elt (cdr collection) 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defun elib-set-collection->buffer (collection buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Change the buffer. Args: COLLECTION BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (aset (cdr collection) 0 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun elib-set-collection->pretty-printer (collection pretty-printer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; Change the pretty-printer. Args: COLLECTION PRETTY-PRINTER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (aset (cdr collection) 1 pretty-printer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun elib-set-collection->header (collection header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; Change the header. Args: COLLECTION HEADER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (aset (cdr collection) 2 header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (defun elib-set-collection->footer (collection footer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; Change the footer. Args: COLLECTION FOOTER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (aset (cdr collection) 3 footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defun elib-set-collection->dll (collection dll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; Change the dll. Args: COLLECTION DLL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (aset (cdr collection) 4 dll))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defun elib-set-collection->last-tin (collection last-tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; Change the last-tin. Args: COLLECTION LAST-TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (aset (cdr collection) 5 last-tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;; ================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;;; Internal functions for use in the cookie package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun elib-abs (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; Return the absolute value of x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (max x (- x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defun elib-create-wrapper-and-insert (cookie string pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; Insert STRING at POS in current buffer. Remember the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; position. Create a wrapper containing that start position and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; COOKIE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;; INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; Remember the position as a number so that it doesn't move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; when we insert the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (let ((start (if (markerp pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (marker-position pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; Use insert-before-markers so that the marker for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;; next cookie is updated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (insert-before-markers string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ;; Always insert a newline. You want invisible cookies? You
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; lose. (At least in this version). FIXME-someday. (It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; harder to fix than it might seem. All markers have to point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; to the right place all the time...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (insert-before-markers ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (elib-create-wrapper (copy-marker start) cookie))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (defun elib-create-wrapper-and-pretty-print (cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 pretty-printer pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;; Call PRETTY-PRINTER with point set at POS in current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;; Remember the start position. Create a wrapper containing that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;; start position and the COOKIE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ;; INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; Remember the position as a number so that it doesn't move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; when we insert the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((start (if (markerp pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (marker-position pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; Insert the trailing newline using insert-before-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; so that the start position for the next cookie is updated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (insert-before-markers ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; Move back, and call the pretty-printer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (funcall pretty-printer cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (elib-create-wrapper (copy-marker start) cookie))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defun elib-delete-tin-internal (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; Delete a cookie string from COLLECTION. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; Can not be used on the footer. Returns the wrapper that is deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; The start-marker in the wrapper is set to nil, so that it doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; consume any more resources.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (let ((dll (elib-collection->dll collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; If we are about to delete the tin pointed at by last-tin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; set last-tin to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if (eq (elib-collection->last-tin collection) tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (elib-set-collection->last-tin collection nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (delete-region (elib-wrapper->start-marker (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (dll-element dll (dll-next dll tin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (set-marker (elib-wrapper->start-marker (dll-element dll tin)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; Delete the tin, and return the wrapper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (dll-delete dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun elib-refresh-tin (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; Redisplay the cookie represented by TIN. INTERNAL USE ONLY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; Args: COLLECTION TIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; Can not be used on the footer. dll *must* be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;; (elib-collection->dll collection).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; First, remove the string from the buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (delete-region (elib-wrapper->start-marker (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (1- (marker-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (dll-element dll (dll-next dll tin))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Calculate and insert the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (goto-char (elib-wrapper->start-marker (dll-element dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (funcall (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (elib-wrapper->cookie (dll-element dll tin))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (defun elib-pos-before-middle-p (collection pos tin1 tin2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; Return true if for the cookies in COLLECTION, POS is in the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; half of the region defined by TIN1 and TIN2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let ((dll (elib-collection->dll collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (< pos (/ (+ (elib-wrapper->start-marker (dll-element dll tin1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (elib-wrapper->start-marker (dll-element dll tin2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;; Public members of the cookie package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defun collection-create (buffer pretty-printer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 &optional header footer pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "Create an empty collection of cookies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 Args: BUFFER PRETTY-PRINTER &optional HEADER FOOTER POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 The collection will be inserted in BUFFER. BUFFER may be a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 buffer or a buffer name. It is created if it does not exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 PRETTY-PRINTER should be a function that takes one argument, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 cookie, and inserts a string representing it in the buffer (at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 point). The string PRETTY-PRINTER inserts may be empty or span
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 several linse. A trailing newline will always be inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 automatically. The PRETTY-PRINTER should use insert, and not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 insert-before-markers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 Optional third argument HEADER is a string that will always be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 present at the top of the collection. HEADER should end with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 newline. Optionaly fourth argument FOOTER is similar, and will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 always be inserted at the bottom of the collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Optional fifth argument POS is a buffer position, specifying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 where the collection will be inserted. It defaults to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 begining of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (let ((new-collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (elib-create-collection (get-buffer-create buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 pretty-printer nil nil (dll-create))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (elib-set-buffer-bind-dll new-collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;; Set default values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if (not header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq header ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (if (not footer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (setq footer ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if (not pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq pos (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (if (markerp pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (set pos (marker-position pos)))) ;Force header to be above footer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (let ((foot (elib-create-wrapper-and-insert footer footer pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (head (elib-create-wrapper-and-insert header header pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (dll-enter-first dll head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (dll-enter-last dll foot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (elib-set-collection->header new-collection (dll-nth dll 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (elib-set-collection->footer new-collection (dll-nth dll -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; Return the collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 new-collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (defun tin-cookie (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 "Get the cookie from a TIN. Args: COLLECTION TIN."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (elib-wrapper->cookie (dll-element (cookie->dll collection) tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defun cookie-enter-first (collection cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "Enter a COOKIE first in the cookie collection COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 Args: COLLECTION COOKIE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;; It is always safe to insert an element after the first element,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; because the header is always present. (dll-nth dll 0) should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; therefore never return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (dll-enter-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 dll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (dll-nth dll 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (elib-create-wrapper-and-pretty-print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (dll-element dll (dll-nth dll 1)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (defun cookie-enter-last (collection cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 "Enter a COOKIE last in the cookie-collection COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Args: COLLECTION COOKIE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; Remember that the header and footer are always present. There
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; is no need to check if (dll-nth dll -1) returns nil - it never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (dll-enter-before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 dll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (dll-nth dll -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (elib-create-wrapper-and-pretty-print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (elib-wrapper->start-marker (dll-last dll))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (defun cookie-enter-after-tin (collection tin cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 "Enter a new COOKIE after TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 Args: COLLECTION TIN COOKIE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (dll-enter-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 dll tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (elib-create-wrapper-and-pretty-print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (elib-wrapper->start-marker (dll-element dll (dll-next dll tin)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (defun cookie-enter-before-tin (collection tin cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 "Enter a new COOKIE before TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 Args: COLLECTION TIN COOKIE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (dll-enter-before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 dll tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (elib-create-wrapper-and-pretty-print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (elib-wrapper->start-marker (dll-element dll tin))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defun tin-next (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 "Get the next tin. Args: COLLECTION TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 Returns nil if TIN is nil or the last cookie."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (if tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (elib-filter-hf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 collection (dll-next (elib-collection->dll collection) tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (defun tin-previous (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 "Get the previous tin. Args: COLLECTION TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 Returns nil if TIN is nil or the first cookie."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (if tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (elib-filter-hf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (dll-previous (elib-collection->dll collection) tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (defun tin-nth (collection n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 "Return the Nth tin. Args: COLLECTION N.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 N counts from zero. Nil is returned if there is less than N cookies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 If N is negative, return the -(N+1)th last element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 Thus, (tin-nth dll 0) returns the first node,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 and (tin-nth dll -1) returns the last node.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 Use tin-cookie to extract the cookie from the tin (or use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 cookie-nth instead)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; Skip the header (or footer, if n is negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (if (< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (setq n (1- n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (setq n (1+ n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (elib-filter-hf collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (dll-nth (elib-collection->dll collection) n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (defun cookie-nth (collection n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 "Return the Nth cookie. Args: COLLECTION N.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 N counts from zero. Nil is returned if there is less than N cookies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 If N is negative, return the -(N+1)th last element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 Thus, (cookie-nth dll 0) returns the first cookie,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 and (cookie-nth dll -1) returns the last cookie."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; Skip the header (or footer, if n is negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (if (< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (setq n (1- n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (setq n (1+ n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (let* ((dll (elib-collection->dll collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (tin (elib-filter-hf collection (dll-nth dll n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (if tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (defun tin-delete (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 "Delete a tin from a collection. Args: COLLECTION TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 The cookie in the tin is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (elib-wrapper->cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (elib-delete-tin-internal collection tin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (defun cookie-delete-first (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 "Delete first cookie and return it. Args: COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 Returns nil if there are no cookies left in the collection."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ((tin (dll-nth dll 1))) ;Skip the header.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; We have to check that we do not try to delete the footer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (if (eq tin (elib-collection->footer collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (elib-wrapper->cookie (elib-delete-tin-internal collection tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (defun cookie-delete-last (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 "Delete last cookie and return it. Args: COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 Returns nil if there is no cookie left in the collection."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ((tin (dll-nth dll -2))) ;Skip the footer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ;; We have to check that we do not try to delete the header.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (if (eq tin (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (elib-wrapper->cookie (elib-delete-tin-internal collection tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (defun cookie-first (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 "Return the first cookie in COLLECTION. The cookie is not removed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (let* ((dll (elib-collection->dll collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (tin (elib-filter-hf collection (dll-nth dll -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (if tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (elib-wrapper->cookie (dll-element dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (defun cookie-last (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 "Return the last cookie in COLLECTION. The cookie is not removed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (let* ((dll (elib-collection->dll collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (tin (elib-filter-hf collection (dll-nth dll -2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (if tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (elib-wrapper->cookie (dll-element dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (defun collection-empty (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 "Return true if there are no cookies in COLLECTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (eq (dll-nth (elib-collection->dll collection) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (elib-collection->footer collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (defun collection-length (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 "Return the number of cookies in COLLECTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; Don't count the footer and header.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (- (dll-length (elib-collection->dll collection)) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (defun collection-list-cookies (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 "Return a list of all cookies in COLLECTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ((result nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (tin (dll-nth dll -2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (while (not (eq tin header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (setq result (cons (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (setq tin (dll-previous dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (defun collection-clear (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 "Remove all cookies in COLLECTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ((header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (footer (elib-collection->footer collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; We have to bind buffer-read-only separately, so that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; current buffer is correct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (delete-region (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (dll-element dll (dll-nth dll 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (dll-element dll footer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (setq dll (dll-create-from-list (list (dll-element dll header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (dll-element dll footer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (elib-set-collection->dll collection dll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; Re-set the header and footer, since they are now new objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; elib-filter-hf uses eq to compare objects to them...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (elib-set-collection->header collection (dll-nth dll 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (elib-set-collection->footer collection (dll-nth dll -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (defun cookie-map (map-function collection &rest map-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 "Apply MAP-FUNCTION to all cookies in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 MAP-FUNCTION is applied to the first element first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 If MAP-FUNCTION returns non-nil the cookie will be refreshed (its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 pretty-printer will be called once again).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 Note that the buffer for COLLECTION will be current buffer when MAP-FUNCTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 is called. MAP-FUNCTION must restore the current buffer to BUFFER before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 it returns, if it changes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 If more than two arguments are given to cookie-map, remaining
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 arguments will be passed to MAP-FUNCTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ((footer (elib-collection->footer collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (tin (dll-nth dll 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (while (not (eq tin footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (if (apply map-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 map-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (elib-refresh-tin collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (setq tin (dll-next dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (defun cookie-map-reverse (map-function collection &rest map-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 "Apply MAP-FUNCTION to all cookies in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 MAP-FUNCTION is applied to the last cookie first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 If MAP-FUNCTION returns non-nil the cookie will be refreshed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 Note that the buffer for COLLECTION will be current buffer when MAP-FUNCTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 is called. MAP-FUNCTION must restore the current buffer to BUFFER before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 it returns, if it changes the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 If more than two arguments are given to cookie-map, remaining
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 arguments will be passed to MAP-FUNCTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ((header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (tin (dll-nth dll -2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (while (not (eq tin header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (if (apply map-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 map-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (elib-refresh-tin collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (setq tin (dll-previous dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (defun collection-append-cookies (collection cookie-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 "Insert all cookies in the list COOKIE-LIST last in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 Args: COLLECTION COOKIE-LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (while cookie-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (cookie-enter-last collection (car cookie-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (setq cookie-list (cdr cookie-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun collection-filter-cookies (collection predicate &rest extra-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 "Remove all cookies in COLLECTION for which PREDICATE returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 Args: COLLECTION PREDICATE &rest EXTRA-ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 Note that the buffer for COLLECTION will be current-buffer when PREDICATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 is called. PREDICATE must restore the current buffer before it returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 if it changes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 The PREDICATE is called with the cookie as its first argument. If any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 EXTRA-ARGS are given to collection-filter-cookies they will be passed to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 PREDICATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ((tin (dll-nth dll 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (footer (elib-collection->footer collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (next nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (while (not (eq tin footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (setq next (dll-next dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (if (apply predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 extra-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (elib-delete-tin-internal collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq tin next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (defun collection-filter-tins (collection predicate &rest extra-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 "Remove all cookies in COLLECTION for which PREDICATE returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 Note that the buffer for COLLECTION will be current-buffer when PREDICATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 is called. PREDICATE must restore the current buffer before it returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 if it changes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 The PREDICATE is called with one argument, the tin. If any EXTRA-ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 are given to collection-filter-cookies they will be passed to the PREDICATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ((tin (dll-nth dll 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (footer (elib-collection->footer collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (next nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (while (not (eq tin footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (setq next (dll-next dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (if (apply predicate tin extra-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (elib-delete-tin-internal collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (setq tin next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (defun tin-locate (collection pos &optional guess)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 "Return the tin that POS (a buffer position) is within.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 Args: COLLECTION POS &optional GUESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 POS may be a marker or an integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 GUESS should be a tin that it is likely that POS is near.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 If POS points before the first cookie, the first cookie is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 If POS points after the last cookie, the last cookie is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 If the COLLECTION is empty, nil is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ((footer (elib-collection->footer collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;; No cookies present?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ((eq (dll-nth dll 1) (dll-nth dll -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ;; Before first cookie?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ((< pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (dll-element dll (dll-nth dll 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (dll-nth dll 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;; After last cookie?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ((>= pos (elib-wrapper->start-marker (dll-last dll)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (dll-nth dll -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;; We now now that pos is within a cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;; Make an educated guess about which of the three known
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;; cookies (the first, the last, or GUESS) is nearest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (let* ((best-guess (dll-nth dll 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (distance (elib-abs (- pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (dll-element dll best-guess))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (if guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (let* ((g guess) ;Check the guess, if given.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (d (elib-abs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (- pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (dll-element dll g))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ((< d distance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq distance d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (setq best-guess g)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (let* ((g (dll-nth dll -1)) ;Check the last cookie
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (d (elib-abs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (- pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (dll-element dll g))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ((< d distance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (setq distance d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq best-guess g))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (if (elib-collection->last-tin collection) ;Check "previous".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (let* ((g (elib-collection->last-tin collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (d (elib-abs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (- pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (dll-element dll g))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ((< d distance)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (setq distance d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (setq best-guess g)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;; best-guess is now a "best guess".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;; Find the correct cookie. First determine in which direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;; it lies, and then move in that direction until it is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; Is pos after the guess?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ((>= pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (elib-wrapper->start-marker (dll-element dll best-guess)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ;; Loop until we are exactly one cookie too far down...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (while (>= pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (dll-element dll best-guess)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (setq best-guess (dll-next dll best-guess)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; ...and return the previous cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (dll-previous dll best-guess))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ;; Pos is before best-guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (while (< pos (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (dll-element dll best-guess)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq best-guess (dll-previous dll best-guess)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 best-guess)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;;(defun tin-start-marker (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ;; "Return start-position of a cookie in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ;;Args: COLLECTION TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 ;;The marker that is returned should not be modified in any way,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;;and is only valid until the contents of the cookie buffer changes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ;; (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; (dll-element (elib-collection->dll collection) tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;;(defun tin-end-marker (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;; "Return end-position of a cookie in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ;;Args: COLLECTION TIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 ;;The marker that is returned should not be modified in any way,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;;and is only valid until the contents of the cookie buffer changes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; (let ((dll (elib-collection->dll collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;; (dll-element dll (dll-next dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (defun collection-refresh (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 "Refresh all cookies in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 The pretty-printer that was specified when the COLLECTION was created
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 will be called for all cookies in COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 Note that tin-invalidate is more efficient if only a small
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 number of cookies needs to be refreshed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ((header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (footer (elib-collection->footer collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (delete-region (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (dll-element dll (dll-nth dll 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (dll-element dll footer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (goto-char (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (dll-element dll footer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (let ((tin (dll-nth dll 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (while (not (eq tin footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (set-marker (elib-wrapper->start-marker (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (funcall (elib-collection->pretty-printer collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (elib-wrapper->cookie (dll-element dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (setq tin (dll-next dll tin)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (set-marker (elib-wrapper->start-marker (dll-element dll footer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (defun tin-invalidate (collection &rest tins)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 "Refresh some cookies. Args: COLLECTION &rest TINS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 The pretty-printer that for COLLECTION will be called for all TINS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (while tins
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (elib-refresh-tin collection (car tins))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (setq tins (cdr tins)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (defun collection-set-goal-column (collection goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 "Set goal-column for COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 Args: COLLECTION GOAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 goal-column is made buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 There will eventually be a better way to specify the cursor position."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (make-local-variable 'goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (setq goal-column goal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (defun tin-goto-previous (collection pos arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 "Move point to the ARGth previous cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 Don't move if we are at the first cookie, or if COLLECTION is empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 Args: COLLECTION POS ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 Returns the tin we move to."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ((tin (tin-locate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 collection pos (elib-collection->last-tin collection))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (tin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (while (and tin (> arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (setq tin (dll-previous dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;; Never step above the first cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (if (null (elib-filter-hf collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (setq tin (dll-nth dll 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (dll-element dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (if goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (move-to-column goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (elib-set-collection->last-tin collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 tin))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (defun tin-goto-next (collection pos arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 "Move point to the ARGth next cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 Don't move if we are at the last cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 Args: COLLECTION POS ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 Returns the tin."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 ;;Need to do something clever with (current-buffer)...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ;;Previously, when the buffer was used instead of the collection, this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 ;;did the trick. No longer so... This is hard to do right! Remember that a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 ;;cookie can contain a collection!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ;;(interactive (list (current-buffer) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 ;; (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ((tin (tin-locate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 collection pos (elib-collection->last-tin collection))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (while (and tin (> arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (setq tin (dll-next dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; Never step below the first cookie.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (if (null (elib-filter-hf collection tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (setq tin (dll-nth dll -2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (dll-element dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (if goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (move-to-column goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (elib-set-collection->last-tin collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (defun tin-goto (collection tin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 "Move point to TIN. Args: COLLECTION TIN."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (elib-set-buffer-bind-dll collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (elib-wrapper->start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (dll-element dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (if goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (move-to-column goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (elib-set-collection->last-tin collection tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (defun collection-collect-tin (collection predicate &rest predicate-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 "Select cookies from COLLECTION using PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 Return a list of all selected tins.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 PREDICATE is a function that takes a cookie as its first argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 The tins on the returned list will appear in the same order as in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 buffer. You should not rely on in which order PREDICATE is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 Note that the buffer the COLLECTION is displayed in is current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 when PREDICATE is called. If PREDICATE must restore current-buffer if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 it changes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 If more than two arguments are given to collection-collect-tin the remaining
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 arguments will be passed to PREDICATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ((header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (tin (dll-nth dll -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ;; Collect the tins, starting at the last one, so that they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ;; appear in the correct order in the result (which is cons'ed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 ;; together).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (while (not (eq tin header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (if (apply predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 predicate-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (setq result (cons tin result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (setq tin (dll-previous dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (defun collection-collect-cookie (collection predicate &rest predicate-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 "Select cookies from COLLECTION using PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 Return a list of all selected cookies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 PREDICATE is a function that takes a cookie as its first argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 The cookies on the returned list will appear in the same order as in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 the buffer. You should not rely on in which order PREDICATE is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 Note that the buffer the COLLECTION is displayed in is current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 when PREDICATE is called. If PREDICATE must restore current-buffer if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 it changes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 If more than two arguments are given to collection-collect-cookie the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 remaining arguments will be passed to PREDICATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (elib-set-buffer-bind-dll-let* collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ((header (elib-collection->header collection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (tin (dll-nth dll -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (while (not (eq tin header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (if (apply predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 predicate-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (setq result (cons (elib-wrapper->cookie (dll-element dll tin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (setq tin (dll-previous dll tin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (defun cookie-sort (collection predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 "Sort the cookies in COLLECTION, stably, comparing elements using PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 PREDICATE is called with two cookies, and should return T
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 if the first cookie is \"less\" than the second.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 All cookies will be refreshed when the sort is complete."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (elib-set-collection->last-tin collection nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (collection-append-cookies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (prog1 (sort (collection-list-cookies collection) predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (collection-clear collection))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (defun collection-buffer (collection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 "Return the buffer that is associated with COLLECTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 Returns nil if the buffer has been deleted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (let ((buf (elib-collection->buffer collection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (if (buffer-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 ;;; Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 ;;; eval: (put 'elib-set-buffer-bind-dll 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 ;;; eval: (put 'elib-set-buffer-bind-dll-let* 'lisp-indent-hook 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ;;; End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;;; cookie.el ends here