annotate lisp/packages/page-ext.el @ 0:376386a54a3c r19-14

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