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