annotate lisp/info-xref.el @ 50076:a3f6f7daf7e3

*** empty log message ***
author John Paul Wallington <jpw@pobox.com>
date Mon, 10 Mar 2003 13:30:22 +0000
parents f3c2ee28113b
children 695cf19ef79e d7ddb3e565de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
1 ;;; info-xref.el --- check external references in an Info document.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
2
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
3 ;; Copyright 2003 Free Software Foundation, Inc
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
4 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
5 ;; Author: Kevin Ryde <user42@zip.com.au>
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
6 ;; Keywords: docs
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
7 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
8 ;; info-xref.el is free software; you can redistribute it and/or modify
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by the
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
10 ;; Free Software Foundation; either version 2, or (at your option) any later
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
11 ;; version.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
12 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
13 ;; info-xref.el is distributed in the hope that it will be useful, but
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
16 ;; Public License for more details.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
17 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
18 ;; You can get a copy of the GNU General Public License online at
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
19 ;; http://www.gnu.org/licenses/gpl.txt, or you should have one in the file
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
20 ;; COPYING which comes with GNU Emacs and other GNU programs. Failing that,
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
21 ;; write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
23
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
24
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
26
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
27 ;; This file implements some simple checking of external cross references in
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
28 ;; info files, by attempting to visit the nodes specified.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
29 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
30 ;; "makeinfo" checks references internal to a document, but not external
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
31 ;; references, which makes it rather easy for mistakes to creep in or node
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
32 ;; name changes to go unnoticed. `Info-validate' doesn't check external
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
33 ;; references either.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
34 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
35 ;; `M-x info-xref-check' checks one file. When invoked from an Info-mode or
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
36 ;; texinfo-mode buffer, the current info file is the default at the prompt.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
37 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
38 ;; `M-x info-xref-check-all' looks at everything in the normal info path.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
39 ;; This might be a lot of files but it's a good way to check the consistency
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
40 ;; of the whole system.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
41 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
42 ;; Results are shown in a buffer. The format is a bit rough, but hopefully
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
43 ;; there won't be too many problems normally, and correcting them is a
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
44 ;; manual process anyway, a case of finding the right spot in the original
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
45 ;; .texi and finding what node it ought to point to.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
46 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
47 ;; When a target info file doesn't exist there's clearly no way to validate
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
48 ;; node references within it. A message is given for missing target files
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
49 ;; (once per source document), it could be simply that the target hasn't
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
50 ;; been installed, or it could be a mistake in the reference.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
51 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
52 ;; Indirect info files are understood, just pass the top-level foo.info to
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
53 ;; `info-xref-check' and it traverses all sub-files. Compressed info files
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
54 ;; are accepted too, as usual for `Info-mode'.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
55 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
56 ;; `info-xref-check-all' is rather permissive in what it considers an info
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
57 ;; file. It has to be since info files don't necessarily have a ".info"
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
58 ;; suffix (eg. this is usual for the emacs manuals). One consequence of
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
59 ;; this is that if for instance there's a source code directory in
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
60 ;; `Info-directory-list' then a lot of extraneous files might be read, which
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
61 ;; will be time consuming but should be harmless.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
62
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
63
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
64 ;;; Install:
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
65
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
66 ;; Put info-xref.el somewhere in your `load-path', and in your .emacs put
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
67 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
68 ;; (autoload 'info-xref-check "info-xref" nil t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
69 ;; (autoload 'info-xref-check-all "info-xref" nil t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
70 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
71 ;; then
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
72 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
73 ;; M-x info-xref-check
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
74 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
75 ;; and enter an info file name.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
76
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
77
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
78 ;;; Emacsen:
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
79
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
80 ;; Designed for use with GNU Emacs 21.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
81
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
82
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
83 ;;; History:
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
84
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
85 ;; Version 1 - the first version.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
86
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
87
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
88 ;;; Code:
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
89
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
90 (require 'info)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
91
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
92 (defconst info-xref-results-buffer "*info-xref results*"
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
93 "Name of the buffer for info-xref results.")
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
94
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
95 ;;;###autoload
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
96 (defun info-xref-check (filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
97 "Check external references in FILENAME, an info document."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
98 (interactive
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
99 (list
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
100 (let* ((default-filename
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
101 (cond ((eq major-mode 'Info-mode)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
102 Info-current-file)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
103 ((eq major-mode 'texinfo-mode)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
104 ;; look for @setfilename like makeinfo.el does
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
105 (save-excursion
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
106 (goto-char (point-min))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
107 (if (re-search-forward
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
108 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*"
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
109 (line-beginning-position 100) t)
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
110 (expand-file-name (match-string 1)))))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
111 (prompt (if default-filename
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
112 (format "Info file (%s): " default-filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
113 "Info file: ")))
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
114 (read-file-name prompt nil default-filename t))))
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
115 (info-xref-check-list (list filename)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
116
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
117 ;;;###autoload
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
118 (defun info-xref-check-all ()
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
119 "Check external references in all info documents in the usual path.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
120 The usual path is `Info-directory-list' and `Info-additional-directory-list'."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
121 (interactive)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
122 (info-xref-check-list (info-xref-all-info-files)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
123
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
124 ;; An alternative to trying to get only top-level files here would be to
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
125 ;; simply return all files, and have info-xref-check-list not follow
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
126 ;; Indirect:. The current way seems a bit nicer though, because it gets the
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
127 ;; proper top-level filename into the error messages, and suppresses
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
128 ;; duplicate "not available" messages for all subfiles of a single document.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
129
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
130 (defun info-xref-all-info-files ()
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
131 "Return a list of all available info files.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
132 Only top-level files are returned, subfiles are excluded.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
133
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
134 Since info files don't have to have a .info suffix, all files in the
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
135 relevant directories are considered, which might mean a lot of extraneous
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
136 things are returned if for instance a source code directory is in the path."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
137
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
138 (info-initialize) ;; establish Info-directory-list
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
139 (apply 'nconc
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
140 (mapcar
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
141 (lambda (dir)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
142 (let ((result nil))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
143 (dolist (name (directory-files dir t))
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
144 (unless (or (file-directory-p name) (info-xref-subfile-p name))
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
145 (push name result)))
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
146 (nreverse result)))
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
147 (append Info-directory-list Info-additional-directory-list))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
148
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
149 (defun info-xref-subfile-p (filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
150 "Return t if FILENAME is an info subfile.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
151 If removing the last \"-<NUM>\" from the filename gives a file that exists,
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
152 then consider FILENAME a subfile. This is an imperfect test, we probably
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
153 should open up the purported top file and see what subfiles it says."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
154 (and (string-match "\\`\\(\\([^-]*-\\)*[^-]*\\)-[0-9]+\\(.*\\)\\'" filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
155 (file-exists-p (concat (match-string 1 filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
156 (match-string 3 filename)))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
157
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
158
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
159 ;; Some dynamic variables are used to share information with sub-functions
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
160 ;; below.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
161 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
162 ;; info-xref-filename - current top-level filename, eg. /usr/info/foo.info.gz
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
163 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
164 ;; info-xref-filename-header - a heading message for the current top-level
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
165 ;; filename, or "" when it's been printed.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
166 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
167 ;; info-xref-good - count of good cross references.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
168 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
169 ;; info-xref-bad - count of bad cross references.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
170 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
171 ;; info-xref-xfile-alist - indexed by "(foo)" with value nil or t according
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
172 ;; to whether "(foo)" exists or not. This is used to suppress duplicate
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
173 ;; messages about foo not being available. (Duplicates within one
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
174 ;; top-level file that is.)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
175
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
176 (defun info-xref-check-list (filename-list)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
177 "Check external references in info documents in FILENAME-LIST."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
178 (pop-to-buffer info-xref-results-buffer t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
179 (erase-buffer)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
180 (let ((info-xref-good 0)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
181 (info-xref-bad 0))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
182 (dolist (info-xref-filename filename-list)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
183 (let ((info-xref-filename-heading
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
184 (format "In file %s:\n" info-xref-filename))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
185 (info-xref-xfile-alist nil))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
186 (with-temp-message (format "Looking at %s" info-xref-filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
187 (with-temp-buffer
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
188 (info-insert-file-contents info-xref-filename)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
189 (goto-char (point-min))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
190 (if (re-search-forward "\^_\nIndirect:\n" nil t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
191 (let ((dir (file-name-directory info-xref-filename)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
192 (while (looking-at "\\(.*\\): [0-9]+\n")
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
193 (let ((subfile (match-string 1)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
194 (with-temp-buffer
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
195 (info-insert-file-contents
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
196 (expand-file-name subfile dir))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
197 (info-xref-check-buffer)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
198 (forward-line)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
199 (info-xref-check-buffer))))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
200 (insert (format "done, %d good, %d bad\n" info-xref-good info-xref-bad))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
201
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
202 (defun info-xref-check-buffer ()
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
203 "Check external references in the info file in the current buffer.
49717
ecb17cef5c44 (info-xref-check-buffer): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 49698
diff changeset
204 This should be the raw file contents, not `Info-mode'."
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
205 (goto-char (point-min))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
206 (while (re-search-forward
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
207 "\\*[Nn]ote[ \n\t]+[^:]*:[ \n\t]+\\(\\(([^)]+)\\)[^.,]+\\)[.,]"
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
208 nil t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
209 (let* ((file (match-string 2))
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
210 (node ;; Canonicalize spaces: we could use "[\t\n ]+" but
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
211 ;; we try to avoid uselessly replacing " " with " ".
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
212 (replace-regexp-in-string "[\t\n][\t\n ]*\\| [\t\n ]+" " "
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
213 (match-string 1) t t)))
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
214 ;; see if the file exists, if we haven't tried it before
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
215 (unless (assoc file info-xref-xfile-alist)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
216 (let ((found (info-xref-goto-node-p file)))
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
217 (push (cons file found) info-xref-xfile-alist)
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
218 (unless found
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
219 (info-xref-output (format "Not available to check: %s\n" file)))))
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
220 ;; if the file exists, try the node, if we haven't before
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
221 (when (cdr (assoc file info-xref-xfile-alist))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
222 (unless (assoc node info-xref-xfile-alist)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
223 (if (info-xref-goto-node-p node)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
224 (setq info-xref-good (1+ info-xref-good))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
225 (setq info-xref-bad (1+ info-xref-bad))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
226 (info-xref-output (format "No such node: %s\n" node))))))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
227
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
228 (defun info-xref-output (str)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
229 "Emit STR as an info-xref result message."
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
230 (with-current-buffer info-xref-results-buffer
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
231 (insert info-xref-filename-heading str)
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
232 (setq info-xref-filename-heading "")))
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
233
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
234 ;; When asking Info-goto-node to fork, *info* needs to be the current
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
235 ;; buffer, otherwise it seems to clone the current buffer but then do the
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
236 ;; goto-node in plain *info*.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
237 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
238 ;; We only fork if *info* already exists, if it doesn't then we can create
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
239 ;; and destroy just that instead of a new name.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
240 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
241 ;; If Info-goto-node can't find the file, then no new buffer is created. If
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
242 ;; it finds the file but not the node, then a buffer is created. Handle
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
243 ;; this difference by checking before killing.
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
244 ;;
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
245 (defun info-xref-goto-node-p (node)
49729
f3c2ee28113b (info-xref-check): Use line-beginning-position.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 49717
diff changeset
246 "Return t if it's possible to go to the given NODE."
49698
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
247 (let ((oldbuf (current-buffer)))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
248 (save-excursion
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
249 (save-window-excursion
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
250 (prog1
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
251 (condition-case err
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
252 (progn
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
253 (Info-goto-node node
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
254 (when (get-buffer "*info*")
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
255 (set-buffer "*info*")
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
256 "xref - temporary"))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
257 t)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
258 (error nil))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
259 (unless (equal (current-buffer) oldbuf)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
260 (kill-buffer (current-buffer))))))))
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
261
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
262 (provide 'info-xref)
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
263
a208a118a3d8 Initial revision
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
264 ;;; info-xref.el ends here