660
|
1 ;;; informat.el --- info support functions package for Emacs
|
|
2
|
74442
|
3 ;; Copyright (C) 1986, 2001, 2002, 2003, 2004, 2005,
|
79721
|
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
|
846
|
5
|
807
|
6 ;; Maintainer: FSF
|
811
|
7 ;; Keywords: help
|
807
|
8
|
257
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
94678
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
257
|
12 ;; it under the terms of the GNU General Public License as published by
|
94678
|
13 ;; the Free Software Foundation, either version 3 of the License, or
|
|
14 ;; (at your option) any later version.
|
257
|
15
|
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 ;; GNU General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
94678
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
257
|
23
|
22693
|
24 ;;; Commentary:
|
|
25
|
|
26 ;; Nowadays, the Texinfo formatting commands always tagify a buffer
|
|
27 ;; (as does `makeinfo') since @anchor commands need tag tables.
|
|
28
|
807
|
29 ;;; Code:
|
|
30
|
257
|
31 (require 'info)
|
|
32
|
87111
|
33 (declare-function texinfo-format-refill "texinfmt" ())
|
86234
860a7a8e779e
* progmodes/octave-mod.el (inferior-octave-send-list-and-digest):
Dan Nicolaescu <dann@ics.uci.edu>
diff
changeset
|
34
|
257
|
35 ;;;###autoload
|
22693
|
36 (defun Info-tagify (&optional input-buffer-name)
|
|
37 "Create or update Info file tag table in current buffer or in a region."
|
257
|
38 (interactive)
|
|
39 ;; Save and restore point and restrictions.
|
|
40 ;; save-restrictions would not work
|
|
41 ;; because it records the old max relative to the end.
|
|
42 ;; We record it relative to the beginning.
|
22693
|
43 (if input-buffer-name
|
|
44 (message "Tagifying region in %s ..." input-buffer-name)
|
|
45 (message
|
|
46 "Tagifying %s ..." (file-name-nondirectory (buffer-file-name))))
|
257
|
47 (let ((omin (point-min))
|
|
48 (omax (point-max))
|
|
49 (nomax (= (point-max) (1+ (buffer-size))))
|
|
50 (opoint (point)))
|
|
51 (unwind-protect
|
22660
|
52 (progn
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
53 (widen)
|
22660
|
54 (goto-char (point-min))
|
|
55 (if (search-forward "\^_\nIndirect:\n" nil t)
|
22693
|
56 (message
|
|
57 "Cannot tagify split info file. Run this before splitting.")
|
22660
|
58 (let (tag-list
|
|
59 refillp
|
|
60 (case-fold-search t)
|
49597
|
61 (regexp
|
22660
|
62 (concat
|
|
63 "\\("
|
|
64
|
|
65
|
|
66 "\\("
|
|
67 "@anchor" ; match-string 2 matches @anchor
|
|
68 "\\)"
|
|
69 "\\(-no\\|-yes\\)" ; match-string 3 matches -no or -yes
|
|
70 "\\("
|
|
71 "-refill"
|
|
72 "\\)"
|
|
73
|
|
74 "\\("
|
|
75 "{"
|
|
76 "\\)"
|
|
77 "\\("
|
|
78 "[^}]+" ; match-string 6 matches arg to anchor
|
|
79 "\\)"
|
|
80 "\\("
|
|
81 "}"
|
|
82 "\\)"
|
|
83
|
|
84 "\\|"
|
|
85
|
|
86 "\\("
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
87 "\n\^_\\(\^L\\)?"
|
22660
|
88 "\\)"
|
|
89
|
|
90 "\\("
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
91 "\n\\(File:[ \t]*\\([^,\n\t]*\\)[,\t\n]+[ \t\n]*\\)?"
|
22660
|
92 "Node:[ \t]*"
|
|
93 "\\("
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
94 "[^,\n\t]*" ; match-string 13 matches arg to node name
|
22660
|
95 "\\)"
|
|
96 "[,\t\n]"
|
|
97 "\\)"
|
|
98
|
|
99 "\\)"
|
|
100 )))
|
|
101 (while (re-search-forward regexp nil t)
|
|
102 (if (string-equal "@anchor" (match-string 2))
|
|
103 (progn
|
|
104 ;; kludge lest lose match-data
|
|
105 (if (string-equal "-yes" (match-string 3))
|
|
106 (setq refillp t))
|
|
107 (setq tag-list
|
|
108 (cons (list
|
|
109 (concat "Ref: " (match-string 6))
|
|
110 (match-beginning 0))
|
|
111 tag-list))
|
|
112 (if (eq refillp t)
|
|
113 ;; set start and end so texinfo-format-refill works
|
|
114 (let ((texinfo-command-start (match-beginning 0))
|
|
115 (texinfo-command-end (match-end 0)))
|
|
116 (texinfo-format-refill))
|
|
117 (delete-region (match-beginning 0) (match-end 0))))
|
|
118 ;; else this is a Node
|
|
119 (setq tag-list
|
49597
|
120 (cons (list
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
121 (concat "Node: " (match-string-no-properties 13))
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
122 (1+ (match-beginning 10)))
|
22660
|
123 tag-list))))
|
|
124
|
257
|
125 (goto-char (point-max))
|
|
126 (forward-line -8)
|
|
127 (let ((buffer-read-only nil))
|
|
128 (if (search-forward "\^_\nEnd tag table\n" nil t)
|
|
129 (let ((end (point)))
|
|
130 (search-backward "\nTag table:\n")
|
|
131 (beginning-of-line)
|
|
132 (delete-region (point) end)))
|
|
133 (goto-char (point-max))
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
134 (or (bolp)
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
135 (newline))
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
136 (insert "\^_\f\nTag table:\n")
|
18137
985e47a14cab
(Info-tagify): Don't set Info-tag-table-marker if not in Info mode.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
137 (if (eq major-mode 'info-mode)
|
985e47a14cab
(Info-tagify): Don't set Info-tag-table-marker if not in Info mode.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
138 (move-marker Info-tag-table-marker (point)))
|
22660
|
139 (setq tag-list (nreverse tag-list))
|
|
140 (while tag-list
|
|
141 (insert (car (car tag-list)) ?\177)
|
22693
|
142 (princ (car (cdr (car tag-list))) (current-buffer))
|
257
|
143 (insert ?\n)
|
22660
|
144 (setq tag-list (cdr tag-list)))
|
257
|
145 (insert "\^_\nEnd tag table\n")))))
|
|
146 (goto-char opoint)
|
|
147 (narrow-to-region omin (if nomax (1+ (buffer-size))
|
|
148 (min omax (point-max))))))
|
22693
|
149 (if input-buffer-name
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
150 (message "Tagifying region in %s done" input-buffer-name)
|
22693
|
151 (message
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
152 "Tagifying %s done" (file-name-nondirectory (buffer-file-name)))))
|
22693
|
153
|
257
|
154
|
|
155 ;;;###autoload
|
98359
|
156 (defcustom Info-split-threshold 262144
|
|
157 "The number of characters by which `Info-split' splits an info file."
|
|
158 :type 'integer
|
|
159 :version "23.1"
|
|
160 :group 'texinfo)
|
|
161
|
|
162 ;;;###autoload
|
257
|
163 (defun Info-split ()
|
|
164 "Split an info file into an indirect file plus bounded-size subfiles.
|
98359
|
165 Each subfile will be up to the number of characters that
|
|
166 `Info-split-threshold' specifies, plus one node.
|
257
|
167
|
|
168 To use this command, first visit a large Info file that has a tag
|
|
169 table. The buffer is modified into a (small) indirect info file which
|
|
170 should be saved in place of the original visited file.
|
|
171
|
|
172 The subfiles are written in the same directory the original file is
|
|
173 in, with names generated by appending `-' and a number to the original
|
|
174 file name. The indirect file still functions as an Info file, but it
|
|
175 contains just the tag table and a directory of subfiles."
|
|
176
|
|
177 (interactive)
|
98359
|
178 (if (< (buffer-size) (+ 20000 Info-split-threshold))
|
257
|
179 (error "This is too small to be worth splitting"))
|
|
180 (goto-char (point-min))
|
|
181 (search-forward "\^_")
|
|
182 (forward-char -1)
|
|
183 (let ((start (point))
|
22693
|
184 (chars-deleted 0)
|
257
|
185 subfiles
|
|
186 (subfile-number 1)
|
|
187 (case-fold-search t)
|
|
188 (filename (file-name-sans-versions buffer-file-name)))
|
|
189 (goto-char (point-max))
|
|
190 (forward-line -8)
|
|
191 (setq buffer-read-only nil)
|
|
192 (or (search-forward "\^_\nEnd tag table\n" nil t)
|
|
193 (error "Tag table required; use M-x Info-tagify"))
|
|
194 (search-backward "\nTag table:\n")
|
|
195 (if (looking-at "\nTag table:\n\^_")
|
|
196 (error "Tag table is just a skeleton; use M-x Info-tagify"))
|
|
197 (beginning-of-line)
|
|
198 (forward-char 1)
|
|
199 (save-restriction
|
|
200 (narrow-to-region (point-min) (point))
|
|
201 (goto-char (point-min))
|
|
202 (while (< (1+ (point)) (point-max))
|
98359
|
203 (goto-char (min (+ (point) Info-split-threshold) (point-max)))
|
257
|
204 (search-forward "\^_" nil 'move)
|
|
205 (setq subfiles
|
22693
|
206 (cons (list (+ start chars-deleted)
|
257
|
207 (concat (file-name-nondirectory filename)
|
|
208 (format "-%d" subfile-number)))
|
|
209 subfiles))
|
|
210 ;; Put a newline at end of split file, to make Unix happier.
|
|
211 (insert "\n")
|
|
212 (write-region (point-min) (point)
|
|
213 (concat filename (format "-%d" subfile-number)))
|
|
214 (delete-region (1- (point)) (point))
|
|
215 ;; Back up over the final ^_.
|
|
216 (forward-char -1)
|
22693
|
217 (setq chars-deleted (+ chars-deleted (- (point) start)))
|
257
|
218 (delete-region start (point))
|
|
219 (setq subfile-number (1+ subfile-number))))
|
|
220 (while subfiles
|
|
221 (goto-char start)
|
|
222 (insert (nth 1 (car subfiles))
|
10156
|
223 (format ": %d" (1- (car (car subfiles))))
|
257
|
224 "\n")
|
|
225 (setq subfiles (cdr subfiles)))
|
|
226 (goto-char start)
|
|
227 (insert "\^_\nIndirect:\n")
|
|
228 (search-forward "\nTag Table:\n")
|
|
229 (insert "(Indirect)\n")))
|
|
230
|
18422
|
231 (defvar Info-validate-allnodes)
|
|
232 (defvar Info-validate-thisnode)
|
|
233 (defvar Info-validate-lossages)
|
|
234
|
257
|
235 ;;;###autoload
|
|
236 (defun Info-validate ()
|
|
237 "Check current buffer for validity as an Info file.
|
|
238 Check that every node pointer points to an existing node."
|
|
239 (interactive)
|
|
240 (save-excursion
|
|
241 (save-restriction
|
|
242 (widen)
|
|
243 (goto-char (point-min))
|
|
244 (if (search-forward "\nTag table:\n(Indirect)\n" nil t)
|
|
245 (error "Don't yet know how to validate indirect info files: \"%s\""
|
|
246 (buffer-name (current-buffer))))
|
|
247 (goto-char (point-min))
|
18422
|
248 (let ((Info-validate-allnodes '(("*")))
|
257
|
249 (regexp "Node:[ \t]*\\([^,\n\t]*\\)[,\t\n]")
|
|
250 (case-fold-search t)
|
|
251 (tags-losing nil)
|
18422
|
252 (Info-validate-lossages ()))
|
257
|
253 (while (search-forward "\n\^_" nil t)
|
|
254 (forward-line 1)
|
|
255 (let ((beg (point)))
|
|
256 (forward-line 1)
|
|
257 (if (re-search-backward regexp beg t)
|
|
258 (let ((name (downcase
|
18422
|
259 (buffer-substring-no-properties
|
|
260 (match-beginning 1)
|
|
261 (progn
|
|
262 (goto-char (match-end 1))
|
|
263 (skip-chars-backward " \t")
|
|
264 (point))))))
|
|
265 (if (assoc name Info-validate-allnodes)
|
|
266 (setq Info-validate-lossages
|
257
|
267 (cons (list name "Duplicate node-name" nil)
|
18422
|
268 Info-validate-lossages))
|
|
269 (setq Info-validate-allnodes
|
|
270 (cons (list name
|
|
271 (progn
|
|
272 (end-of-line)
|
|
273 (and (re-search-backward
|
|
274 "prev[ious]*:" beg t)
|
|
275 (progn
|
|
276 (goto-char (match-end 0))
|
|
277 (downcase
|
|
278 (Info-following-node-name)))))
|
|
279 beg)
|
|
280 Info-validate-allnodes)))))))
|
257
|
281 (goto-char (point-min))
|
|
282 (while (search-forward "\n\^_" nil t)
|
|
283 (forward-line 1)
|
|
284 (let ((beg (point))
|
18422
|
285 Info-validate-thisnode next)
|
257
|
286 (forward-line 1)
|
|
287 (if (re-search-backward regexp beg t)
|
|
288 (save-restriction
|
25427
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
289 (let ((md (match-data)))
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
290 (search-forward "\n\^_" nil 'move)
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
291 (narrow-to-region beg (point))
|
dde5fcbfa2af
(Info-tagify): Don't insert more than one newline before the tag table.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
292 (set-match-data md))
|
18422
|
293 (setq Info-validate-thisnode (downcase
|
|
294 (buffer-substring-no-properties
|
|
295 (match-beginning 1)
|
|
296 (progn
|
|
297 (goto-char (match-end 1))
|
|
298 (skip-chars-backward " \t")
|
|
299 (point)))))
|
257
|
300 (end-of-line)
|
|
301 (and (search-backward "next:" nil t)
|
|
302 (setq next (Info-validate-node-name "invalid Next"))
|
18422
|
303 (assoc next Info-validate-allnodes)
|
|
304 (if (equal (car (cdr (assoc next Info-validate-allnodes)))
|
|
305 Info-validate-thisnode)
|
257
|
306 ;; allow multiple `next' pointers to one node
|
18422
|
307 (let ((tem Info-validate-lossages))
|
257
|
308 (while tem
|
|
309 (if (and (equal (car (cdr (car tem)))
|
|
310 "should have Previous")
|
|
311 (equal (car (car tem))
|
|
312 next))
|
18422
|
313 (setq Info-validate-lossages
|
|
314 (delq (car tem) Info-validate-lossages)))
|
257
|
315 (setq tem (cdr tem))))
|
18422
|
316 (setq Info-validate-lossages
|
257
|
317 (cons (list next
|
|
318 "should have Previous"
|
18422
|
319 Info-validate-thisnode)
|
|
320 Info-validate-lossages))))
|
257
|
321 (end-of-line)
|
|
322 (if (re-search-backward "prev[ious]*:" nil t)
|
|
323 (Info-validate-node-name "invalid Previous"))
|
|
324 (end-of-line)
|
|
325 (if (search-backward "up:" nil t)
|
|
326 (Info-validate-node-name "invalid Up"))
|
|
327 (if (re-search-forward "\n* Menu:" nil t)
|
|
328 (while (re-search-forward "\n\\* " nil t)
|
|
329 (Info-validate-node-name
|
18422
|
330 (concat "invalid menu item "
|
|
331 (buffer-substring (point)
|
|
332 (save-excursion
|
|
333 (skip-chars-forward "^:")
|
|
334 (point))))
|
|
335 (Info-extract-menu-node-name))))
|
257
|
336 (goto-char (point-min))
|
|
337 (while (re-search-forward "\\*note[ \n]*[^:\t]*:" nil t)
|
|
338 (goto-char (+ (match-beginning 0) 5))
|
|
339 (skip-chars-forward " \n")
|
|
340 (Info-validate-node-name
|
|
341 (concat "invalid reference "
|
|
342 (buffer-substring (point)
|
|
343 (save-excursion
|
|
344 (skip-chars-forward "^:")
|
|
345 (point))))
|
|
346 (Info-extract-menu-node-name "Bad format cross-reference")))))))
|
|
347 (setq tags-losing (not (Info-validate-tags-table)))
|
18422
|
348 (if (or Info-validate-lossages tags-losing)
|
257
|
349 (with-output-to-temp-buffer " *problems in info file*"
|
18422
|
350 (while Info-validate-lossages
|
257
|
351 (princ "In node \"")
|
18422
|
352 (princ (car (car Info-validate-lossages)))
|
257
|
353 (princ "\", ")
|
18422
|
354 (let ((tem (nth 1 (car Info-validate-lossages))))
|
257
|
355 (cond ((string-match "\n" tem)
|
|
356 (princ (substring tem 0 (match-beginning 0)))
|
|
357 (princ "..."))
|
|
358 (t
|
|
359 (princ tem))))
|
18422
|
360 (if (nth 2 (car Info-validate-lossages))
|
257
|
361 (progn
|
|
362 (princ ": ")
|
18422
|
363 (let ((tem (nth 2 (car Info-validate-lossages))))
|
257
|
364 (cond ((string-match "\n" tem)
|
|
365 (princ (substring tem 0 (match-beginning 0)))
|
|
366 (princ "..."))
|
|
367 (t
|
|
368 (princ tem))))))
|
|
369 (terpri)
|
18422
|
370 (setq Info-validate-lossages (cdr Info-validate-lossages)))
|
257
|
371 (if tags-losing (princ "\nTags table must be recomputed\n")))
|
|
372 ;; Here if info file is valid.
|
|
373 ;; If we already made a list of problems, clear it out.
|
|
374 (save-excursion
|
|
375 (if (get-buffer " *problems in info file*")
|
|
376 (progn
|
|
377 (set-buffer " *problems in info file*")
|
|
378 (kill-buffer (current-buffer)))))
|
|
379 (message "File appears valid"))))))
|
|
380
|
|
381 (defun Info-validate-node-name (kind &optional name)
|
|
382 (if name
|
|
383 nil
|
|
384 (goto-char (match-end 0))
|
|
385 (skip-chars-forward " \t")
|
|
386 (if (= (following-char) ?\()
|
|
387 nil
|
|
388 (setq name
|
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
389 (buffer-substring-no-properties
|
257
|
390 (point)
|
|
391 (progn
|
18422
|
392 (skip-chars-forward "^,\t\n")
|
|
393 (skip-chars-backward " ")
|
|
394 (point))))))
|
257
|
395 (if (null name)
|
|
396 nil
|
|
397 (setq name (downcase name))
|
|
398 (or (and (> (length name) 0) (= (aref name 0) ?\())
|
18422
|
399 (assoc name Info-validate-allnodes)
|
|
400 (setq Info-validate-lossages
|
|
401 (cons (list Info-validate-thisnode kind name)
|
|
402 Info-validate-lossages))))
|
257
|
403 name)
|
|
404
|
|
405 (defun Info-validate-tags-table ()
|
|
406 (goto-char (point-min))
|
|
407 (if (not (search-forward "\^_\nEnd tag table\n" nil t))
|
|
408 t
|
|
409 (not (catch 'losing
|
|
410 (let* ((end (match-beginning 0))
|
|
411 (start (progn (search-backward "\nTag table:\n")
|
|
412 (1- (match-end 0))))
|
|
413 tem)
|
18422
|
414 (setq tem Info-validate-allnodes)
|
257
|
415 (while tem
|
|
416 (goto-char start)
|
|
417 (or (equal (car (car tem)) "*")
|
|
418 (search-forward (concat "Node: "
|
|
419 (car (car tem))
|
|
420 "\177")
|
|
421 end t)
|
|
422 (throw 'losing 'x))
|
|
423 (setq tem (cdr tem)))
|
|
424 (goto-char (1+ start))
|
|
425 (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>
diff
changeset
|
426 (setq tem (downcase (buffer-substring-no-properties
|
257
|
427 (match-beginning 1)
|
|
428 (match-end 1))))
|
18422
|
429 (setq tem (assoc tem Info-validate-allnodes))
|
257
|
430 (if (or (not tem)
|
|
431 (< 1000 (progn
|
|
432 (goto-char (match-beginning 2))
|
|
433 (setq tem (- (car (cdr (cdr tem)))
|
|
434 (read (current-buffer))))
|
|
435 (if (> tem 0) tem (- tem)))))
|
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
436 (throw 'losing 'y))
|
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
437 (forward-line 1)))
|
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
438 (if (looking-at "\^_\n")
|
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
439 (forward-line 1))
|
257
|
440 (or (looking-at "End tag table\n")
|
|
441 (throw 'losing 'z))
|
|
442 nil))))
|
|
443
|
|
444 ;;;###autoload
|
|
445 (defun batch-info-validate ()
|
|
446 "Runs `Info-validate' on the files remaining on the command line.
|
|
447 Must be used only with -batch, and kills Emacs on completion.
|
|
448 Each file will be processed even if an error occurred previously.
|
|
449 For example, invoke \"emacs -batch -f batch-info-validate $info/ ~/*.info\""
|
|
450 (if (not noninteractive)
|
38412
|
451 (error "batch-info-validate may only be used -batch"))
|
257
|
452 (let ((version-control t)
|
|
453 (auto-save-default nil)
|
|
454 (find-file-run-dired nil)
|
|
455 (kept-old-versions 259259)
|
|
456 (kept-new-versions 259259))
|
|
457 (let ((error 0)
|
|
458 file
|
|
459 (files ()))
|
|
460 (while command-line-args-left
|
|
461 (setq file (expand-file-name (car command-line-args-left)))
|
|
462 (cond ((not (file-exists-p file))
|
|
463 (message ">> %s does not exist!" file)
|
|
464 (setq error 1
|
49597
|
465 command-line-args-left (cdr command-line-args-left)))
|
257
|
466 ((file-directory-p file)
|
|
467 (setq command-line-args-left (nconc (directory-files file)
|
|
468 (cdr command-line-args-left))))
|
|
469 (t
|
|
470 (setq files (cons file files)
|
|
471 command-line-args-left (cdr command-line-args-left)))))
|
|
472 (while files
|
|
473 (setq file (car files)
|
|
474 files (cdr files))
|
|
475 (let ((lose nil))
|
|
476 (condition-case err
|
|
477 (progn
|
|
478 (if buffer-file-name (kill-buffer (current-buffer)))
|
|
479 (find-file file)
|
|
480 (buffer-disable-undo (current-buffer))
|
|
481 (set-buffer-modified-p nil)
|
|
482 (fundamental-mode)
|
|
483 (let ((case-fold-search nil))
|
|
484 (goto-char (point-max))
|
|
485 (cond ((search-backward "\n\^_\^L\nTag table:\n" nil t)
|
|
486 (message "%s already tagified" file))
|
|
487 ((< (point-max) 30000)
|
|
488 (message "%s too small to bother tagifying" file))
|
|
489 (t
|
923
|
490 (Info-tagify))))
|
257
|
491 (let ((loss-name " *problems in info file*"))
|
|
492 (message "Checking validity of info file %s..." file)
|
|
493 (if (get-buffer loss-name)
|
|
494 (kill-buffer loss-name))
|
|
495 (Info-validate)
|
|
496 (if (not (get-buffer loss-name))
|
|
497 nil ;(message "Checking validity of info file %s... OK" file)
|
|
498 (message "----------------------------------------------------------------------")
|
|
499 (message ">> PROBLEMS IN INFO FILE %s" file)
|
|
500 (save-excursion
|
|
501 (set-buffer loss-name)
|
13291
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
502 (princ (buffer-substring-no-properties
|
49de0d4ca42e
(Info-validate, Info-validate-node-name): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
503 (point-min) (point-max))))
|
257
|
504 (message "----------------------------------------------------------------------")
|
|
505 (setq error 1 lose t)))
|
|
506 (if (and (buffer-modified-p)
|
|
507 (not lose))
|
|
508 (progn (message "Saving modified %s" file)
|
|
509 (save-buffer))))
|
|
510 (error (message ">> Error: %s" (prin1-to-string err))))))
|
|
511 (kill-emacs error))))
|
660
|
512
|
18383
|
513 (provide 'informat)
|
|
514
|
93975
|
515 ;; arch-tag: 581c440e-5be1-4f31-b005-2d5824bbf569
|
660
|
516 ;;; informat.el ends here
|