Mercurial > emacs
annotate lisp/informat.el @ 14117:50df7ee940e8
(makefile-space-face): Don't work on
facemenu-unlisted-faces if it isn't bound.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 09 Jan 1996 23:19:17 +0000 |
parents | 49de0d4ca42e |
children | 83f275dcd93a |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
1 ;;; informat.el --- info support functions package for Emacs |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: help |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
7 |
257 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
257 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
24 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
25 |
257 | 26 (require 'info) |
27 | |
28 ;;;###autoload | |
29 (defun Info-tagify () | |
30 "Create or update Info-file tag table in current buffer." | |
31 (interactive) | |
32 ;; Save and restore point and restrictions. | |
33 ;; save-restrictions would not work | |
34 ;; because it records the old max relative to the end. | |
35 ;; We record it relative to the beginning. | |
36 (message "Tagifying %s ..." (file-name-nondirectory (buffer-file-name))) | |
37 (let ((omin (point-min)) | |
38 (omax (point-max)) | |
39 (nomax (= (point-max) (1+ (buffer-size)))) | |
40 (opoint (point))) | |
41 (unwind-protect | |
42 (progn | |
43 (widen) | |
44 (goto-char (point-min)) | |
45 (if (search-forward "\^_\nIndirect:\n" nil t) | |
46 (message "Cannot tagify split info file") | |
1880
36ec0bfbb2c2
* informat.el (Info-tagify): Correct the regular expression which
Jim Blandy <jimb@redhat.com>
parents:
923
diff
changeset
|
47 (let ((regexp "Node:[ \t]*\\([^,\n\t]*\\)[,\t\n]") |
257 | 48 (case-fold-search t) |
49 list) | |
50 (while (search-forward "\n\^_" nil t) | |
10154
a864b7f97b56
(Info-tagify): Avoid 1-off error in position of a tag.
Richard M. Stallman <rms@gnu.org>
parents:
1880
diff
changeset
|
51 ;; We want the 0-origin character position of the ^_. |
a864b7f97b56
(Info-tagify): Avoid 1-off error in position of a tag.
Richard M. Stallman <rms@gnu.org>
parents:
1880
diff
changeset
|
52 ;; That is the same as the Emacs (1-origin) position |
a864b7f97b56
(Info-tagify): Avoid 1-off error in position of a tag.
Richard M. Stallman <rms@gnu.org>
parents:
1880
diff
changeset
|
53 ;; of the newline before it. |
a864b7f97b56
(Info-tagify): Avoid 1-off error in position of a tag.
Richard M. Stallman <rms@gnu.org>
parents:
1880
diff
changeset
|
54 (let ((beg (match-beginning 0))) |
a864b7f97b56
(Info-tagify): Avoid 1-off error in position of a tag.
Richard M. Stallman <rms@gnu.org>
parents:
1880
diff
changeset
|
55 (forward-line 2) |
257 | 56 (if (re-search-backward regexp beg t) |
57 (setq list | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
58 (cons (list (buffer-substring-no-properties |
257 | 59 (match-beginning 1) |
60 (match-end 1)) | |
61 beg) | |
62 list))))) | |
63 (goto-char (point-max)) | |
64 (forward-line -8) | |
65 (let ((buffer-read-only nil)) | |
66 (if (search-forward "\^_\nEnd tag table\n" nil t) | |
67 (let ((end (point))) | |
68 (search-backward "\nTag table:\n") | |
69 (beginning-of-line) | |
70 (delete-region (point) end))) | |
71 (goto-char (point-max)) | |
72 (insert "\^_\f\nTag table:\n") | |
73 (move-marker Info-tag-table-marker (point)) | |
74 (setq list (nreverse list)) | |
75 (while list | |
76 (insert "Node: " (car (car list)) ?\177) | |
77 (princ (car (cdr (car list))) (current-buffer)) | |
78 (insert ?\n) | |
79 (setq list (cdr list))) | |
80 (insert "\^_\nEnd tag table\n"))))) | |
81 (goto-char opoint) | |
82 (narrow-to-region omin (if nomax (1+ (buffer-size)) | |
83 (min omax (point-max)))))) | |
84 (message "Tagifying %s ... done" (file-name-nondirectory (buffer-file-name)))) | |
85 | |
86 ;;;###autoload | |
87 (defun Info-split () | |
88 "Split an info file into an indirect file plus bounded-size subfiles. | |
89 Each subfile will be up to 50,000 characters plus one node. | |
90 | |
91 To use this command, first visit a large Info file that has a tag | |
92 table. The buffer is modified into a (small) indirect info file which | |
93 should be saved in place of the original visited file. | |
94 | |
95 The subfiles are written in the same directory the original file is | |
96 in, with names generated by appending `-' and a number to the original | |
97 file name. The indirect file still functions as an Info file, but it | |
98 contains just the tag table and a directory of subfiles." | |
99 | |
100 (interactive) | |
101 (if (< (buffer-size) 70000) | |
102 (error "This is too small to be worth splitting")) | |
103 (goto-char (point-min)) | |
104 (search-forward "\^_") | |
105 (forward-char -1) | |
106 (let ((start (point)) | |
107 (chars-deleted 0) | |
108 subfiles | |
109 (subfile-number 1) | |
110 (case-fold-search t) | |
111 (filename (file-name-sans-versions buffer-file-name))) | |
112 (goto-char (point-max)) | |
113 (forward-line -8) | |
114 (setq buffer-read-only nil) | |
115 (or (search-forward "\^_\nEnd tag table\n" nil t) | |
116 (error "Tag table required; use M-x Info-tagify")) | |
117 (search-backward "\nTag table:\n") | |
118 (if (looking-at "\nTag table:\n\^_") | |
119 (error "Tag table is just a skeleton; use M-x Info-tagify")) | |
120 (beginning-of-line) | |
121 (forward-char 1) | |
122 (save-restriction | |
123 (narrow-to-region (point-min) (point)) | |
124 (goto-char (point-min)) | |
125 (while (< (1+ (point)) (point-max)) | |
126 (goto-char (min (+ (point) 50000) (point-max))) | |
127 (search-forward "\^_" nil 'move) | |
128 (setq subfiles | |
129 (cons (list (+ start chars-deleted) | |
130 (concat (file-name-nondirectory filename) | |
131 (format "-%d" subfile-number))) | |
132 subfiles)) | |
133 ;; Put a newline at end of split file, to make Unix happier. | |
134 (insert "\n") | |
135 (write-region (point-min) (point) | |
136 (concat filename (format "-%d" subfile-number))) | |
137 (delete-region (1- (point)) (point)) | |
138 ;; Back up over the final ^_. | |
139 (forward-char -1) | |
140 (setq chars-deleted (+ chars-deleted (- (point) start))) | |
141 (delete-region start (point)) | |
142 (setq subfile-number (1+ subfile-number)))) | |
143 (while subfiles | |
144 (goto-char start) | |
145 (insert (nth 1 (car subfiles)) | |
10156
baf3b68f7e56
(Info-split): Fix 1-off error in subfile position.
Richard M. Stallman <rms@gnu.org>
parents:
10154
diff
changeset
|
146 (format ": %d" (1- (car (car subfiles)))) |
257 | 147 "\n") |
148 (setq subfiles (cdr subfiles))) | |
149 (goto-char start) | |
150 (insert "\^_\nIndirect:\n") | |
151 (search-forward "\nTag Table:\n") | |
152 (insert "(Indirect)\n"))) | |
153 | |
154 ;;;###autoload | |
155 (defun Info-validate () | |
156 "Check current buffer for validity as an Info file. | |
157 Check that every node pointer points to an existing node." | |
158 (interactive) | |
159 (save-excursion | |
160 (save-restriction | |
161 (widen) | |
162 (goto-char (point-min)) | |
163 (if (search-forward "\nTag table:\n(Indirect)\n" nil t) | |
164 (error "Don't yet know how to validate indirect info files: \"%s\"" | |
165 (buffer-name (current-buffer)))) | |
166 (goto-char (point-min)) | |
167 (let ((allnodes '(("*"))) | |
168 (regexp "Node:[ \t]*\\([^,\n\t]*\\)[,\t\n]") | |
169 (case-fold-search t) | |
170 (tags-losing nil) | |
171 (lossages ())) | |
172 (while (search-forward "\n\^_" nil t) | |
173 (forward-line 1) | |
174 (let ((beg (point))) | |
175 (forward-line 1) | |
176 (if (re-search-backward regexp beg t) | |
177 (let ((name (downcase | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
178 (buffer-substring-no-properties |
257 | 179 (match-beginning 1) |
180 (progn | |
181 (goto-char (match-end 1)) | |
182 (skip-chars-backward " \t") | |
183 (point)))))) | |
184 (if (assoc name allnodes) | |
185 (setq lossages | |
186 (cons (list name "Duplicate node-name" nil) | |
187 lossages)) | |
188 (setq allnodes | |
189 (cons (list name | |
190 (progn | |
191 (end-of-line) | |
192 (and (re-search-backward | |
193 "prev[ious]*:" beg t) | |
194 (progn | |
195 (goto-char (match-end 0)) | |
196 (downcase | |
197 (Info-following-node-name))))) | |
198 beg) | |
199 allnodes))))))) | |
200 (goto-char (point-min)) | |
201 (while (search-forward "\n\^_" nil t) | |
202 (forward-line 1) | |
203 (let ((beg (point)) | |
204 thisnode next) | |
205 (forward-line 1) | |
206 (if (re-search-backward regexp beg t) | |
207 (save-restriction | |
208 (search-forward "\n\^_" nil 'move) | |
209 (narrow-to-region beg (point)) | |
210 (setq thisnode (downcase | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
211 (buffer-substring-no-properties |
257 | 212 (match-beginning 1) |
213 (progn | |
214 (goto-char (match-end 1)) | |
215 (skip-chars-backward " \t") | |
216 (point))))) | |
217 (end-of-line) | |
218 (and (search-backward "next:" nil t) | |
219 (setq next (Info-validate-node-name "invalid Next")) | |
220 (assoc next allnodes) | |
221 (if (equal (car (cdr (assoc next allnodes))) | |
222 thisnode) | |
223 ;; allow multiple `next' pointers to one node | |
224 (let ((tem lossages)) | |
225 (while tem | |
226 (if (and (equal (car (cdr (car tem))) | |
227 "should have Previous") | |
228 (equal (car (car tem)) | |
229 next)) | |
230 (setq lossages (delq (car tem) lossages))) | |
231 (setq tem (cdr tem)))) | |
232 (setq lossages | |
233 (cons (list next | |
234 "should have Previous" | |
235 thisnode) | |
236 lossages)))) | |
237 (end-of-line) | |
238 (if (re-search-backward "prev[ious]*:" nil t) | |
239 (Info-validate-node-name "invalid Previous")) | |
240 (end-of-line) | |
241 (if (search-backward "up:" nil t) | |
242 (Info-validate-node-name "invalid Up")) | |
243 (if (re-search-forward "\n* Menu:" nil t) | |
244 (while (re-search-forward "\n\\* " nil t) | |
245 (Info-validate-node-name | |
246 (concat "invalid menu item " | |
247 (buffer-substring (point) | |
248 (save-excursion | |
249 (skip-chars-forward "^:") | |
250 (point)))) | |
251 (Info-extract-menu-node-name)))) | |
252 (goto-char (point-min)) | |
253 (while (re-search-forward "\\*note[ \n]*[^:\t]*:" nil t) | |
254 (goto-char (+ (match-beginning 0) 5)) | |
255 (skip-chars-forward " \n") | |
256 (Info-validate-node-name | |
257 (concat "invalid reference " | |
258 (buffer-substring (point) | |
259 (save-excursion | |
260 (skip-chars-forward "^:") | |
261 (point)))) | |
262 (Info-extract-menu-node-name "Bad format cross-reference"))))))) | |
263 (setq tags-losing (not (Info-validate-tags-table))) | |
264 (if (or lossages tags-losing) | |
265 (with-output-to-temp-buffer " *problems in info file*" | |
266 (while lossages | |
267 (princ "In node \"") | |
268 (princ (car (car lossages))) | |
269 (princ "\", ") | |
270 (let ((tem (nth 1 (car lossages)))) | |
271 (cond ((string-match "\n" tem) | |
272 (princ (substring tem 0 (match-beginning 0))) | |
273 (princ "...")) | |
274 (t | |
275 (princ tem)))) | |
276 (if (nth 2 (car lossages)) | |
277 (progn | |
278 (princ ": ") | |
279 (let ((tem (nth 2 (car lossages)))) | |
280 (cond ((string-match "\n" tem) | |
281 (princ (substring tem 0 (match-beginning 0))) | |
282 (princ "...")) | |
283 (t | |
284 (princ tem)))))) | |
285 (terpri) | |
286 (setq lossages (cdr lossages))) | |
287 (if tags-losing (princ "\nTags table must be recomputed\n"))) | |
288 ;; Here if info file is valid. | |
289 ;; If we already made a list of problems, clear it out. | |
290 (save-excursion | |
291 (if (get-buffer " *problems in info file*") | |
292 (progn | |
293 (set-buffer " *problems in info file*") | |
294 (kill-buffer (current-buffer))))) | |
295 (message "File appears valid")))))) | |
296 | |
297 (defun Info-validate-node-name (kind &optional name) | |
298 (if name | |
299 nil | |
300 (goto-char (match-end 0)) | |
301 (skip-chars-forward " \t") | |
302 (if (= (following-char) ?\() | |
303 nil | |
304 (setq name | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
305 (buffer-substring-no-properties |
257 | 306 (point) |
307 (progn | |
308 (skip-chars-forward "^,\t\n") | |
309 (skip-chars-backward " ") | |
310 (point)))))) | |
311 (if (null name) | |
312 nil | |
313 (setq name (downcase name)) | |
314 (or (and (> (length name) 0) (= (aref name 0) ?\()) | |
315 (assoc name allnodes) | |
316 (setq lossages | |
317 (cons (list thisnode kind name) lossages)))) | |
318 name) | |
319 | |
320 (defun Info-validate-tags-table () | |
321 (goto-char (point-min)) | |
322 (if (not (search-forward "\^_\nEnd tag table\n" nil t)) | |
323 t | |
324 (not (catch 'losing | |
325 (let* ((end (match-beginning 0)) | |
326 (start (progn (search-backward "\nTag table:\n") | |
327 (1- (match-end 0)))) | |
328 tem) | |
329 (setq tem allnodes) | |
330 (while tem | |
331 (goto-char start) | |
332 (or (equal (car (car tem)) "*") | |
333 (search-forward (concat "Node: " | |
334 (car (car tem)) | |
335 "\177") | |
336 end t) | |
337 (throw 'losing 'x)) | |
338 (setq tem (cdr tem))) | |
339 (goto-char (1+ start)) | |
340 (while (looking-at ".*Node: \\(.*\\)\177\\([0-9]+\\)$") | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
341 (setq tem (downcase (buffer-substring-no-properties |
257 | 342 (match-beginning 1) |
343 (match-end 1)))) | |
344 (setq tem (assoc tem allnodes)) | |
345 (if (or (not tem) | |
346 (< 1000 (progn | |
347 (goto-char (match-beginning 2)) | |
348 (setq tem (- (car (cdr (cdr tem))) | |
349 (read (current-buffer)))) | |
350 (if (> tem 0) tem (- tem))))) | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
351 (throw 'losing 'y)) |
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
352 (forward-line 1))) |
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
353 (if (looking-at "\^_\n") |
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
354 (forward-line 1)) |
257 | 355 (or (looking-at "End tag table\n") |
356 (throw 'losing 'z)) | |
357 nil)))) | |
358 | |
359 ;;;###autoload | |
360 (defun batch-info-validate () | |
361 "Runs `Info-validate' on the files remaining on the command line. | |
362 Must be used only with -batch, and kills Emacs on completion. | |
363 Each file will be processed even if an error occurred previously. | |
364 For example, invoke \"emacs -batch -f batch-info-validate $info/ ~/*.info\"" | |
365 (if (not noninteractive) | |
366 (error "batch-info-validate may only be used -batch.")) | |
367 (let ((version-control t) | |
368 (auto-save-default nil) | |
369 (find-file-run-dired nil) | |
370 (kept-old-versions 259259) | |
371 (kept-new-versions 259259)) | |
372 (let ((error 0) | |
373 file | |
374 (files ())) | |
375 (while command-line-args-left | |
376 (setq file (expand-file-name (car command-line-args-left))) | |
377 (cond ((not (file-exists-p file)) | |
378 (message ">> %s does not exist!" file) | |
379 (setq error 1 | |
380 command-line-args-left (cdr command-line-args-left))) | |
381 ((file-directory-p file) | |
382 (setq command-line-args-left (nconc (directory-files file) | |
383 (cdr command-line-args-left)))) | |
384 (t | |
385 (setq files (cons file files) | |
386 command-line-args-left (cdr command-line-args-left))))) | |
387 (while files | |
388 (setq file (car files) | |
389 files (cdr files)) | |
390 (let ((lose nil)) | |
391 (condition-case err | |
392 (progn | |
393 (if buffer-file-name (kill-buffer (current-buffer))) | |
394 (find-file file) | |
395 (buffer-disable-undo (current-buffer)) | |
396 (set-buffer-modified-p nil) | |
397 (fundamental-mode) | |
398 (let ((case-fold-search nil)) | |
399 (goto-char (point-max)) | |
400 (cond ((search-backward "\n\^_\^L\nTag table:\n" nil t) | |
401 (message "%s already tagified" file)) | |
402 ((< (point-max) 30000) | |
403 (message "%s too small to bother tagifying" file)) | |
404 (t | |
923 | 405 (Info-tagify)))) |
257 | 406 (let ((loss-name " *problems in info file*")) |
407 (message "Checking validity of info file %s..." file) | |
408 (if (get-buffer loss-name) | |
409 (kill-buffer loss-name)) | |
410 (Info-validate) | |
411 (if (not (get-buffer loss-name)) | |
412 nil ;(message "Checking validity of info file %s... OK" file) | |
413 (message "----------------------------------------------------------------------") | |
414 (message ">> PROBLEMS IN INFO FILE %s" file) | |
415 (save-excursion | |
416 (set-buffer loss-name) | |
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
417 (princ (buffer-substring-no-properties |
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10156
diff
changeset
|
418 (point-min) (point-max)))) |
257 | 419 (message "----------------------------------------------------------------------") |
420 (setq error 1 lose t))) | |
421 (if (and (buffer-modified-p) | |
422 (not lose)) | |
423 (progn (message "Saving modified %s" file) | |
424 (save-buffer)))) | |
425 (error (message ">> Error: %s" (prin1-to-string err)))))) | |
426 (kill-emacs error)))) | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
427 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
428 ;;; informat.el ends here |