annotate lisp/informat.el @ 22084:08f31e440c92

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