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