Mercurial > emacs
annotate lisp/textmodes/page-ext.el @ 47667:96b260e0ff3d
New major mode "SES" for spreadsheets.
New function (unsafep X) determines whether X is a safe Lisp form.
New support module testcover.el for coverage testing.
author | Jonathan Yavner <jyavner@member.fsf.org> |
---|---|
date | Sat, 28 Sep 2002 18:45:56 +0000 |
parents | 28ae6b9b086e |
children | 5ade352e8d1c |
rev | line source |
---|---|
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1 ;;; page-ext.el --- extended page handling commands |
235 | 2 |
7300 | 3 ;; Copyright (C) 1990, 1991, 1993, 1994 Free Software Foundation |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
4 |
25278 | 5 ;; Maintainer: Robert J. Chassell <bob@gnu.org> |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
6 ;; Keywords: wp data |
235 | 7 |
664
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
9 |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
664
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
664
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
13 ;; any later version. |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
14 |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
18 ;; GNU General Public License for more details. |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
19 |
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; You may use these commands to handle an address list or other | |
28 ;; small data base. | |
664
9b0e666dfdf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
29 |
235 | 30 |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
31 ;;; Summary |
235 | 32 |
14169 | 33 ;; The current page commands are: |
235 | 34 |
14169 | 35 ;; forward-page C-x ] |
36 ;; backward-page C-x [ | |
37 ;; narrow-to-page C-x p | |
38 ;; count-lines-page C-x l | |
39 ;; mark-page C-x C-p (change this to C-x C-p C-m) | |
40 ;; sort-pages not bound | |
41 ;; what-page not bound | |
235 | 42 |
14169 | 43 ;; The new page handling commands all use `C-x C-p' as a prefix. This |
44 ;; means that the key binding for `mark-page' must be changed. | |
45 ;; Otherwise, no other changes are made to the current commands or | |
46 ;; their bindings. | |
235 | 47 |
14169 | 48 ;; New page handling commands: |
235 | 49 |
14169 | 50 ;; next-page C-x C-p C-n |
51 ;; previous-page C-x C-p C-p | |
52 ;; search-pages C-x C-p C-s | |
53 ;; add-new-page C-x C-p C-a | |
54 ;; sort-pages-buffer C-x C-p s | |
55 ;; set-page-delimiter C-x C-p C-l | |
56 ;; pages-directory C-x C-p C-d | |
57 ;; pages-directory-for-addresses C-x C-p d | |
58 ;; pages-directory-goto C-c C-c | |
235 | 59 |
60 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
61 ;;; Using the page commands |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
62 |
14169 | 63 ;; The page commands are helpful in several different contexts. For |
64 ;; example, programmers often divide source files into sections using the | |
65 ;; `page-delimiter'; you can use the `pages-directory' command to list | |
66 ;; the sections. | |
235 | 67 |
14169 | 68 ;; You may change the buffer local value of the `page-delimiter' with |
69 ;; the `set-page-delimiter' command. This command is bound to `C-x C-p | |
70 ;; C-l' The command prompts you for a new value for the page-delimiter. | |
71 ;; Called with a prefix-arg, the command resets the value of the | |
72 ;; page-delimiter to its original value. | |
235 | 73 |
14169 | 74 ;; You may set several user options: |
75 ;; | |
76 ;; The `pages-directory-buffer-narrowing-p' variable causes the | |
77 ;; `pages-directory-goto' command to narrow to the destination page. | |
78 ;; | |
79 ;; The `pages-directory-for-adding-page-narrowing-p' variable, causes the | |
80 ;; `add-new-page' command to narrow to the new entry. | |
81 ;; | |
82 ;; The `pages-directory-for-adding-new-page-before-current-page-p' variable | |
83 ;; causes the `add-new-page' command to insert a new page before current | |
84 ;; page. | |
85 ;; | |
86 ;; These variables are true by default. | |
87 ;; | |
88 ;; Additional, addresses-related user options are described in the next page | |
89 ;; of this file. | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
90 |
235 | 91 |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
92 ;;; Handling an address list or small data base |
235 | 93 |
14169 | 94 ;; You may use the page commands to handle an address list or other |
95 ;; small data base. Put each address or entry on its own page. The | |
96 ;; first line of text in each page is a `header line' and is listed by | |
97 ;; the `pages-directory' or `pages-directory-for-addresses' command. | |
235 | 98 |
14169 | 99 ;; Specifically: |
100 ;; | |
101 ;; 1. Begin each entry with a `page-delimiter' (which is, by default, | |
102 ;; `^L' at the beginning of the line). | |
103 ;; | |
104 ;; 2. The first line of text in each entry is the `heading line'; it | |
105 ;; will appear in the pages-directory-buffer which is constructed | |
106 ;; using the `C-x C-p C-d' (pages-directory) command or the `C-x | |
107 ;; C-p d' (pages-directory-for-addresses) command. | |
108 ;; | |
109 ;; The heading line may be on the same line as the page-delimiter | |
110 ;; or it may follow after. It is the first non-blank line on the | |
111 ;; page. Conventionally, the heading line is placed on the line | |
112 ;; immediately following the line containing page-delimiter. | |
113 ;; | |
114 ;; 3. Follow the heading line with the body of the entry. The body | |
115 ;; extends up to the next `page-delimiter'. The body may be of any | |
116 ;; length. It is conventional to place a blank line after the last | |
117 ;; line of the body. | |
235 | 118 |
14169 | 119 ;; For example, a file might look like this: |
120 ;; | |
121 ;; FSF | |
122 ;; Free Software Foundation | |
15741
a1176aab935b
Use current FSF address/phone in sample file.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
123 ;; 59 Temple Place - Suite 330 |
a1176aab935b
Use current FSF address/phone in sample file.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
124 ;; Boston, MA 02111-1307 USA. |
a1176aab935b
Use current FSF address/phone in sample file.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
125 ;; (617) 542-5942 |
25278 | 126 ;; gnu@gnu.org |
14169 | 127 ;; |
128 ;; | |
129 ;; House Subcommittee on Intellectual Property, | |
130 ;; U.S. House of Representatives, | |
131 ;; Washington, DC 20515 | |
132 ;; | |
133 ;; Congressional committee concerned with permitting or preventing | |
134 ;; monopolistic restrictions on the use of software technology. | |
135 ;; | |
136 ;; | |
137 ;; George Lakoff | |
138 ;; ``Women, Fire, and Dangerous Things: | |
139 ;; What Categories Reveal about the Mind'' | |
140 ;; 1987, Univ. of Chicago Press | |
141 ;; | |
142 ;; About philosophy, Whorfian effects, and linguistics. | |
143 ;; | |
144 ;; | |
145 ;; OBI (On line text collection.) | |
146 ;; Open Book Initiative | |
147 ;; c/o Software Tool & Die | |
148 ;; 1330 Beacon St, Brookline, MA 02146 USA | |
149 ;; (617) 739-0202 | |
150 ;; obi@world.std.com | |
235 | 151 |
14169 | 152 ;; In this example, the heading lines are: |
153 ;; | |
154 ;; FSF | |
155 ;; House Subcommittee on Intellectual Property | |
156 ;; George Lakoff | |
157 ;; OBI (On line text collection.) | |
235 | 158 |
14169 | 159 ;; The `C-x C-p s' (sort-pages-buffer) command sorts the entries in the |
160 ;; buffer alphabetically. | |
235 | 161 |
14169 | 162 ;; You may use any of the page commands, including the `next-page', |
163 ;; `previous-page', `add-new-page', `mark-page', and `search-pages' | |
164 ;; commands. | |
235 | 165 |
14169 | 166 ;; You may use either the `C-x C-p d' (pages-directory-for-addresses) |
167 ;; or the `C-x C-p C-d' (pages-directory) command to construct and | |
168 ;; display a directory of all the heading lines. | |
235 | 169 |
14169 | 170 ;; In the directory, you may position the cursor over a heading line |
171 ;; and type `C-c C-c' (pages-directory-goto) to go to the entry to | |
172 ;; which it refers in the pages buffer. | |
235 | 173 |
14169 | 174 ;; You can type `C-c C-p C-a' (add-new-page) to add a new entry in the |
175 ;; pages buffer or address file. This is the same command you use to | |
176 ;; add a new entry when you are in the pages buffer or address file. | |
235 | 177 |
14169 | 178 ;; If you wish, you may create several different directories, |
179 ;; one for each different buffer. | |
235 | 180 |
181 ;; `pages-directory-for-addresses' in detail | |
182 | |
14169 | 183 ;; The `pages-directory-for-addresses' assumes a default addresses |
184 ;; file. You do not need to specify the addresses file but merely type | |
185 ;; `C-x C-p d' from any buffer. The command finds the file, constructs | |
186 ;; a directory for it, and switches you to the directory. If you call | |
187 ;; the command with a prefix arg, `C-u C-x C-p d', it prompts you for a | |
188 ;; file name. | |
235 | 189 |
14169 | 190 ;; You may customize the addresses commands: |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
191 |
14169 | 192 ;; The `pages-addresses-file-name' variable determines the name of |
193 ;; the addresses file; by default it is "~/addresses". | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
194 |
14169 | 195 ;; The `pages-directory-for-addresses-goto-narrowing-p' variable |
196 ;; determines whether `pages-directory-goto' narrows the addresses | |
197 ;; buffer to the entry, which it does by default. | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
198 |
14169 | 199 ;; The `pages-directory-for-addresses-buffer-keep-windows-p' variable |
200 ;; determines whether `pages-directory-for-addresses' deletes other | |
201 ;; windows to show as many lines as possible on the screen or works | |
202 ;; in the usual Emacs manner and keeps other windows. Default is to | |
203 ;; keep other windows. | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
204 |
14169 | 205 ;; The `pages-directory-for-adding-addresses-narrowing-p' variable |
206 ;; determines whether `pages-directory-for-addresses' narrows the | |
207 ;; addresses buffer to a new entry when you are adding that entry. | |
208 ;; Default is to narrow to new entry, which means you see a blank | |
209 ;; screen before you write the new entry. | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
210 |
235 | 211 ;; `pages-directory' in detail |
212 | |
14169 | 213 ;; Call the `pages-directory' command from the buffer for which you |
214 ;; want a directory created; it creates a directory for the buffer and | |
215 ;; pops you to the directory. | |
235 | 216 |
14169 | 217 ;; The `pages-directory' command has several options: |
235 | 218 |
14169 | 219 ;; Called with a prefix arg, `C-u C-x C-p C-d', the `pages-directory' |
220 ;; prompts you for a regular expression and only lists only those | |
221 ;; header lines that are part of pages that contain matches to the | |
222 ;; regexp. In the example above, `C-u C-x C-p C-d 617 RET' would | |
223 ;; match the telephone area code of the first and fourth entries, so | |
224 ;; only the header lines of those two entries would appear in the | |
225 ;; pages-directory-buffer. | |
226 ;; | |
227 ;; Called with a numeric argument, the `pages-directory' command | |
228 ;; lists the number of lines in each page. This is helpful when you | |
229 ;; are printing hardcopy. | |
235 | 230 |
14169 | 231 ;; Called with a negative numeric argument, the `pages-directory' |
232 ;; command lists the lengths of pages whose contents match a regexp. | |
235 | 233 |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
234 ;;; Code: |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
235 |
235 | 236 |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
237 ;;; Customarily customizable variable definitions |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
238 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
239 (defgroup pages nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
240 "Extended page-handling commands." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
241 :group 'extensions) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
242 |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
243 |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
244 (defcustom pages-directory-buffer-narrowing-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
245 "*If non-nil, `pages-directory-goto' narrows pages buffer to entry." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
246 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
247 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
248 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
249 (defcustom pages-directory-for-adding-page-narrowing-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
250 "*If non-nil, `add-new-page' narrows page buffer to new entry." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
251 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
252 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
253 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
254 (defcustom pages-directory-for-adding-new-page-before-current-page-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
255 "*If non-nil, `add-new-page' inserts new page before current page." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
256 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
257 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
258 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
259 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
260 ;;; Addresses related variables |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
261 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
262 (defcustom pages-addresses-file-name "~/addresses" |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
263 "*Standard name for file of addresses. Entries separated by page-delimiter. |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
264 Used by `pages-directory-for-addresses' function." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
265 :type 'file |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
266 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
267 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
268 (defcustom pages-directory-for-addresses-goto-narrowing-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
269 "*If non-nil, `pages-directory-goto' narrows addresses buffer to entry." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
270 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
271 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
272 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
273 (defcustom pages-directory-for-addresses-buffer-keep-windows-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
274 "*If nil, `pages-directory-for-addresses' deletes other windows." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
275 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
276 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
277 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
278 (defcustom pages-directory-for-adding-addresses-narrowing-p t |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
279 "*If non-nil, `add-new-page' narrows addresses buffer to new entry." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
280 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15741
diff
changeset
|
281 :group 'pages) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
282 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
283 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
284 ;;; Key bindings for page handling functions |
235 | 285 |
286 (global-unset-key "\C-x\C-p") | |
287 | |
288 (defvar ctl-x-ctl-p-map (make-sparse-keymap) | |
289 "Keymap for subcommands of C-x C-p, which are for page handling.") | |
290 | |
291 (define-key ctl-x-map "\C-p" 'ctl-x-ctl-p-prefix) | |
292 (fset 'ctl-x-ctl-p-prefix ctl-x-ctl-p-map) | |
293 | |
294 (define-key ctl-x-ctl-p-map "\C-n" 'next-page) | |
295 (define-key ctl-x-ctl-p-map "\C-p" 'previous-page) | |
296 (define-key ctl-x-ctl-p-map "\C-a" 'add-new-page) | |
297 (define-key ctl-x-ctl-p-map "\C-m" 'mark-page) | |
298 (define-key ctl-x-ctl-p-map "\C-s" 'search-pages) | |
299 (define-key ctl-x-ctl-p-map "s" 'sort-pages-buffer) | |
300 (define-key ctl-x-ctl-p-map "\C-l" 'set-page-delimiter) | |
301 (define-key ctl-x-ctl-p-map "\C-d" 'pages-directory) | |
302 (define-key ctl-x-ctl-p-map "d" 'pages-directory-for-addresses) | |
303 | |
304 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
305 ;;; Page movement function definitions |
235 | 306 |
307 (defun next-page (&optional count) | |
308 "Move to the next page bounded by the `page-delimiter' variable. | |
309 With arg (prefix if interactive), move that many pages." | |
310 (interactive "p") | |
311 (or count (setq count 1)) | |
312 (widen) | |
313 ;; Cannot use forward-page because of problems at page boundaries. | |
314 (while (and (> count 0) (not (eobp))) | |
315 (if (re-search-forward page-delimiter nil t) | |
316 nil | |
317 (goto-char (point-max))) | |
318 (setq count (1- count))) | |
1770
29bcc2c88773
* page-ext.el (next-page): Correctly handle negative page count.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
319 ;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries. |
29bcc2c88773
* page-ext.el (next-page): Correctly handle negative page count.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
320 ;; The first page boundary we reach is the top of the current page, |
29bcc2c88773
* page-ext.el (next-page): Correctly handle negative page count.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
321 ;; which doesn't count. |
29bcc2c88773
* page-ext.el (next-page): Correctly handle negative page count.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
322 (while (and (< count 1) (not (bobp))) |
235 | 323 (if (re-search-backward page-delimiter nil t) |
324 (goto-char (match-beginning 0)) | |
325 (goto-char (point-min))) | |
326 (setq count (1+ count))) | |
327 (narrow-to-page) | |
328 (goto-char (point-min)) | |
329 (recenter 0)) | |
330 | |
331 (defun previous-page (&optional count) | |
332 "Move to the previous page bounded by the `page-delimiter' variable. | |
333 With arg (prefix if interactive), move that many pages." | |
334 (interactive "p") | |
335 (or count (setq count 1)) | |
336 (next-page (- count))) | |
337 | |
338 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
339 ;;; Adding and searching pages |
235 | 340 |
341 (defun add-new-page (header-line) | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
342 "Insert new page. Prompt for header line. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
343 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
344 If point is in the pages directory buffer, insert the new page in the |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
345 buffer associated with the directory. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
346 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
347 Insert the new page just before current page if |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
348 pages-directory-for-adding-new-page-before-current-page-p variable |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
349 is non-nil. Else insert at exact location of point. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
350 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
351 Narrow to new page if |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
352 pages-directory-for-adding-page-narrowing-p variable |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
353 is non-nil. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
354 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
355 Page begins with a `^L' as the default page-delimiter. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
356 Use \\[set-page-delimiter] to change the page-delimiter. |
235 | 357 Point is left in the body of page." |
358 (interactive "sHeader line: ") | |
359 (widen) | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
360 ;; If in pages directory buffer |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
361 (if (eq major-mode 'pages-directory-mode) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
362 (progn |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
363 ;; Add new page before or after current page? |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
364 (if pages-directory-for-adding-new-page-before-current-page-p |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
365 (pages-directory-goto) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
366 (pages-directory-goto) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
367 (forward-page) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
368 (or (eobp) (forward-line -1))))) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
369 (widen) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
370 ;; Move point before current delimiter if desired. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
371 (and pages-directory-for-adding-new-page-before-current-page-p |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
372 (if (re-search-backward page-delimiter nil t) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
373 (goto-char (match-beginning 0)) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
374 ;; If going to beginning of file, insert a page-delimiter |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
375 ;; before current first page. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
376 (goto-char (point-min)) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
377 (insert |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
378 (format "%s\n" |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
379 ;; Remove leading `^' from page-delimiter string |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
380 (if (eq '^ (car (read-from-string page-delimiter))) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
381 (substring page-delimiter 1)))) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
382 (goto-char (point-min)))) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
383 ;; Insert page delimiter at beginning of line. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
384 (if (not (looking-at "^.")) (forward-line 1)) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
385 (insert (format "%s\n%s\n\n\n" |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
386 (if (eq '^ (car (read-from-string page-delimiter))) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
387 (substring page-delimiter 1)) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
388 header-line)) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
389 (forward-line -1) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
390 (and pages-directory-for-adding-page-narrowing-p (narrow-to-page))) |
235 | 391 |
392 (defvar pages-last-search nil | |
393 "Value of last regexp searched for. Initially, nil.") | |
394 | |
395 (defun search-pages (regexp) | |
396 "Search for REGEXP, starting from point, and narrow to page it is in." | |
397 (interactive (list | |
398 (read-string | |
399 (format "Search for `%s' (end with RET): " | |
400 (or pages-last-search "regexp"))))) | |
401 (if (equal regexp "") | |
402 (setq regexp pages-last-search) | |
403 (setq pages-last-search regexp)) | |
404 (widen) | |
405 (re-search-forward regexp) | |
406 (narrow-to-page)) | |
407 | |
408 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
409 ;;; Sorting pages |
235 | 410 |
411 (autoload 'sort-subr "sort" "Primary function for sorting." t nil) | |
412 | |
413 (defun sort-pages-in-region (reverse beg end) | |
414 "Sort pages in region alphabetically. Prefix arg means reverse order. | |
415 | |
416 Called from a program, there are three arguments: | |
417 REVERSE (non-nil means reverse order), BEG and END (region to sort)." | |
418 | |
419 ;;; This sort function handles ends of pages differently than | |
420 ;;; `sort-pages' and works better with lists of addresses and similar | |
421 ;;; files. | |
422 | |
423 (interactive "P\nr") | |
424 (save-restriction | |
425 (narrow-to-region beg end) | |
426 (goto-char (point-min)) | |
427 ;;; `sort-subr' takes three arguments | |
428 (sort-subr reverse | |
429 | |
430 ;; NEXTRECFUN is called with point at the end of the | |
431 ;; previous record. It moves point to the start of the | |
432 ;; next record. | |
433 (function (lambda () | |
434 (re-search-forward page-delimiter nil t) | |
435 (skip-chars-forward " \t\n") | |
436 )) | |
437 | |
438 ;; ENDRECFUN is is called with point within the record. | |
439 ;; It should move point to the end of the record. | |
440 (function (lambda () | |
441 (if (re-search-forward | |
442 page-delimiter | |
443 nil | |
444 t) | |
445 (goto-char (match-beginning 0)) | |
446 (goto-char (point-max)))))))) | |
447 | |
448 (defun sort-pages-buffer (&optional reverse) | |
449 "Sort pages alphabetically in buffer. Prefix arg means reverse order. | |
450 \(Non-nil arg if not interactive.\)" | |
451 | |
452 (interactive "P") | |
453 (or reverse (setq reverse nil)) | |
454 (widen) | |
455 (let ((beginning (point-min)) | |
456 (end (point-max))) | |
457 (sort-pages-in-region reverse beginning end))) | |
458 | |
459 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
460 ;;; Pages directory ancillary definitions |
235 | 461 |
462 (defvar pages-directory-previous-regexp nil | |
463 "Value of previous regexp used by `pages-directory'. | |
464 \(This regular expression may be used to select only those pages that | |
465 contain matches to the regexp.\)") | |
466 | |
467 (defvar pages-buffer nil | |
468 "The buffer for which the pages-directory function creates the directory.") | |
469 | |
470 (defvar pages-directory-prefix "*Directory for:" | |
471 "Prefix of name of temporary buffer for pages-directory.") | |
472 | |
473 (defvar pages-pos-list nil | |
474 "List containing the positions of the pages in the pages-buffer.") | |
475 | |
46863
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
476 (defvar pages-target-buffer) |
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
477 |
235 | 478 (defvar pages-directory-map nil |
479 "Keymap for the pages-directory-buffer.") | |
480 | |
481 (if pages-directory-map | |
482 () | |
483 (setq pages-directory-map (make-sparse-keymap)) | |
484 (define-key pages-directory-map "\C-c\C-c" | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
485 'pages-directory-goto) |
23957
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
486 (define-key pages-directory-map "\C-c\C-p\C-a" 'add-new-page) |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
487 (define-key pages-directory-map [mouse-2] 'pages-directory-goto-with-mouse)) |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
488 |
6337
32cb5a7228ab
(original-page-delimiter, set-page-delimiter): Use printable escapes instead of
Karl Heuer <kwzh@gnu.org>
parents:
5311
diff
changeset
|
489 (defvar original-page-delimiter "^\f" |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
490 "Default page delimiter.") |
235 | 491 |
492 (defun set-page-delimiter (regexp reset-p) | |
493 "Set buffer local value of page-delimiter to REGEXP. | |
494 Called interactively with a prefix argument, reset `page-delimiter' to | |
495 its original value. | |
496 | |
497 In a program, non-nil second arg causes first arg to be ignored and | |
498 resets the page-delimiter to the original value." | |
499 | |
500 (interactive | |
501 (if current-prefix-arg | |
6337
32cb5a7228ab
(original-page-delimiter, set-page-delimiter): Use printable escapes instead of
Karl Heuer <kwzh@gnu.org>
parents:
5311
diff
changeset
|
502 (list original-page-delimiter "^\f") |
235 | 503 (list (read-string "Set page-delimiter to regexp: " page-delimiter) |
504 nil))) | |
505 (make-local-variable 'original-page-delimiter) | |
506 (make-local-variable 'page-delimiter) | |
507 (setq original-page-delimiter | |
508 (or original-page-delimiter page-delimiter)) | |
509 (if (not reset-p) | |
510 (setq page-delimiter regexp) | |
511 (setq page-delimiter original-page-delimiter)) | |
512 (if (interactive-p) | |
513 (message "The value of `page-delimiter' is now: %s" page-delimiter))) | |
514 | |
515 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
516 ;;; Pages directory main definitions |
235 | 517 |
518 (defun pages-directory | |
519 (pages-list-all-headers-p count-lines-p &optional regexp) | |
520 "Display a directory of the page headers in a temporary buffer. | |
521 A header is the first non-blank line after the page-delimiter. | |
522 \\[pages-directory-mode] | |
523 You may move point to one of the lines in the temporary buffer, | |
524 then use \\<pages-directory-goto> to go to the same line in the pages buffer. | |
525 | |
526 In interactive use: | |
527 | |
528 1. With no prefix arg, display all headers. | |
529 | |
530 2. With prefix arg, display the headers of only those pages that | |
531 contain matches to a regular expression for which you are | |
532 prompted. | |
533 | |
534 3. With numeric prefix arg, for every page, print the number of | |
535 lines within each page. | |
536 | |
537 4. With negative numeric prefix arg, for only those pages that | |
538 match a regular expression, print the number of lines within | |
539 each page. | |
540 | |
541 When called from a program, non-nil first arg means list all headers; | |
542 non-nil second arg means print numbers of lines in each page; if first | |
543 arg is nil, optional third arg is regular expression. | |
544 | |
545 If the buffer is narrowed, the `pages-directory' command creates a | |
546 directory for only the accessible portion of the buffer." | |
547 | |
548 (interactive | |
549 (cond ((not current-prefix-arg) | |
550 (list t nil nil)) | |
551 ((listp current-prefix-arg) | |
552 (list nil | |
553 nil | |
554 (read-string | |
555 (format "Select according to `%s' (end with RET): " | |
556 (or pages-directory-previous-regexp "regexp"))))) | |
557 ((> (prefix-numeric-value current-prefix-arg) 0) | |
558 (list t t nil)) | |
559 ((< (prefix-numeric-value current-prefix-arg) 0) | |
560 (list nil | |
561 t | |
562 (read-string | |
563 (format "Select according to `%s' (end with RET): " | |
564 (or pages-directory-previous-regexp "regexp"))))))) | |
565 | |
566 (if (equal regexp "") | |
567 (setq regexp pages-directory-previous-regexp) | |
568 (setq pages-directory-previous-regexp regexp)) | |
569 | |
570 (if (interactive-p) | |
571 (message "Creating directory for: %s " | |
572 (buffer-name))) | |
573 | |
46863
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
574 (let ((pages-target-buffer (current-buffer)) |
235 | 575 (pages-directory-buffer |
5311
da52825a3880
(pages-copy-header-and-position): Call end-of-line, not forward-line.
Richard M. Stallman <rms@gnu.org>
parents:
5021
diff
changeset
|
576 (concat pages-directory-prefix " " (buffer-name))) |
235 | 577 (linenum 1) |
578 (pages-buffer-original-position (point)) | |
579 (pages-buffer-original-page 0)) | |
580 | |
581 ;; `with-output-to-temp-buffer' binds the value of the variable | |
582 ;; `standard-output' to the buffer named as its first argument, | |
583 ;; but does not switch to that buffer. | |
584 (with-output-to-temp-buffer pages-directory-buffer | |
585 (save-excursion | |
586 (set-buffer standard-output) | |
587 (pages-directory-mode) | |
588 (insert | |
589 "==== Pages Directory: use `C-c C-c' to go to page under cursor. ====" ?\n) | |
46863
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
590 (setq pages-buffer pages-target-buffer) |
235 | 591 (setq pages-pos-list nil)) |
592 | |
593 (if pages-list-all-headers-p | |
594 | |
595 ;; 1. If no prefix argument, list all headers | |
596 (save-excursion | |
597 (goto-char (point-min)) | |
598 | |
599 ;; (a) Point is at beginning of buffer; but the first | |
600 ;; page may not begin with a page-delimiter | |
601 (save-restriction | |
602 ;; If page delimiter is at beginning of buffer, skip it | |
603 (if (and (save-excursion | |
604 (re-search-forward page-delimiter nil t)) | |
605 (= 1 (match-beginning 0))) | |
606 (goto-char (match-end 0))) | |
607 (narrow-to-page) | |
608 (pages-copy-header-and-position count-lines-p)) | |
609 | |
610 ;; (b) Search within pages buffer for next page-delimiter | |
611 (while (re-search-forward page-delimiter nil t) | |
612 (pages-copy-header-and-position count-lines-p))) | |
613 | |
614 ;; 2. Else list headers whose pages match regexp. | |
615 (save-excursion | |
616 ;; REMOVED save-restriction AND widen FROM HERE | |
617 (goto-char (point-min)) | |
618 | |
619 ;; (a) Handle first page | |
620 (save-restriction | |
621 (narrow-to-page) | |
622 ;; search for selection regexp | |
623 (if (save-excursion (re-search-forward regexp nil t)) | |
624 (pages-copy-header-and-position count-lines-p))) | |
625 | |
626 ;; (b) Search for next page-delimiter | |
627 (while (re-search-forward page-delimiter nil t) | |
628 (save-restriction | |
629 (narrow-to-page) | |
630 ;; search for selection regexp | |
631 (if (save-excursion (re-search-forward regexp nil t)) | |
632 (pages-copy-header-and-position count-lines-p) | |
633 ))))) | |
634 | |
635 (set-buffer standard-output) | |
636 ;; Put positions in increasing order to go with buffer. | |
637 (setq pages-pos-list (nreverse pages-pos-list)) | |
638 (if (interactive-p) | |
639 (message "%d matching lines in: %s" | |
46863
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
640 (length pages-pos-list) (buffer-name pages-target-buffer)))) |
235 | 641 (pop-to-buffer pages-directory-buffer) |
642 (sit-for 0) ; otherwise forward-line fails if N > window height. | |
643 (forward-line (if (= 0 pages-buffer-original-page) | |
644 1 | |
645 pages-buffer-original-page)))) | |
25329 | 646 (eval-when-compile |
647 (defvar pages-buffer-original-position) | |
648 (defvar pages-buffer-original-page) | |
649 (defvar pages-buffer-original-page)) | |
235 | 650 |
651 (defun pages-copy-header-and-position (count-lines-p) | |
652 "Copy page header and its position to the Pages Directory. | |
653 Only arg non-nil, count lines in page and insert before header. | |
654 Used by `pages-directory' function." | |
655 | |
656 (let (position line-count) | |
657 | |
658 (if count-lines-p | |
659 (save-excursion | |
660 (save-restriction | |
661 (narrow-to-page) | |
662 (setq line-count (count-lines (point-min) (point-max)))))) | |
663 | |
664 ;; Keep track of page for later cursor positioning | |
665 (if (<= (point) pages-buffer-original-position) | |
666 (setq pages-buffer-original-page | |
667 (1+ pages-buffer-original-page))) | |
668 | |
669 (save-excursion | |
670 ;; go to first non-blank char after the page-delimiter | |
671 (skip-chars-forward " \t\n") | |
672 ;; set the marker here; this the place to which the | |
673 ;; `pages-directory-goto' command will go | |
674 (setq position (make-marker)) | |
675 (set-marker position (point)) | |
676 (let ((start (point)) | |
23957
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
677 (end (save-excursion (end-of-line) (point))) |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
678 inserted-at) |
235 | 679 ;; change to directory buffer |
680 (set-buffer standard-output) | |
681 ;; record page position | |
682 (setq pages-pos-list (cons position pages-pos-list)) | |
683 ;; insert page header | |
23957
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
684 (setq inserted-at (point)) |
46863
28ae6b9b086e
(pages-target-buffer): Add defvar. Renamed from target-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
46847
diff
changeset
|
685 (insert-buffer-substring pages-target-buffer start end) |
38082
b1c18f0dd970
(pages-copy-header-and-position): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
25329
diff
changeset
|
686 (add-text-properties inserted-at (point) |
b1c18f0dd970
(pages-copy-header-and-position): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
25329
diff
changeset
|
687 '(mouse-face highlight |
b1c18f0dd970
(pages-copy-header-and-position): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents:
25329
diff
changeset
|
688 help-echo "mouse-2: go to this page")) |
23965 | 689 (put-text-property inserted-at (point) 'rear-nonsticky 'highlight)) |
235 | 690 |
691 (if count-lines-p | |
692 (save-excursion | |
693 (beginning-of-line) | |
694 (insert (format "%3d: " line-count)))) | |
695 | |
696 (terpri)) | |
5311
da52825a3880
(pages-copy-header-and-position): Call end-of-line, not forward-line.
Richard M. Stallman <rms@gnu.org>
parents:
5021
diff
changeset
|
697 (end-of-line 1))) |
235 | 698 |
46847
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
699 (defun pages-directory-mode () |
235 | 700 "Mode for handling the pages-directory buffer. |
701 | |
702 Move point to one of the lines in this buffer, then use \\[pages-directory-goto] to go | |
703 to the same line in the pages buffer." | |
46847
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
704 |
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
705 (kill-all-local-variables) |
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
706 (use-local-map pages-directory-map) |
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
707 (setq major-mode 'pages-directory-mode) |
b1f5929aa675
(pages-directory-mode): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
39895
diff
changeset
|
708 (setq mode-name "Pages-Directory") |
235 | 709 (make-local-variable 'pages-buffer) |
710 (make-local-variable 'pages-pos-list) | |
711 (make-local-variable 'pages-directory-buffer-narrowing-p)) | |
712 | |
713 (defun pages-directory-goto () | |
714 "Go to the corresponding line in the pages buffer." | |
715 | |
716 ;;; This function is mostly a copy of `occur-mode-goto-occurrence' | |
717 | |
718 (interactive) | |
719 (if (or (not pages-buffer) | |
720 (not (buffer-name pages-buffer))) | |
721 (progn | |
722 (setq pages-buffer nil | |
723 pages-pos-list nil) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38082
diff
changeset
|
724 (error "Buffer in which pages were found is deleted"))) |
235 | 725 (beginning-of-line) |
726 (let* ((pages-number (1- (count-lines (point-min) (point)))) | |
727 (pos (nth pages-number pages-pos-list)) | |
728 (end-of-directory-p (eobp)) | |
729 (narrowing-p pages-directory-buffer-narrowing-p)) | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
730 (pop-to-buffer pages-buffer) |
235 | 731 (widen) |
732 (if end-of-directory-p | |
733 (goto-char (point-max)) | |
734 (goto-char (marker-position pos))) | |
735 (if narrowing-p (narrow-to-page)))) | |
736 | |
23957
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
737 (defun pages-directory-goto-with-mouse (event) |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
738 "Go to the corresponding line under the mouse pointer in the pages buffer." |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
739 (interactive "e") |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
740 (save-excursion |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
741 (set-buffer (window-buffer (posn-window (event-end event)))) |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
742 (save-excursion |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
743 (goto-char (posn-point (event-end event))) |
71fe29ccef4c
Added mouse-selection feature for pages directory buffer.
Richard M. Stallman <rms@gnu.org>
parents:
17436
diff
changeset
|
744 (pages-directory-goto)))) |
235 | 745 |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
746 ;;; The `pages-directory-for-addresses' function and ancillary code |
235 | 747 |
748 (defun pages-directory-for-addresses (&optional filename) | |
749 "Find addresses file and display its directory. | |
750 By default, create and display directory of `pages-addresses-file-name'. | |
751 Optional argument is FILENAME. In interactive use, with prefix | |
752 argument, prompt for file name and provide completion. | |
753 | |
754 Move point to one of the lines in the displayed directory, | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
755 then use \\[pages-directory-goto] to go to the same line |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
756 in the addresses buffer. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
757 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
758 If pages-directory-for-addresses-goto-narrowing-p is non-nil, |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
759 `pages-directory-goto' narrows addresses buffer to entry. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
760 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
761 If pages-directory-for-addresses-buffer-keep-windows-p is nil, |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
762 this command deletes other windows when it displays the addresses |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
763 directory." |
235 | 764 |
765 (interactive | |
766 (list (if current-prefix-arg | |
767 (read-file-name "Filename: " pages-addresses-file-name)))) | |
768 | |
769 (if (interactive-p) | |
770 (message "Creating directory for: %s " | |
771 (or filename pages-addresses-file-name))) | |
772 (if (file-exists-p (or filename pages-addresses-file-name)) | |
773 (progn | |
774 (set-buffer | |
775 (find-file-noselect | |
776 (expand-file-name | |
777 (or filename pages-addresses-file-name)))) | |
778 (widen) | |
779 (pages-directory t nil nil) | |
780 (pages-directory-address-mode) | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
781 (setq pages-directory-buffer-narrowing-p |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
782 pages-directory-for-addresses-goto-narrowing-p) |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
783 (or pages-directory-for-addresses-buffer-keep-windows-p |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
784 (delete-other-windows)) |
235 | 785 (save-excursion |
786 (goto-char (point-min)) | |
787 (delete-region (point) (save-excursion (end-of-line) (point))) | |
788 (insert | |
789 "=== Address List Directory: use `C-c C-c' to go to page under cursor. ===") | |
790 (set-buffer-modified-p nil) | |
791 )) | |
792 (error "No addresses file found!"))) | |
793 | |
794 (defun pages-directory-address-mode () | |
795 "Mode for handling the Addresses Directory buffer. | |
796 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
797 Move point to one of the lines in this buffer, |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
798 then use \\[pages-directory-goto] to go |
235 | 799 to the same line in the pages buffer." |
800 | |
801 (use-local-map pages-directory-map) | |
802 (setq major-mode 'pages-directory-address-mode) | |
803 (setq mode-name "Addresses Directory") | |
804 (make-local-variable 'pages-buffer) | |
805 (make-local-variable 'pages-pos-list) | |
806 (make-local-variable 'pages-directory-buffer-narrowing-p)) | |
807 | |
5021
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
808 |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
809 ;;; Place `provide' at end of file. |
47afb35f4968
Revise documentation. Add `provide'.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
810 (provide 'page-ext) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
235
diff
changeset
|
811 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38082
diff
changeset
|
812 ;;; page-ext.el ends here |