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