Commit | Line | Data |
---|---|---|
e3431643 | 1 | ;;; info.el --- info package for Emacs. |
e5167999 | 2 | |
5b907c5e | 3 | ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99 Free Software |
3ec18f3f | 4 | ;; Foundation, Inc. |
3a801d0c | 5 | |
e5167999 | 6 | ;; Maintainer: FSF |
fd7fa35a | 7 | ;; Keywords: help |
e5167999 | 8 | |
a384cab3 JB |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
e5167999 | 13 | ;; the Free Software Foundation; either version 2, or (at your option) |
a384cab3 JB |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
a384cab3 | 25 | |
e5167999 ER |
26 | ;;; Commentary: |
27 | ||
b578f267 | 28 | ;; Note that nowadays we expect info files to be made using makeinfo. |
e5167999 ER |
29 | |
30 | ;;; Code: | |
31 | ||
bc6262c8 DL |
32 | (eval-when-compile (require 'jka-compr)) |
33 | ||
ded3e3d8 RS |
34 | (defgroup info nil |
35 | "Info subsystem" | |
36 | :group 'help | |
37 | :group 'docs) | |
38 | ||
39 | ||
a384cab3 JB |
40 | (defvar Info-history nil |
41 | "List of info nodes user has visited. | |
42 | Each element of list is a list (FILENAME NODENAME BUFFERPOS).") | |
43 | ||
ded3e3d8 | 44 | (defcustom Info-enable-edit nil |
d5913bf6 | 45 | "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node. |
ada0a60d RS |
46 | This is convenient if you want to write info files by hand. |
47 | However, we recommend that you not do this. | |
48 | It is better to write a Texinfo file and generate the Info file from that, | |
ded3e3d8 RS |
49 | because that gives you a printed manual as well." |
50 | :type 'boolean | |
51 | :group 'info) | |
a384cab3 | 52 | |
67f445d7 | 53 | (defvar Info-enable-active-nodes nil |
a384cab3 JB |
54 | "Non-nil allows Info to execute Lisp code associated with nodes. |
55 | The Lisp code is executed when the node is selected.") | |
67f445d7 | 56 | (put 'Info-enable-active-nodes 'risky-local-variable t) |
a384cab3 | 57 | |
ded3e3d8 RS |
58 | (defcustom Info-fontify t |
59 | "*Non-nil enables highlighting and fonts in Info nodes." | |
60 | :type 'boolean | |
61 | :group 'info) | |
552775bd | 62 | |
93480d70 | 63 | (defface info-node |
7a3abcd8 EZ |
64 | '((((class color)) (:foreground "brown" :bold t :italic t)) |
65 | (t (:bold t :italic t))) | |
93480d70 RS |
66 | "Face for Info node names." |
67 | :group 'info) | |
68 | ||
69 | (defface info-menu-5 | |
7a3abcd8 EZ |
70 | '((((class color)) (:foreground "red1")) |
71 | (t (:underline t))) | |
93480d70 RS |
72 | "Face for the fifth and tenth `*' in an Info menu." |
73 | :group 'info) | |
74 | ||
75 | (defface info-xref | |
7a3abcd8 EZ |
76 | '((((class color)) (:foreground "magenta4" :bold t)) |
77 | (t (:bold t))) | |
93480d70 RS |
78 | "Face for Info cross-references." |
79 | :group 'info) | |
80 | ||
88ef7f62 | 81 | (defcustom Info-fontify-maximum-menu-size 100000 |
ded3e3d8 RS |
82 | "*Maximum size of menu to fontify if `Info-fontify' is non-nil." |
83 | :type 'integer | |
84 | :group 'info) | |
bdf62a4d | 85 | |
7d3766a8 | 86 | (defvar Info-directory-list nil |
a384cab3 | 87 | "List of directories to search for Info documentation files. |
aea2a8da | 88 | nil means not yet initialized. In this case, Info uses the environment |
44c327f9 | 89 | variable INFOPATH to initialize it, or `Info-default-directory-list' |
e5bd2125 RS |
90 | if there is no INFOPATH variable in the environment. |
91 | The last element of `Info-default-directory-list' is the directory | |
5c11086b | 92 | where Emacs installs the Info files that come with it. |
5da0f945 RS |
93 | |
94 | If you run the Emacs executable from the `src' directory in the Emacs | |
95 | source tree, the `info' directory in the source tree is used as the last | |
96 | element, in place of the installation Info directory. This is useful | |
97 | when you run a version of Emacs without installing it.") | |
a384cab3 | 98 | |
ded3e3d8 | 99 | (defcustom Info-additional-directory-list nil |
bdf62a4d | 100 | "List of additional directories to search for Info documentation files. |
ded3e3d8 RS |
101 | These directories are not searched for merging the `dir' file." |
102 | :type '(repeat directory) | |
103 | :group 'info) | |
bdf62a4d | 104 | |
a384cab3 | 105 | (defvar Info-current-file nil |
d6be34f3 RS |
106 | "Info file that Info is now looking at, or nil. |
107 | This is the name that was specified in Info, not the actual file name. | |
4fceda3c SM |
108 | It doesn't contain directory names or file name extensions added by Info. |
109 | Can also be t when using `Info-on-current-buffer'.") | |
a384cab3 JB |
110 | |
111 | (defvar Info-current-subfile nil | |
112 | "Info subfile that is actually in the *info* buffer now, | |
113 | or nil if current info file is not split into subfiles.") | |
114 | ||
115 | (defvar Info-current-node nil | |
116 | "Name of node that Info is now looking at, or nil.") | |
117 | ||
c5fe2ff1 | 118 | (defvar Info-tag-table-marker nil |
a384cab3 JB |
119 | "Marker pointing at beginning of current Info file's tag table. |
120 | Marker points nowhere if file has no tag table.") | |
121 | ||
c5fe2ff1 RS |
122 | (defvar Info-tag-table-buffer nil |
123 | "Buffer used for indirect tag tables.") | |
124 | ||
552775bd RS |
125 | (defvar Info-current-file-completions nil |
126 | "Cached completion list for current Info file.") | |
127 | ||
1143a6b0 ER |
128 | (defvar Info-index-alternatives nil |
129 | "List of possible matches for last Info-index command.") | |
130 | ||
552775bd RS |
131 | (defvar Info-standalone nil |
132 | "Non-nil if Emacs was started solely as an Info browser.") | |
7d3766a8 | 133 | \f |
bd0c9168 | 134 | (defvar Info-suffix-list |
3c19e6c1 RS |
135 | ;; The MS-DOS list should work both when long file names are |
136 | ;; supported (Windows 9X), and when only 8+3 file names are available. | |
bd0c9168 RS |
137 | (if (eq system-type 'ms-dos) |
138 | '( (".gz" . "gunzip") | |
139 | (".z" . "gunzip") | |
76dc74a2 | 140 | (".bz2" . "bzip2 -dc") |
3c19e6c1 RS |
141 | (".inz" . "gunzip") |
142 | (".igz" . "gunzip") | |
143 | (".info.Z" . "gunzip") | |
144 | (".info.gz" . "gunzip") | |
145 | ("-info.Z" . "gunzip") | |
146 | ("-info.gz" . "gunzip") | |
147 | ("/index.gz". "gunzip") | |
148 | ("/index.z" . "gunzip") | |
9b842cab | 149 | (".inf" . nil) |
3c19e6c1 RS |
150 | (".info" . nil) |
151 | ("-info" . nil) | |
152 | ("/index" . nil) | |
bd0c9168 | 153 | ("" . nil)) |
a70dc410 RS |
154 | '( (".info.Z". "uncompress") |
155 | (".info.Y". "unyabba") | |
156 | (".info.gz". "gunzip") | |
157 | (".info.z". "gunzip") | |
bc6262c8 | 158 | (".info.bz2" . "bzip2 -dc") |
a70dc410 RS |
159 | (".info". nil) |
160 | ("-info.Z". "uncompress") | |
161 | ("-info.Y". "unyabba") | |
162 | ("-info.gz". "gunzip") | |
bc6262c8 | 163 | ("-info.bz2" . "bzip2 -dc") |
a70dc410 RS |
164 | ("-info.z". "gunzip") |
165 | ("-info". nil) | |
166 | ("/index.Z". "uncompress") | |
167 | ("/index.Y". "unyabba") | |
168 | ("/index.gz". "gunzip") | |
169 | ("/index.z". "gunzip") | |
bc6262c8 | 170 | ("/index.bz2". "bzip2 -dc") |
a70dc410 RS |
171 | ("/index". nil) |
172 | (".Z". "uncompress") | |
173 | (".Y". "unyabba") | |
174 | (".gz". "gunzip") | |
175 | (".z". "gunzip") | |
bc6262c8 | 176 | (".bz2" . "bzip2 -dc") |
a70dc410 | 177 | ("". nil))) |
1143a6b0 ER |
178 | "List of file name suffixes and associated decoding commands. |
179 | Each entry should be (SUFFIX . STRING); the file is given to | |
97f99202 KH |
180 | the command as standard input. If STRING is nil, no decoding is done. |
181 | Because the SUFFIXes are tried in order, the empty string should | |
182 | be last in the list.") | |
1143a6b0 | 183 | |
c8e9dd54 | 184 | ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot. |
bd0c9168 RS |
185 | ;; First, on ms-dos, delete some of the extension in FILENAME |
186 | ;; to make room. | |
187 | (defun info-insert-file-contents-1 (filename suffix) | |
188 | (if (not (eq system-type 'ms-dos)) | |
189 | (concat filename suffix) | |
190 | (let* ((sans-exts (file-name-sans-extension filename)) | |
c8e9dd54 RS |
191 | ;; How long is the extension in FILENAME (not counting the dot). |
192 | (ext-len (max 0 (- (length filename) (length sans-exts) 1))) | |
193 | ext-left) | |
9b842cab | 194 | ;; SUFFIX starts with a dot. If FILENAME already has one, |
1583fe94 | 195 | ;; get rid of the one in SUFFIX (unless suffix is empty). |
c8e9dd54 | 196 | (or (and (<= ext-len 0) |
9b842cab | 197 | (not (eq (aref filename (1- (length filename))) ?.))) |
1583fe94 | 198 | (= (length suffix) 0) |
9b842cab | 199 | (setq suffix (substring suffix 1))) |
c8e9dd54 RS |
200 | ;; How many chars of that extension should we keep? |
201 | (setq ext-left (min ext-len (max 0 (- 3 (length suffix))))) | |
bd0c9168 RS |
202 | ;; Get rid of the rest of the extension, and add SUFFIX. |
203 | (concat (substring filename 0 (- (length filename) | |
204 | (- ext-len ext-left))) | |
205 | suffix)))) | |
206 | ||
9c7924d5 RS |
207 | (defun info-file-exists-p (filename) |
208 | (and (file-exists-p filename) | |
209 | (not (file-directory-p filename)))) | |
210 | ||
1143a6b0 ER |
211 | (defun info-insert-file-contents (filename &optional visit) |
212 | "Insert the contents of an info file in the current buffer. | |
213 | Do the right thing if the file has been compressed or zipped." | |
97f99202 KH |
214 | (let ((tail Info-suffix-list) |
215 | fullname decoder) | |
216 | (if (file-exists-p filename) | |
bd0c9168 RS |
217 | ;; FILENAME exists--see if that name contains a suffix. |
218 | ;; If so, set DECODE accordingly. | |
97f99202 KH |
219 | (progn |
220 | (while (and tail | |
221 | (not (string-match | |
222 | (concat (regexp-quote (car (car tail))) "$") | |
223 | filename))) | |
224 | (setq tail (cdr tail))) | |
225 | (setq fullname filename | |
226 | decoder (cdr (car tail)))) | |
bd0c9168 | 227 | ;; Try adding suffixes to FILENAME and see if we can find something. |
97f99202 | 228 | (while (and tail |
9c7924d5 RS |
229 | (not (info-file-exists-p (info-insert-file-contents-1 |
230 | filename (car (car tail)))))) | |
97f99202 | 231 | (setq tail (cdr tail))) |
bd0c9168 RS |
232 | ;; If we found a file with a suffix, set DECODER according to the suffix |
233 | ;; and set FULLNAME to the file's actual name. | |
9b842cab | 234 | (setq fullname (info-insert-file-contents-1 filename (car (car tail))) |
97f99202 KH |
235 | decoder (cdr (car tail))) |
236 | (or tail | |
bd0c9168 | 237 | (error "Can't find %s or any compressed version of it" filename))) |
e175bda2 RS |
238 | ;; check for conflict with jka-compr |
239 | (if (and (featurep 'jka-compr) | |
240 | (jka-compr-installed-p) | |
241 | (jka-compr-get-compression-info fullname)) | |
242 | (setq decoder nil)) | |
97f99202 | 243 | (if decoder |
3c19e6c1 RS |
244 | (progn |
245 | (insert-file-contents-literally fullname visit) | |
246 | (let ((buffer-read-only nil) | |
247 | (coding-system-for-write 'no-conversion) | |
248 | (default-directory (or (file-name-directory fullname) | |
249 | default-directory))) | |
250 | (call-process-region (point-min) (point-max) decoder t t))) | |
251 | (insert-file-contents fullname visit)))) | |
7d3766a8 RS |
252 | \f |
253 | ;; Initialize Info-directory-list, if that hasn't been done yet. | |
254 | (defun info-initialize () | |
255 | (unless Info-directory-list | |
256 | (let ((path (getenv "INFOPATH")) | |
257 | (source (expand-file-name "info/" source-directory)) | |
258 | (sibling (if installation-directory | |
259 | (expand-file-name "info/" installation-directory))) | |
260 | alternative) | |
261 | (setq Info-directory-list | |
262 | (if path | |
263 | (split-string path (regexp-quote path-separator)) | |
264 | (if (and sibling (file-exists-p sibling)) | |
265 | ;; Uninstalled, Emacs builddir != srcdir. | |
266 | (setq alternative sibling) | |
267 | ;; Uninstalled, builddir == srcdir | |
268 | (setq alternative source)) | |
269 | (if (or (member alternative Info-default-directory-list) | |
7d3766a8 RS |
270 | ;; On DOS/NT, we use movable executables always, |
271 | ;; and we must always find the Info dir at run time. | |
272 | (if (memq system-type '(ms-dos windows-nt)) | |
273 | nil | |
274 | ;; Use invocation-directory for Info | |
275 | ;; only if we used it for exec-directory also. | |
276 | (not (string= exec-directory | |
277 | (expand-file-name "lib-src/" | |
9eb53591 PR |
278 | installation-directory)))) |
279 | (not (file-exists-p alternative))) | |
7d3766a8 RS |
280 | Info-default-directory-list |
281 | ;; `alternative' contains the Info files that came with this | |
282 | ;; version, so we should look there first. `Info-insert-dir' | |
283 | ;; currently expects to find `alternative' first on the list. | |
284 | (cons alternative | |
285 | (reverse (cdr (reverse Info-default-directory-list)))))))))) | |
1143a6b0 | 286 | |
a6e4564e RS |
287 | ;;;###autoload |
288 | (defun info-other-window (&optional file) | |
289 | "Like `info' but show the Info buffer in another window." | |
290 | (interactive (if current-prefix-arg | |
291 | (list (read-file-name "Info file name: " nil nil t)))) | |
292 | (let (same-window-buffer-names) | |
293 | (info file))) | |
294 | ||
d282974b | 295 | ;;;###autoload (add-hook 'same-window-buffer-names "*info*") |
211d6309 | 296 | |
a384cab3 JB |
297 | ;;;###autoload |
298 | (defun info (&optional file) | |
299 | "Enter Info, the documentation browser. | |
300 | Optional argument FILE specifies the file to examine; | |
301 | the default is the top-level directory of Info. | |
83d5c772 DL |
302 | Called from a program, FILE may specify an Info node of the form |
303 | `(FILENAME)NODENAME'. | |
a384cab3 JB |
304 | |
305 | In interactive use, a prefix argument directs this command | |
e341dab2 RS |
306 | to read a file name from the minibuffer. |
307 | ||
308 | The search path for Info files is in the variable `Info-directory-list'. | |
309 | The top-level Info directory is made by combining all the files named `dir' | |
310 | in all the directories in that path." | |
a384cab3 JB |
311 | (interactive (if current-prefix-arg |
312 | (list (read-file-name "Info file name: " nil nil t)))) | |
a384cab3 | 313 | (if file |
c613e27e KH |
314 | (progn |
315 | (pop-to-buffer "*info*") | |
316 | ;; If argument already contains parentheses, don't add another set | |
317 | ;; since the argument will then be parsed improperly. This also | |
318 | ;; has the added benefit of allowing node names to be included | |
319 | ;; following the parenthesized filename. | |
320 | (if (and (stringp file) (string-match "(.*)" file)) | |
321 | (Info-goto-node file) | |
322 | (Info-goto-node (concat "(" file ")")))) | |
35d2d241 RS |
323 | (if (get-buffer "*info*") |
324 | (pop-to-buffer "*info*") | |
325 | (Info-directory)))) | |
a384cab3 | 326 | |
552775bd RS |
327 | ;;;###autoload |
328 | (defun info-standalone () | |
329 | "Run Emacs as a standalone Info reader. | |
330 | Usage: emacs -f info-standalone [filename] | |
331 | In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself." | |
332 | (setq Info-standalone t) | |
333 | (if (and command-line-args-left | |
334 | (not (string-match "^-" (car command-line-args-left)))) | |
335 | (condition-case err | |
336 | (progn | |
337 | (info (car command-line-args-left)) | |
338 | (setq command-line-args-left (cdr command-line-args-left))) | |
339 | (error (send-string-to-terminal | |
340 | (format "%s\n" (if (eq (car-safe err) 'error) | |
341 | (nth 1 err) err))) | |
342 | (save-buffers-kill-emacs))) | |
343 | (info))) | |
7d3766a8 | 344 | \f |
11638562 EZ |
345 | ;; See if the the accessible portion of the buffer begins with a node |
346 | ;; delimiter, and the node header line which follows matches REGEXP. | |
347 | ;; Typically, this test will be followed by a loop that examines the | |
348 | ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity | |
349 | ;; to have the overhead of this special test inside the loop. | |
350 | ||
351 | ;; This function changes match-data, but supposedly the caller might | |
352 | ;; want to use the results of re-search-backward. | |
353 | ||
354 | ;; The return value is the value of point at the beginning of matching | |
355 | ;; REGERXP, if the function succeeds, nil otherwise. | |
356 | (defun Info-node-at-bob-matching (regexp) | |
357 | (and (bobp) ; are we at beginning of buffer? | |
358 | (looking-at "\^_") ; does it begin with node delimiter? | |
359 | (let (beg) | |
360 | (forward-line 1) | |
361 | (setq beg (point)) | |
362 | (forward-line 1) ; does the line after delimiter match REGEXP? | |
363 | (re-search-backward regexp beg t)))) | |
364 | ||
a384cab3 JB |
365 | ;; Go to an info node specified as separate filename and nodename. |
366 | ;; no-going-back is non-nil if recovering from an error in this function; | |
367 | ;; it says do not attempt further (recursive) error recovery. | |
368 | (defun Info-find-node (filename nodename &optional no-going-back) | |
d0e41cba | 369 | (info-initialize) |
a384cab3 JB |
370 | ;; Convert filename to lower case if not found as specified. |
371 | ;; Expand it. | |
4fceda3c | 372 | (if (stringp filename) |
a384cab3 | 373 | (let (temp temp-downcase found) |
37a3ff5b RS |
374 | (setq filename (substitute-in-file-name filename)) |
375 | (if (string= (downcase filename) "dir") | |
376 | (setq found t) | |
377 | (let ((dirs (if (string-match "^\\./" filename) | |
378 | ;; If specified name starts with `./' | |
379 | ;; then just try current directory. | |
380 | '("./") | |
381 | (if (file-name-absolute-p filename) | |
382 | ;; No point in searching for an | |
383 | ;; absolute file name | |
384 | '(nil) | |
385 | (if Info-additional-directory-list | |
386 | (append Info-directory-list | |
387 | Info-additional-directory-list) | |
388 | Info-directory-list))))) | |
389 | ;; Search the directory list for file FILENAME. | |
390 | (while (and dirs (not found)) | |
391 | (setq temp (expand-file-name filename (car dirs))) | |
392 | (setq temp-downcase | |
393 | (expand-file-name (downcase filename) (car dirs))) | |
394 | ;; Try several variants of specified name. | |
395 | (let ((suffix-list Info-suffix-list)) | |
396 | (while (and suffix-list (not found)) | |
397 | (cond ((info-file-exists-p | |
398 | (info-insert-file-contents-1 | |
399 | temp (car (car suffix-list)))) | |
400 | (setq found temp)) | |
401 | ((info-file-exists-p | |
402 | (info-insert-file-contents-1 | |
403 | temp-downcase (car (car suffix-list)))) | |
404 | (setq found temp-downcase))) | |
405 | (setq suffix-list (cdr suffix-list)))) | |
406 | (setq dirs (cdr dirs))))) | |
407 | (if found | |
408 | (setq filename found) | |
409 | (error "Info file %s does not exist" filename)))) | |
410 | ;; Record the node we are leaving. | |
411 | (if (and Info-current-file (not no-going-back)) | |
412 | (setq Info-history | |
413 | (cons (list Info-current-file Info-current-node (point)) | |
414 | Info-history))) | |
a384cab3 | 415 | ;; Go into info buffer. |
c5fe2ff1 | 416 | (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*")) |
4fceda3c SM |
417 | (Info-find-node-2 filename nodename no-going-back)) |
418 | ||
419 | (defun Info-on-current-buffer (&optional nodename) | |
420 | "Use the `Info-mode' to browse the current info buffer. | |
421 | If a prefix arg is provided, it queries for the NODENAME which | |
422 | else defaults to `Top'." | |
423 | (interactive | |
424 | (list (if current-prefix-arg | |
425 | (completing-read "Node name: " (Info-build-node-completions) | |
426 | nil t "Top") | |
427 | "Top"))) | |
428 | (Info-mode) | |
429 | (set (make-local-variable 'Info-current-file) t) | |
430 | (Info-find-node-2 nil nodename)) | |
431 | ||
432 | (defun Info-find-node-2 (filename nodename &optional no-going-back) | |
9e5c2f50 | 433 | (buffer-disable-undo (current-buffer)) |
a384cab3 JB |
434 | (or (eq major-mode 'Info-mode) |
435 | (Info-mode)) | |
436 | (widen) | |
437 | (setq Info-current-node nil) | |
438 | (unwind-protect | |
1bcedb3b | 439 | ;; Bind case-fold-search in case the user sets it to nil. |
8bdf4b20 KH |
440 | (let ((case-fold-search t) |
441 | anchorpos) | |
37a3ff5b RS |
442 | ;; Switch files if necessary |
443 | (or (null filename) | |
444 | (equal Info-current-file filename) | |
445 | (let ((buffer-read-only nil)) | |
446 | (setq Info-current-file nil | |
447 | Info-current-subfile nil | |
448 | Info-current-file-completions nil | |
449 | buffer-file-name nil) | |
450 | (erase-buffer) | |
451 | (if (eq filename t) | |
452 | (Info-insert-dir) | |
453 | (info-insert-file-contents filename t) | |
454 | (setq default-directory (file-name-directory filename))) | |
455 | (set-buffer-modified-p nil) | |
456 | ;; See whether file has a tag table. Record the location if yes. | |
457 | (goto-char (point-max)) | |
458 | (forward-line -8) | |
459 | ;; Use string-equal, not equal, to ignore text props. | |
460 | (if (not (or (string-equal nodename "*") | |
461 | (not | |
462 | (search-forward "\^_\nEnd tag table\n" nil t)))) | |
463 | (let (pos) | |
464 | ;; We have a tag table. Find its beginning. | |
465 | ;; Is this an indirect file? | |
466 | (search-backward "\nTag table:\n") | |
467 | (setq pos (point)) | |
468 | (if (save-excursion | |
469 | (forward-line 2) | |
470 | (looking-at "(Indirect)\n")) | |
471 | ;; It is indirect. Copy it to another buffer | |
472 | ;; and record that the tag table is in that buffer. | |
473 | (let ((buf (current-buffer)) | |
474 | (tagbuf | |
475 | (or Info-tag-table-buffer | |
476 | (generate-new-buffer " *info tag table*")))) | |
477 | (setq Info-tag-table-buffer tagbuf) | |
478 | (save-excursion | |
479 | (set-buffer tagbuf) | |
9e5c2f50 | 480 | (buffer-disable-undo (current-buffer)) |
37a3ff5b RS |
481 | (setq case-fold-search t) |
482 | (erase-buffer) | |
483 | (insert-buffer-substring buf)) | |
484 | (set-marker Info-tag-table-marker | |
485 | (match-end 0) tagbuf)) | |
486 | (set-marker Info-tag-table-marker pos))) | |
487 | (set-marker Info-tag-table-marker nil)) | |
488 | (setq Info-current-file | |
489 | (if (eq filename t) "dir" filename)))) | |
490 | ;; Use string-equal, not equal, to ignore text props. | |
491 | (if (string-equal nodename "*") | |
492 | (progn (setq Info-current-node nodename) | |
493 | (Info-set-mode-line)) | |
494 | ;; Possibilities: | |
495 | ;; | |
496 | ;; 1. Anchor found in tag table | |
497 | ;; 2. Anchor *not* in tag table | |
498 | ;; | |
499 | ;; 3. Node found in tag table | |
500 | ;; 4. Node *not* found in tag table, but found in file | |
501 | ;; 5. Node *not* in tag table, and *not* in file | |
502 | ;; | |
503 | ;; *Or* the same, but in an indirect subfile. | |
504 | ||
505 | ;; Search file for a suitable node. | |
8bdf4b20 KH |
506 | (let ((guesspos (point-min)) |
507 | (regexp | |
508 | (concat "\\(Node:\\|Ref:\\) *\\(" | |
509 | (regexp-quote nodename) | |
510 | "\\) *[,\t\n\177]")) | |
511 | (nodepos nil)) | |
37a3ff5b RS |
512 | |
513 | ;; First, search a tag table, if any | |
514 | (if (marker-position Info-tag-table-marker) | |
8bdf4b20 | 515 | (let ((found-in-tag-table t) |
635173de | 516 | found-anchor |
8bdf4b20 KH |
517 | found-mode |
518 | (m Info-tag-table-marker)) | |
37a3ff5b RS |
519 | (save-excursion |
520 | (set-buffer (marker-buffer m)) | |
521 | (goto-char m) | |
522 | (beginning-of-line) ; so re-search will work. | |
523 | ||
524 | ;; Search tag table | |
8bdf4b20 KH |
525 | (catch 'foo |
526 | (while (re-search-forward regexp nil t) | |
527 | (setq found-anchor | |
528 | (string-equal "Ref:" (match-string 1))) | |
529 | (or nodepos (setq nodepos (point)) | |
530 | (if (string-equal (match-string 2) nodename) | |
531 | (throw 'foo t)))) | |
532 | (if nodepos | |
533 | (goto-char nodepos) | |
534 | (setq found-in-tag-table nil))) | |
37a3ff5b | 535 | (if found-in-tag-table |
ba42ce14 | 536 | (setq guesspos (1+ (read (current-buffer))))) |
37a3ff5b RS |
537 | (setq found-mode major-mode)) |
538 | ||
539 | ;; Indirect file among split files | |
540 | (if found-in-tag-table | |
541 | (progn | |
542 | ;; If this is an indirect file, determine | |
543 | ;; which file really holds this node and | |
544 | ;; read it in. | |
545 | (if (not (eq found-mode 'Info-mode)) | |
546 | ;; Note that the current buffer must be | |
547 | ;; the *info* buffer on entry to | |
548 | ;; Info-read-subfile. Thus the hackery | |
549 | ;; above. | |
550 | (setq guesspos (Info-read-subfile guesspos))))) | |
551 | ||
552 | ;; Handle anchor | |
8bdf4b20 KH |
553 | (if found-anchor |
554 | (goto-char (setq anchorpos guesspos)) | |
37a3ff5b RS |
555 | |
556 | ;; Else we may have a node, which we search for: | |
55f9feda RS |
557 | (let ((guesschar |
558 | (or (byte-to-position guesspos) | |
559 | (if (< (position-bytes (point-max)) guesspos) | |
560 | (point-max) | |
561 | (point-min))))) | |
562 | (goto-char (max (point-min) | |
563 | (- guesschar 1000)))) | |
37a3ff5b RS |
564 | ;; Now search from our advised position |
565 | ;; (or from beg of buffer) | |
566 | ;; to find the actual node. | |
11638562 EZ |
567 | ;; First, check whether the node is right |
568 | ;; where we are, in case the buffer begins | |
569 | ;; with a node. | |
8bdf4b20 | 570 | (setq nodepos nil) |
11638562 EZ |
571 | (or (Info-node-at-bob-matching regexp) |
572 | (catch 'foo | |
573 | (while (search-forward "\n\^_" nil t) | |
ba42ce14 | 574 | (forward-line 1) |
11638562 EZ |
575 | (let ((beg (point))) |
576 | (forward-line 1) | |
577 | (if (re-search-backward regexp beg t) | |
8bdf4b20 KH |
578 | (if (string-equal (match-string 2) nodename) |
579 | (progn | |
580 | (beginning-of-line) | |
581 | (throw 'foo t)) | |
582 | (or nodepos | |
583 | (setq nodepos (point))))))) | |
584 | (if nodepos | |
585 | (progn | |
586 | (goto-char nodepos) | |
587 | (beginning-of-line)) | |
588 | (error | |
589 | "No such anchor in tag table or node in tag table or file: %s" | |
590 | nodename)))))) | |
4fba3b2c RS |
591 | (goto-char (max (point-min) (- guesspos 1000))) |
592 | ;; Now search from our advised position (or from beg of buffer) | |
593 | ;; to find the actual node. | |
11638562 EZ |
594 | ;; First, check whether the node is right where we are, in case |
595 | ;; the buffer begins with a node. | |
8bdf4b20 | 596 | (setq nodepos nil) |
11638562 EZ |
597 | (or (Info-node-at-bob-matching regexp) |
598 | (catch 'foo | |
599 | (while (search-forward "\n\^_" nil t) | |
ba42ce14 | 600 | (forward-line 1) |
11638562 EZ |
601 | (let ((beg (point))) |
602 | (forward-line 1) | |
603 | (if (re-search-backward regexp beg t) | |
8bdf4b20 KH |
604 | (if (string-equal (match-string 2) nodename) |
605 | (throw 'foo t) | |
606 | (or nodepos | |
607 | (setq nodepos (point))))))) | |
608 | (if nodepos | |
609 | (goto-char nodepos) | |
610 | (error "No such node: %s" nodename)))))) | |
9d499629 | 611 | (Info-select-node) |
8bdf4b20 | 612 | (goto-char (or anchorpos (point-min))))) |
a384cab3 JB |
613 | ;; If we did not finish finding the specified node, |
614 | ;; go back to the previous one. | |
4db579ab | 615 | (or Info-current-node no-going-back (null Info-history) |
37a3ff5b RS |
616 | (let ((hist (car Info-history))) |
617 | (setq Info-history (cdr Info-history)) | |
618 | (Info-find-node (nth 0 hist) (nth 1 hist) t) | |
619 | (goto-char (nth 2 hist)))))) | |
a384cab3 | 620 | |
44c327f9 JB |
621 | ;; Cache the contents of the (virtual) dir file, once we have merged |
622 | ;; it for the first time, so we can save time subsequently. | |
7ea13762 RS |
623 | (defvar Info-dir-contents nil) |
624 | ||
44c327f9 JB |
625 | ;; Cache for the directory we decided to use for the default-directory |
626 | ;; of the merged dir text. | |
627 | (defvar Info-dir-contents-directory nil) | |
628 | ||
c142ab2d RS |
629 | ;; Record the file attributes of all the files from which we |
630 | ;; constructed Info-dir-contents. | |
631 | (defvar Info-dir-file-attributes nil) | |
632 | ||
4fba3b2c RS |
633 | (defvar Info-dir-file-name nil) |
634 | ||
7ea13762 | 635 | ;; Construct the Info directory node by merging the files named `dir' |
44c327f9 JB |
636 | ;; from various directories. Set the *info* buffer's |
637 | ;; default-directory to the first directory we actually get any text | |
638 | ;; from. | |
7ea13762 | 639 | (defun Info-insert-dir () |
c142ab2d RS |
640 | (if (and Info-dir-contents Info-dir-file-attributes |
641 | ;; Verify that none of the files we used has changed | |
642 | ;; since we used it. | |
643 | (eval (cons 'and | |
644 | (mapcar '(lambda (elt) | |
76af32d5 RS |
645 | (let ((curr (file-attributes |
646 | ;; Handle symlinks | |
647 | (file-truename (car elt))))) | |
648 | ||
825d6f08 RS |
649 | ;; Don't compare the access time. |
650 | (if curr (setcar (nthcdr 4 curr) 0)) | |
651 | (setcar (nthcdr 4 (cdr elt)) 0) | |
652 | (equal (cdr elt) curr))) | |
c142ab2d | 653 | Info-dir-file-attributes)))) |
4fba3b2c RS |
654 | (progn |
655 | (insert Info-dir-contents) | |
656 | (goto-char (point-min))) | |
7ea13762 | 657 | (let ((dirs Info-directory-list) |
1bcedb3b RS |
658 | ;; Bind this in case the user sets it to nil. |
659 | (case-fold-search t) | |
4fba3b2c RS |
660 | ;; This is set non-nil if we find a problem in some input files. |
661 | problems | |
f4008b6e | 662 | buffers buffer others nodes dirs-done) |
44c327f9 | 663 | |
825d6f08 RS |
664 | (setq Info-dir-file-attributes nil) |
665 | ||
44c327f9 | 666 | ;; Search the directory list for the directory file. |
7ea13762 | 667 | (while dirs |
8d1abb42 RS |
668 | (let ((truename (file-truename (expand-file-name (car dirs))))) |
669 | (or (member truename dirs-done) | |
670 | (member (directory-file-name truename) dirs-done) | |
671 | ;; Try several variants of specified name. | |
672 | ;; Try upcasing, appending `.info', or both. | |
825d6f08 RS |
673 | (let* (file |
674 | (attrs | |
675 | (or | |
676 | (progn (setq file (expand-file-name "dir" truename)) | |
677 | (file-attributes file)) | |
678 | (progn (setq file (expand-file-name "DIR" truename)) | |
679 | (file-attributes file)) | |
680 | (progn (setq file (expand-file-name "dir.info" truename)) | |
681 | (file-attributes file)) | |
682 | (progn (setq file (expand-file-name "DIR.INFO" truename)) | |
683 | (file-attributes file))))) | |
8d1abb42 RS |
684 | (setq dirs-done |
685 | (cons truename | |
686 | (cons (directory-file-name truename) | |
687 | dirs-done))) | |
825d6f08 RS |
688 | (if attrs |
689 | (save-excursion | |
690 | (or buffers | |
691 | (message "Composing main Info directory...")) | |
2d41cf59 | 692 | (set-buffer (generate-new-buffer " info dir")) |
9d499629 RS |
693 | (condition-case nil |
694 | (progn | |
695 | (insert-file-contents file) | |
4fba3b2c RS |
696 | (make-local-variable 'Info-dir-file-name) |
697 | (setq Info-dir-file-name file) | |
9d499629 RS |
698 | (setq buffers (cons (current-buffer) buffers) |
699 | Info-dir-file-attributes | |
700 | (cons (cons file attrs) | |
701 | Info-dir-file-attributes))) | |
702 | (error (kill-buffer (current-buffer)))))))) | |
3296453b KH |
703 | (or (cdr dirs) (setq Info-dir-contents-directory |
704 | (file-name-as-directory (car dirs)))) | |
825d6f08 RS |
705 | (setq dirs (cdr dirs)))) |
706 | ||
4db579ab | 707 | (or buffers |
81e14cb2 | 708 | (error "Can't find the Info directory node")) |
44c327f9 | 709 | ;; Distinguish the dir file that comes with Emacs from all the |
f4008b6e | 710 | ;; others. Yes, that is really what this is supposed to do. |
f601cd3e DL |
711 | ;; The definition of `Info-directory-list' puts it first on that |
712 | ;; list and so last in `buffers' at this point. | |
713 | (setq buffer (car (last buffers)) | |
714 | others (delq buffer buffers)) | |
44c327f9 | 715 | |
debcea0c KH |
716 | ;; Insert the entire original dir file as a start; note that we've |
717 | ;; already saved its default directory to use as the default | |
718 | ;; directory for the whole concatenation. | |
7ea13762 | 719 | (insert-buffer buffer) |
44c327f9 | 720 | |
7ea13762 RS |
721 | ;; Look at each of the other buffers one by one. |
722 | (while others | |
4fba3b2c RS |
723 | (let ((other (car others)) |
724 | this-buffer-nodes) | |
7ea13762 RS |
725 | ;; In each, find all the menus. |
726 | (save-excursion | |
727 | (set-buffer other) | |
728 | (goto-char (point-min)) | |
729 | ;; Find each menu, and add an elt to NODES for it. | |
730 | (while (re-search-forward "^\\* Menu:" nil t) | |
731 | (let (beg nodename end) | |
732 | (forward-line 1) | |
733 | (setq beg (point)) | |
ba42ce14 EZ |
734 | (or (search-backward "\n\^_" nil 'move) |
735 | (looking-at "\^_") | |
736 | (signal 'search-failed (list "\n\^_"))) | |
7ea13762 RS |
737 | (search-forward "Node: ") |
738 | (setq nodename (Info-following-node-name)) | |
3a6ade8a | 739 | (search-forward "\n\^_" nil 'move) |
7ea13762 RS |
740 | (beginning-of-line) |
741 | (setq end (point)) | |
4fba3b2c RS |
742 | (setq this-buffer-nodes |
743 | (cons (list nodename other beg end) | |
744 | this-buffer-nodes)))) | |
745 | (if (assoc-ignore-case "top" this-buffer-nodes) | |
746 | (setq nodes (nconc this-buffer-nodes nodes)) | |
747 | (setq problems t) | |
748 | (message "No `top' node in %s" Info-dir-file-name)))) | |
7ea13762 RS |
749 | (setq others (cdr others))) |
750 | ;; Add to the main menu a menu item for each other node. | |
751 | (re-search-forward "^\\* Menu:") | |
752 | (forward-line 1) | |
753 | (let ((menu-items '("top")) | |
754 | (nodes nodes) | |
755 | (case-fold-search t) | |
3a6ade8a | 756 | (end (save-excursion (search-forward "\^_" nil t) (point)))) |
7ea13762 RS |
757 | (while nodes |
758 | (let ((nodename (car (car nodes)))) | |
c3a29d70 RS |
759 | (save-excursion |
760 | (or (member (downcase nodename) menu-items) | |
b37daea4 | 761 | (re-search-forward (concat "^\\* +" |
c3a29d70 RS |
762 | (regexp-quote nodename) |
763 | "::") | |
764 | end t) | |
765 | (progn | |
766 | (insert "* " nodename "::" "\n") | |
767 | (setq menu-items (cons nodename menu-items)))))) | |
7ea13762 RS |
768 | (setq nodes (cdr nodes)))) |
769 | ;; Now take each node of each of the other buffers | |
770 | ;; and merge it into the main buffer. | |
771 | (while nodes | |
772 | (let ((nodename (car (car nodes)))) | |
773 | (goto-char (point-min)) | |
774 | ;; Find the like-named node in the main buffer. | |
ba42ce14 | 775 | (if (re-search-forward (concat "^\^_.*\n.*Node: " |
7ea13762 RS |
776 | (regexp-quote nodename) |
777 | "[,\n\t]") | |
778 | nil t) | |
779 | (progn | |
3a6ade8a | 780 | (search-forward "\n\^_" nil 'move) |
25869acf RS |
781 | (beginning-of-line) |
782 | (insert "\n")) | |
7ea13762 RS |
783 | ;; If none exists, add one. |
784 | (goto-char (point-max)) | |
dfbf6104 | 785 | (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n")) |
7ea13762 RS |
786 | ;; Merge the text from the other buffer's menu |
787 | ;; into the menu in the like-named node in the main buffer. | |
25869acf | 788 | (apply 'insert-buffer-substring (cdr (car nodes)))) |
7ea13762 RS |
789 | (setq nodes (cdr nodes))) |
790 | ;; Kill all the buffers we just made. | |
791 | (while buffers | |
792 | (kill-buffer (car buffers)) | |
825d6f08 | 793 | (setq buffers (cdr buffers))) |
4fba3b2c RS |
794 | (goto-char (point-min)) |
795 | (if problems | |
796 | (message "Composing main Info directory...problems encountered, see `*Messages*'") | |
797 | (message "Composing main Info directory...done"))) | |
44c327f9 JB |
798 | (setq Info-dir-contents (buffer-string))) |
799 | (setq default-directory Info-dir-contents-directory)) | |
7ea13762 | 800 | |
c5fe2ff1 RS |
801 | ;; Note that on entry to this function the current-buffer must be the |
802 | ;; *info* buffer; not the info tags buffer. | |
a384cab3 | 803 | (defun Info-read-subfile (nodepos) |
a361deba RS |
804 | ;; NODEPOS is either a position (in the Info file as a whole, |
805 | ;; not relative to a subfile) or the name of a subfile. | |
a384cab3 JB |
806 | (let (lastfilepos |
807 | lastfilename) | |
a361deba RS |
808 | (if (numberp nodepos) |
809 | (save-excursion | |
810 | (set-buffer (marker-buffer Info-tag-table-marker)) | |
811 | (goto-char (point-min)) | |
ba42ce14 EZ |
812 | (or (looking-at "\^_") |
813 | (search-forward "\n\^_")) | |
a361deba RS |
814 | (forward-line 2) |
815 | (catch 'foo | |
816 | (while (not (looking-at "\^_")) | |
817 | (if (not (eolp)) | |
818 | (let ((beg (point)) | |
819 | thisfilepos thisfilename) | |
820 | (search-forward ": ") | |
821 | (setq thisfilename (buffer-substring beg (- (point) 2))) | |
822 | (setq thisfilepos (read (current-buffer))) | |
823 | ;; read in version 19 stops at the end of number. | |
824 | ;; Advance to the next line. | |
825 | (forward-line 1) | |
826 | (if (> thisfilepos nodepos) | |
827 | (throw 'foo t)) | |
828 | (setq lastfilename thisfilename) | |
829 | (setq lastfilepos thisfilepos)) | |
830 | (forward-line 1))))) | |
831 | (setq lastfilename nodepos) | |
832 | (setq lastfilepos 0)) | |
c5fe2ff1 RS |
833 | ;; Assume previous buffer is in Info-mode. |
834 | ;; (set-buffer (get-buffer "*info*")) | |
a384cab3 JB |
835 | (or (equal Info-current-subfile lastfilename) |
836 | (let ((buffer-read-only nil)) | |
837 | (setq buffer-file-name nil) | |
838 | (widen) | |
839 | (erase-buffer) | |
1143a6b0 | 840 | (info-insert-file-contents lastfilename) |
a384cab3 JB |
841 | (set-buffer-modified-p nil) |
842 | (setq Info-current-subfile lastfilename))) | |
843 | (goto-char (point-min)) | |
ba42ce14 EZ |
844 | (if (looking-at "\^_") |
845 | (forward-char 1) | |
846 | (search-forward "\n\^_")) | |
a361deba RS |
847 | (if (numberp nodepos) |
848 | (+ (- nodepos lastfilepos) (point))))) | |
a384cab3 JB |
849 | |
850 | ;; Select the info node that point is in. | |
851 | (defun Info-select-node () | |
1bcedb3b RS |
852 | ;; Bind this in case the user sets it to nil. |
853 | (let ((case-fold-search t)) | |
854 | (save-excursion | |
855 | ;; Find beginning of node. | |
ba42ce14 EZ |
856 | (if (search-backward "\n\^_" nil 'move) |
857 | (forward-line 2) | |
858 | (if (looking-at "\^_") | |
859 | (forward-line 1) | |
860 | (signal 'search-failed (list "\n\^_")))) | |
1bcedb3b RS |
861 | ;; Get nodename spelled as it is in the node. |
862 | (re-search-forward "Node:[ \t]*") | |
863 | (setq Info-current-node | |
864 | (buffer-substring-no-properties (point) | |
865 | (progn | |
866 | (skip-chars-forward "^,\t\n") | |
867 | (point)))) | |
868 | (Info-set-mode-line) | |
869 | ;; Find the end of it, and narrow. | |
870 | (beginning-of-line) | |
871 | (let (active-expression) | |
872 | (narrow-to-region (point) | |
873 | (if (re-search-forward "\n[\^_\f]" nil t) | |
874 | (prog1 | |
875 | (1- (point)) | |
876 | (if (looking-at "[\n\^_\f]*execute: ") | |
877 | (progn | |
878 | (goto-char (match-end 0)) | |
879 | (setq active-expression | |
880 | (read (current-buffer)))))) | |
881 | (point-max))) | |
882 | (if Info-enable-active-nodes (eval active-expression)) | |
883 | (if Info-fontify (Info-fontify-node)) | |
884 | (run-hooks 'Info-selection-hook))))) | |
a384cab3 JB |
885 | |
886 | (defun Info-set-mode-line () | |
887 | (setq mode-line-buffer-identification | |
888 | (concat | |
a580e884 | 889 | " Info: (" |
a384cab3 | 890 | (if Info-current-file |
4fceda3c SM |
891 | (file-name-nondirectory (if (stringp Info-current-file) |
892 | Info-current-file | |
893 | (or buffer-file-name ""))) | |
a384cab3 JB |
894 | "") |
895 | ")" | |
896 | (or Info-current-node "")))) | |
897 | \f | |
898 | ;; Go to an info node specified with a filename-and-nodename string | |
899 | ;; of the sort that is found in pointers in nodes. | |
900 | ||
4fceda3c SM |
901 | (defun Info-goto-node (nodename &optional fork) |
902 | "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME. | |
903 | If FORK is non-nil, show the node in a new info buffer. | |
904 | If FORK is a string, it is the name to use for the new buffer." | |
905 | (interactive (list (Info-read-node-name "Goto node: ") current-prefix-arg)) | |
d0e41cba | 906 | (info-initialize) |
4fceda3c SM |
907 | (if fork |
908 | (set-buffer | |
909 | (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t))) | |
a384cab3 JB |
910 | (let (filename) |
911 | (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)" | |
912 | nodename) | |
913 | (setq filename (if (= (match-beginning 1) (match-end 1)) | |
914 | "" | |
915 | (substring nodename (match-beginning 2) (match-end 2))) | |
916 | nodename (substring nodename (match-beginning 3) (match-end 3))) | |
917 | (let ((trim (string-match "\\s *\\'" filename))) | |
918 | (if trim (setq filename (substring filename 0 trim)))) | |
919 | (let ((trim (string-match "\\s *\\'" nodename))) | |
920 | (if trim (setq nodename (substring nodename 0 trim)))) | |
e579232c | 921 | (if transient-mark-mode (deactivate-mark)) |
a384cab3 JB |
922 | (Info-find-node (if (equal filename "") nil filename) |
923 | (if (equal nodename "") "Top" nodename)))) | |
552775bd | 924 | |
ddf89211 RS |
925 | (defvar Info-read-node-completion-table) |
926 | ||
03524be6 | 927 | ;; This function is used as the "completion table" while reading a node name. |
ddf89211 | 928 | ;; It does completion using the alist in Info-read-node-completion-table |
03524be6 RS |
929 | ;; unless STRING starts with an open-paren. |
930 | (defun Info-read-node-name-1 (string predicate code) | |
931 | (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\()))) | |
932 | (cond ((eq code nil) | |
933 | (if no-completion | |
934 | string | |
ddf89211 | 935 | (try-completion string Info-read-node-completion-table predicate))) |
03524be6 RS |
936 | ((eq code t) |
937 | (if no-completion | |
938 | nil | |
ddf89211 | 939 | (all-completions string Info-read-node-completion-table predicate))) |
03524be6 RS |
940 | ((eq code 'lambda) |
941 | (if no-completion | |
942 | t | |
ddf89211 | 943 | (assoc string Info-read-node-completion-table)))))) |
03524be6 | 944 | |
552775bd RS |
945 | (defun Info-read-node-name (prompt &optional default) |
946 | (let* ((completion-ignore-case t) | |
ddf89211 | 947 | (Info-read-node-completion-table (Info-build-node-completions)) |
b6d61ffa | 948 | (nodename (completing-read prompt 'Info-read-node-name-1 nil t))) |
552775bd RS |
949 | (if (equal nodename "") |
950 | (or default | |
951 | (Info-read-node-name prompt)) | |
952 | nodename))) | |
953 | ||
954 | (defun Info-build-node-completions () | |
955 | (or Info-current-file-completions | |
1bcedb3b RS |
956 | (let ((compl nil) |
957 | ;; Bind this in case the user sets it to nil. | |
11638562 EZ |
958 | (case-fold-search t) |
959 | (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]")) | |
552775bd RS |
960 | (save-excursion |
961 | (save-restriction | |
962 | (if (marker-buffer Info-tag-table-marker) | |
c5fe2ff1 RS |
963 | (let ((marker Info-tag-table-marker)) |
964 | (set-buffer (marker-buffer marker)) | |
cedb118c | 965 | (widen) |
c5fe2ff1 | 966 | (goto-char marker) |
552775bd RS |
967 | (while (re-search-forward "\nNode: \\(.*\\)\177" nil t) |
968 | (setq compl | |
110d4e80 | 969 | (cons (list (match-string-no-properties 1)) |
552775bd RS |
970 | compl)))) |
971 | (widen) | |
972 | (goto-char (point-min)) | |
11638562 EZ |
973 | ;; If the buffer begins with a node header, process that first. |
974 | (if (Info-node-at-bob-matching node-regexp) | |
110d4e80 | 975 | (setq compl (list (match-string-no-properties 1)))) |
11638562 | 976 | ;; Now for the rest of the nodes. |
552775bd RS |
977 | (while (search-forward "\n\^_" nil t) |
978 | (forward-line 1) | |
979 | (let ((beg (point))) | |
980 | (forward-line 1) | |
11638562 | 981 | (if (re-search-backward node-regexp beg t) |
552775bd | 982 | (setq compl |
110d4e80 | 983 | (cons (list (match-string-no-properties 1)) |
552775bd | 984 | compl)))))))) |
87d2b5a2 | 985 | (setq compl (cons '("*") compl)) |
552775bd | 986 | (setq Info-current-file-completions compl)))) |
a384cab3 | 987 | \f |
aea2a8da JB |
988 | (defun Info-restore-point (hl) |
989 | "If this node has been visited, restore the point value when we left." | |
cedb118c RS |
990 | (while hl |
991 | (if (and (equal (nth 0 (car hl)) Info-current-file) | |
e90d1271 RS |
992 | ;; Use string-equal, not equal, to ignore text props. |
993 | (string-equal (nth 1 (car hl)) Info-current-node)) | |
cedb118c | 994 | (progn |
d96504df KH |
995 | (goto-char (nth 2 (car hl))) |
996 | (setq hl nil)) ;terminate the while at next iter | |
cedb118c | 997 | (setq hl (cdr hl))))) |
aea2a8da | 998 | \f |
a384cab3 | 999 | (defvar Info-last-search nil |
d5913bf6 | 1000 | "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.") |
a384cab3 JB |
1001 | |
1002 | (defun Info-search (regexp) | |
1003 | "Search for REGEXP, starting from point, and select node it's found in." | |
1004 | (interactive "sSearch (regexp): ") | |
e579232c | 1005 | (if transient-mark-mode (deactivate-mark)) |
a384cab3 JB |
1006 | (if (equal regexp "") |
1007 | (setq regexp Info-last-search) | |
1008 | (setq Info-last-search regexp)) | |
c47b5bbe DL |
1009 | (when regexp |
1010 | (let ((found ()) current | |
1011 | (onode Info-current-node) | |
1012 | (ofile Info-current-file) | |
1013 | (opoint (point)) | |
1014 | (ostart (window-start)) | |
1015 | (osubfile Info-current-subfile)) | |
1016 | (save-excursion | |
1017 | (save-restriction | |
1018 | (widen) | |
1019 | (if (null Info-current-subfile) | |
a384cab3 | 1020 | (progn (re-search-forward regexp) (setq found (point))) |
c47b5bbe DL |
1021 | (condition-case err |
1022 | (progn (re-search-forward regexp) (setq found (point))) | |
1023 | (search-failed nil))))) | |
1024 | (if (not found) ;can only happen in subfile case -- else would have erred | |
1025 | (unwind-protect | |
1026 | (let ((list ())) | |
1027 | (save-excursion | |
1028 | (set-buffer (marker-buffer Info-tag-table-marker)) | |
c5fe2ff1 | 1029 | (goto-char (point-min)) |
c47b5bbe DL |
1030 | (search-forward "\n\^_\nIndirect:") |
1031 | (save-restriction | |
1032 | (narrow-to-region (point) | |
1033 | (progn (search-forward "\n\^_") | |
1034 | (1- (point)))) | |
1035 | (goto-char (point-min)) | |
1036 | (search-forward (concat "\n" osubfile ": ")) | |
1037 | (beginning-of-line) | |
1038 | (while (not (eobp)) | |
1039 | (re-search-forward "\\(^.*\\): [0-9]+$") | |
1040 | (goto-char (+ (match-end 1) 2)) | |
1041 | (setq list (cons (cons (read (current-buffer)) | |
110d4e80 | 1042 | (match-string-no-properties 1)) |
c47b5bbe DL |
1043 | list)) |
1044 | (goto-char (1+ (match-end 0)))) | |
1045 | (setq list (nreverse list) | |
1046 | current (car (car list)) | |
1047 | list (cdr list)))) | |
1048 | (while list | |
1049 | (message "Searching subfile %s..." (cdr (car list))) | |
1050 | (Info-read-subfile (car (car list))) | |
1051 | (setq list (cdr list)) | |
1052 | ;;; (goto-char (point-min)) | |
1053 | (if (re-search-forward regexp nil t) | |
1054 | (setq found (point) list ()))) | |
1055 | (if found | |
1056 | (message "") | |
1057 | (signal 'search-failed (list regexp)))) | |
1058 | (if (not found) | |
1059 | (progn (Info-read-subfile osubfile) | |
1060 | (goto-char opoint) | |
1061 | (Info-select-node) | |
1062 | (set-window-start (selected-window) ostart))))) | |
a384cab3 JB |
1063 | (widen) |
1064 | (goto-char found) | |
1065 | (Info-select-node) | |
e90d1271 RS |
1066 | ;; Use string-equal, not equal, to ignore text props. |
1067 | (or (and (string-equal onode Info-current-node) | |
a384cab3 JB |
1068 | (equal ofile Info-current-file)) |
1069 | (setq Info-history (cons (list ofile onode opoint) | |
c47b5bbe | 1070 | Info-history)))))) |
a384cab3 JB |
1071 | \f |
1072 | ;; Extract the value of the node-pointer named NAME. | |
1073 | ;; If there is none, use ERRORNAME in the error message; | |
1074 | ;; if ERRORNAME is nil, just return nil. | |
1075 | (defun Info-extract-pointer (name &optional errorname) | |
1bcedb3b RS |
1076 | ;; Bind this in case the user sets it to nil. |
1077 | (let ((case-fold-search t)) | |
1078 | (save-excursion | |
1079 | (goto-char (point-min)) | |
1080 | (forward-line 1) | |
1081 | (if (re-search-backward (concat name ":") nil t) | |
1082 | (progn | |
1083 | (goto-char (match-end 0)) | |
1084 | (Info-following-node-name)) | |
1085 | (if (eq errorname t) | |
1086 | nil | |
1087 | (error "Node has no %s" (capitalize (or errorname name)))))))) | |
a384cab3 | 1088 | |
7ea13762 RS |
1089 | ;; Return the node name in the buffer following point. |
1090 | ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp | |
c5fe2ff1 | 1091 | ;; saying which chars may appear in the node name. |
a384cab3 JB |
1092 | (defun Info-following-node-name (&optional allowedchars) |
1093 | (skip-chars-forward " \t") | |
70d78eb6 | 1094 | (buffer-substring-no-properties |
a384cab3 JB |
1095 | (point) |
1096 | (progn | |
1097 | (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]")) | |
1098 | (skip-chars-forward (concat (or allowedchars "^,\t\n") "(")) | |
1099 | (if (looking-at "(") | |
1100 | (skip-chars-forward "^)"))) | |
1101 | (skip-chars-backward " ") | |
1102 | (point)))) | |
1103 | ||
1104 | (defun Info-next () | |
1105 | "Go to the next node of this node." | |
1106 | (interactive) | |
1107 | (Info-goto-node (Info-extract-pointer "next"))) | |
1108 | ||
1109 | (defun Info-prev () | |
1110 | "Go to the previous node of this node." | |
1111 | (interactive) | |
1112 | (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))) | |
1113 | ||
5dab2fb4 RS |
1114 | (defun Info-up (&optional same-file) |
1115 | "Go to the superior node of this node. | |
1116 | If SAME-FILE is non-nil, do not move to a different Info file." | |
a384cab3 | 1117 | (interactive) |
5dab2fb4 | 1118 | (let ((node (Info-extract-pointer "up"))) |
4fceda3c | 1119 | (and (or same-file (not (stringp Info-current-file))) |
5dab2fb4 RS |
1120 | (string-match "^(" node) |
1121 | (error "Up node is in another Info file")) | |
1122 | (Info-goto-node node)) | |
aea2a8da | 1123 | (Info-restore-point Info-history)) |
a384cab3 JB |
1124 | |
1125 | (defun Info-last () | |
1126 | "Go back to the last node visited." | |
1127 | (interactive) | |
1128 | (or Info-history | |
1129 | (error "This is the first Info node you looked at")) | |
1130 | (let (filename nodename opoint) | |
1131 | (setq filename (car (car Info-history))) | |
1132 | (setq nodename (car (cdr (car Info-history)))) | |
1133 | (setq opoint (car (cdr (cdr (car Info-history))))) | |
1134 | (setq Info-history (cdr Info-history)) | |
1135 | (Info-find-node filename nodename) | |
1136 | (setq Info-history (cdr Info-history)) | |
1137 | (goto-char opoint))) | |
1138 | ||
1139 | (defun Info-directory () | |
1140 | "Go to the Info directory node." | |
1141 | (interactive) | |
1142 | (Info-find-node "dir" "top")) | |
1143 | \f | |
1144 | (defun Info-follow-reference (footnotename) | |
1145 | "Follow cross reference named NAME to the node it refers to. | |
1146 | NAME may be an abbreviation of the reference name." | |
1147 | (interactive | |
1148 | (let ((completion-ignore-case t) | |
1bcedb3b | 1149 | (case-fold-search t) |
67bc89ab | 1150 | completions default alt-default (start-point (point)) str i bol eol) |
a384cab3 | 1151 | (save-excursion |
67bc89ab RS |
1152 | ;; Store end and beginning of line. |
1153 | (end-of-line) | |
1154 | (setq eol (point)) | |
1155 | (beginning-of-line) | |
1156 | (setq bol (point)) | |
1157 | ||
a384cab3 JB |
1158 | (goto-char (point-min)) |
1159 | (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t) | |
110d4e80 | 1160 | (setq str (buffer-substring-no-properties |
a384cab3 JB |
1161 | (match-beginning 1) |
1162 | (1- (point)))) | |
1163 | ;; See if this one should be the default. | |
1164 | (and (null default) | |
1f179e27 | 1165 | (<= (match-beginning 0) start-point) |
a384cab3 JB |
1166 | (<= start-point (point)) |
1167 | (setq default t)) | |
67bc89ab RS |
1168 | ;; See if this one should be the alternate default. |
1169 | (and (null alt-default) | |
1170 | (and (<= bol (match-beginning 0)) | |
1171 | (<= (point) eol)) | |
1172 | (setq alt-default t)) | |
a384cab3 JB |
1173 | (setq i 0) |
1174 | (while (setq i (string-match "[ \n\t]+" str i)) | |
1175 | (setq str (concat (substring str 0 i) " " | |
1176 | (substring str (match-end 0)))) | |
1177 | (setq i (1+ i))) | |
1178 | ;; Record as a completion and perhaps as default. | |
1179 | (if (eq default t) (setq default str)) | |
67bc89ab | 1180 | (if (eq alt-default t) (setq alt-default str)) |
ec6d29af KH |
1181 | ;; Don't add this string if it's a duplicate. |
1182 | ;; We use a loop instead of "(assoc str completions)" because | |
1183 | ;; we want to do a case-insensitive compare. | |
1184 | (let ((tail completions) | |
1185 | (tem (downcase str))) | |
1186 | (while (and tail | |
1187 | (not (string-equal tem (downcase (car (car tail)))))) | |
1188 | (setq tail (cdr tail))) | |
1189 | (or tail | |
1190 | (setq completions | |
1191 | (cons (cons str nil) | |
1192 | completions)))))) | |
67bc89ab RS |
1193 | ;; If no good default was found, try an alternate. |
1194 | (or default | |
1195 | (setq default alt-default)) | |
1196 | ;; If only one cross-reference found, then make it default. | |
1197 | (if (eq (length completions) 1) | |
1198 | (setq default (car (car completions)))) | |
a384cab3 | 1199 | (if completions |
b0ebdfe5 RS |
1200 | (let ((input (completing-read (if default |
1201 | (concat "Follow reference named: (" | |
1202 | default ") ") | |
1203 | "Follow reference named: ") | |
1204 | completions nil t))) | |
1205 | (list (if (equal input "") | |
1206 | default input))) | |
a384cab3 | 1207 | (error "No cross-references in this node")))) |
ebf8f7e1 RS |
1208 | |
1209 | (unless footnotename | |
1210 | (error "No reference was specified")) | |
1211 | ||
1bcedb3b RS |
1212 | (let (target beg i (str (concat "\\*note " (regexp-quote footnotename))) |
1213 | (case-fold-search t)) | |
a384cab3 JB |
1214 | (while (setq i (string-match " " str i)) |
1215 | (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i)))) | |
1216 | (setq i (+ i 6))) | |
1217 | (save-excursion | |
1218 | (goto-char (point-min)) | |
1219 | (or (re-search-forward str nil t) | |
1220 | (error "No cross-reference named %s" footnotename)) | |
1221 | (goto-char (+ (match-beginning 0) 5)) | |
1222 | (setq target | |
1223 | (Info-extract-menu-node-name "Bad format cross reference" t))) | |
1224 | (while (setq i (string-match "[ \t\n]+" target i)) | |
1225 | (setq target (concat (substring target 0 i) " " | |
1226 | (substring target (match-end 0)))) | |
1227 | (setq i (+ i 1))) | |
1228 | (Info-goto-node target))) | |
1229 | ||
1230 | (defun Info-extract-menu-node-name (&optional errmessage multi-line) | |
1231 | (skip-chars-forward " \t\n") | |
1232 | (let ((beg (point)) | |
1233 | str i) | |
1234 | (skip-chars-forward "^:") | |
1235 | (forward-char 1) | |
1236 | (setq str | |
1237 | (if (looking-at ":") | |
70d78eb6 | 1238 | (buffer-substring-no-properties beg (1- (point))) |
a384cab3 JB |
1239 | (skip-chars-forward " \t\n") |
1240 | (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n")))) | |
1241 | (while (setq i (string-match "\n" str i)) | |
1242 | (aset str i ?\ )) | |
2e52ff59 RS |
1243 | ;; Collapse multiple spaces. |
1244 | (while (string-match " +" str) | |
1245 | (setq str (replace-match " " t t str))) | |
a384cab3 JB |
1246 | str)) |
1247 | ||
e8adde3f | 1248 | ;; No one calls this. |
9e5c2f50 RS |
1249 | ;;(defun Info-menu-item-sequence (list) |
1250 | ;; (while list | |
e8adde3f | 1251 | ;; (Info-menu (car list)) |
9e5c2f50 | 1252 | ;; (setq list (cdr list)))) |
a384cab3 | 1253 | |
6356e646 RS |
1254 | (defvar Info-complete-menu-buffer) |
1255 | ||
e8adde3f RS |
1256 | (defun Info-complete-menu-item (string predicate action) |
1257 | (let ((case-fold-search t)) | |
1258 | (cond ((eq action nil) | |
1259 | (let (completions | |
b37daea4 | 1260 | (pattern (concat "\n\\* +\\(" |
e8adde3f RS |
1261 | (regexp-quote string) |
1262 | "[^:\t\n]*\\):"))) | |
1263 | (save-excursion | |
1264 | (set-buffer Info-complete-menu-buffer) | |
1265 | (goto-char (point-min)) | |
763da090 | 1266 | (search-forward "\n* Menu:") |
e8adde3f | 1267 | (while (re-search-forward pattern nil t) |
110d4e80 DL |
1268 | (setq completions |
1269 | (cons (cons (match-string-no-properties 1) | |
1270 | (match-beginning 1)) | |
1271 | completions)))) | |
e8adde3f RS |
1272 | (try-completion string completions predicate))) |
1273 | ((eq action t) | |
1274 | (let (completions | |
b37daea4 | 1275 | (pattern (concat "\n\\* +\\(" |
e8adde3f RS |
1276 | (regexp-quote string) |
1277 | "[^:\t\n]*\\):"))) | |
1278 | (save-excursion | |
1279 | (set-buffer Info-complete-menu-buffer) | |
1280 | (goto-char (point-min)) | |
763da090 | 1281 | (search-forward "\n* Menu:") |
e8adde3f | 1282 | (while (re-search-forward pattern nil t) |
110d4e80 DL |
1283 | (setq completions (cons (cons |
1284 | (match-string-no-properties 1) | |
1285 | (match-beginning 1)) | |
e8adde3f RS |
1286 | completions)))) |
1287 | (all-completions string completions predicate))) | |
1288 | (t | |
1289 | (save-excursion | |
1290 | (set-buffer Info-complete-menu-buffer) | |
1291 | (goto-char (point-min)) | |
763da090 | 1292 | (search-forward "\n* Menu:") |
b37daea4 | 1293 | (re-search-forward (concat "\n\\* +" |
e8adde3f RS |
1294 | (regexp-quote string) |
1295 | ":") | |
1296 | nil t)))))) | |
1297 | ||
1298 | ||
4fceda3c | 1299 | (defun Info-menu (menu-item &optional fork) |
a384cab3 JB |
1300 | "Go to node for menu item named (or abbreviated) NAME. |
1301 | Completion is allowed, and the menu item point is on is the default." | |
1302 | (interactive | |
1303 | (let ((completions '()) | |
1304 | ;; If point is within a menu item, use that item as the default | |
1305 | (default nil) | |
1306 | (p (point)) | |
211d6309 | 1307 | beg |
a384cab3 JB |
1308 | (last nil)) |
1309 | (save-excursion | |
1310 | (goto-char (point-min)) | |
1311 | (if (not (search-forward "\n* menu:" nil t)) | |
1312 | (error "No menu in this node")) | |
e8adde3f RS |
1313 | (setq beg (point)) |
1314 | (and (< (point) p) | |
1315 | (save-excursion | |
1316 | (goto-char p) | |
1317 | (end-of-line) | |
4fc14e5a | 1318 | (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t) |
110d4e80 | 1319 | (setq default (match-string-no-properties 1)))))) |
a384cab3 JB |
1320 | (let ((item nil)) |
1321 | (while (null item) | |
e8adde3f RS |
1322 | (setq item (let ((completion-ignore-case t) |
1323 | (Info-complete-menu-buffer (current-buffer))) | |
a384cab3 JB |
1324 | (completing-read (if default |
1325 | (format "Menu item (default %s): " | |
1326 | default) | |
1327 | "Menu item: ") | |
e8adde3f | 1328 | 'Info-complete-menu-item nil t))) |
aea2a8da JB |
1329 | ;; we rely on the fact that completing-read accepts an input |
1330 | ;; of "" even when the require-match argument is true and "" | |
1331 | ;; is not a valid possibility | |
a384cab3 JB |
1332 | (if (string= item "") |
1333 | (if default | |
1334 | (setq item default) | |
1335 | ;; ask again | |
1336 | (setq item nil)))) | |
4fceda3c | 1337 | (list item current-prefix-arg)))) |
a384cab3 JB |
1338 | ;; there is a problem here in that if several menu items have the same |
1339 | ;; name you can only go to the node of the first with this command. | |
4fceda3c | 1340 | (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item))) |
a384cab3 JB |
1341 | |
1342 | (defun Info-extract-menu-item (menu-item) | |
1343 | (setq menu-item (regexp-quote menu-item)) | |
1bcedb3b RS |
1344 | (let ((case-fold-search t)) |
1345 | (save-excursion | |
1346 | (goto-char (point-min)) | |
1347 | (or (search-forward "\n* menu:" nil t) | |
1348 | (error "No menu in this node")) | |
1349 | (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t) | |
1350 | (re-search-forward (concat "\n\\* +" menu-item) nil t) | |
1351 | (error "No such item in menu")) | |
1352 | (beginning-of-line) | |
1353 | (forward-char 2) | |
1354 | (Info-extract-menu-node-name)))) | |
a384cab3 JB |
1355 | |
1356 | ;; If COUNT is nil, use the last item in the menu. | |
1357 | (defun Info-extract-menu-counting (count) | |
1bcedb3b RS |
1358 | (let ((case-fold-search t)) |
1359 | (save-excursion | |
1360 | (goto-char (point-min)) | |
1361 | (or (search-forward "\n* menu:" nil t) | |
1362 | (error "No menu in this node")) | |
1363 | (if count | |
1364 | (or (search-forward "\n* " nil t count) | |
1365 | (error "Too few items in menu")) | |
1366 | (while (search-forward "\n* " nil t) | |
1367 | nil)) | |
1368 | (Info-extract-menu-node-name)))) | |
a384cab3 | 1369 | |
e38e7367 RM |
1370 | (defun Info-nth-menu-item () |
1371 | "Go to the node of the Nth menu item. | |
1372 | N is the digit argument used to invoke this command." | |
a384cab3 | 1373 | (interactive) |
e38e7367 RM |
1374 | (Info-goto-node |
1375 | (Info-extract-menu-counting | |
1376 | (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0)))) | |
a384cab3 JB |
1377 | |
1378 | (defun Info-top-node () | |
1379 | "Go to the Top node of this file." | |
1380 | (interactive) | |
1381 | (Info-goto-node "Top")) | |
1382 | ||
1383 | (defun Info-final-node () | |
1384 | "Go to the final node in this file." | |
1385 | (interactive) | |
1386 | (Info-goto-node "Top") | |
1387 | (let (Info-history) | |
1388 | ;; Go to the last node in the menu of Top. | |
1389 | (Info-goto-node (Info-extract-menu-counting nil)) | |
1390 | ;; If the last node in the menu is not last in pointer structure, | |
1391 | ;; move forward until we can't go any farther. | |
1392 | (while (Info-forward-node t t) nil) | |
1393 | ;; Then keep moving down to last subnode, unless we reach an index. | |
1394 | (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
1395 | (save-excursion (search-forward "\n* Menu:" nil t))) | |
1396 | (Info-goto-node (Info-extract-menu-counting nil))))) | |
1397 | ||
1398 | (defun Info-forward-node (&optional not-down no-error) | |
1399 | "Go forward one node, considering all nodes as forming one sequence." | |
1400 | (interactive) | |
1401 | (goto-char (point-min)) | |
1402 | (forward-line 1) | |
1403 | ;; three possibilities, in order of priority: | |
1404 | ;; 1. next node is in a menu in this node (but not in an index) | |
1405 | ;; 2. next node is next at same level | |
1406 | ;; 3. next node is up and next | |
1407 | (cond ((and (not not-down) | |
1408 | (save-excursion (search-forward "\n* menu:" nil t)) | |
1409 | (not (string-match "\\<index\\>" Info-current-node))) | |
463f48f4 | 1410 | (Info-goto-node (Info-extract-menu-counting 1)) |
a384cab3 JB |
1411 | t) |
1412 | ((save-excursion (search-backward "next:" nil t)) | |
1413 | (Info-next) | |
1414 | t) | |
1415 | ((and (save-excursion (search-backward "up:" nil t)) | |
e90d1271 RS |
1416 | ;; Use string-equal, not equal, to ignore text props. |
1417 | (not (string-equal (downcase (Info-extract-pointer "up")) | |
1418 | "top"))) | |
a384cab3 JB |
1419 | (let ((old-node Info-current-node)) |
1420 | (Info-up) | |
1421 | (let (Info-history success) | |
1422 | (unwind-protect | |
1423 | (setq success (Info-forward-node t no-error)) | |
1424 | (or success (Info-goto-node old-node)))))) | |
1425 | (no-error nil) | |
1426 | (t (error "No pointer forward from this node")))) | |
1427 | ||
1428 | (defun Info-backward-node () | |
1429 | "Go backward one node, considering all nodes as forming one sequence." | |
1430 | (interactive) | |
1431 | (let ((prevnode (Info-extract-pointer "prev[ious]*" t)) | |
1432 | (upnode (Info-extract-pointer "up" t))) | |
1433 | (cond ((and upnode (string-match "(" upnode)) | |
1434 | (error "First node in file")) | |
1435 | ((and upnode (or (null prevnode) | |
e90d1271 RS |
1436 | ;; Use string-equal, not equal, |
1437 | ;; to ignore text properties. | |
1438 | (string-equal (downcase prevnode) | |
1439 | (downcase upnode)))) | |
a384cab3 JB |
1440 | (Info-up)) |
1441 | (prevnode | |
1442 | ;; If we move back at the same level, | |
1443 | ;; go down to find the last subnode*. | |
1444 | (Info-prev) | |
1445 | (let (Info-history) | |
1446 | (while (and (not (string-match "\\<index\\>" Info-current-node)) | |
1447 | (save-excursion (search-forward "\n* Menu:" nil t))) | |
1448 | (Info-goto-node (Info-extract-menu-counting nil))))) | |
1449 | (t | |
1450 | (error "No pointer backward from this node"))))) | |
1451 | ||
1452 | (defun Info-exit () | |
1453 | "Exit Info by selecting some other buffer." | |
1454 | (interactive) | |
552775bd RS |
1455 | (if Info-standalone |
1456 | (save-buffers-kill-emacs) | |
4643e92f | 1457 | (quit-window))) |
a384cab3 | 1458 | |
253db917 ER |
1459 | (defun Info-next-menu-item () |
1460 | (interactive) | |
fadfb77f RS |
1461 | (let ((node |
1462 | (save-excursion | |
1463 | (forward-line -1) | |
1464 | (search-forward "\n* menu:" nil t) | |
1465 | (and (search-forward "\n* " nil t) | |
1466 | (Info-extract-menu-node-name))))) | |
1467 | (if node (Info-goto-node node) | |
1468 | (error "No more items in menu")))) | |
253db917 ER |
1469 | |
1470 | (defun Info-last-menu-item () | |
1471 | (interactive) | |
1472 | (save-excursion | |
1473 | (forward-line 1) | |
0a56332b RS |
1474 | (let ((beg (save-excursion |
1475 | (and (search-backward "\n* menu:" nil t) | |
1476 | (point))))) | |
1477 | (or (and beg (search-backward "\n* " beg t)) | |
1478 | (error "No previous items in menu"))) | |
1479 | (Info-goto-node (save-excursion | |
1480 | (goto-char (match-end 0)) | |
1481 | (Info-extract-menu-node-name))))) | |
253db917 | 1482 | |
552775bd | 1483 | (defmacro Info-no-error (&rest body) |
253db917 ER |
1484 | (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil))) |
1485 | ||
1486 | (defun Info-next-preorder () | |
3c9179ea RS |
1487 | "Go to the next subnode or the next node, or go up a level." |
1488 | (interactive) | |
1489 | (cond ((Info-no-error (Info-next-menu-item))) | |
1490 | ((Info-no-error (Info-next))) | |
5dab2fb4 | 1491 | ((Info-no-error (Info-up t)) |
ed690657 KH |
1492 | ;; Since we have already gone thru all the items in this menu, |
1493 | ;; go up to the end of this node. | |
b54d0f0e RS |
1494 | (goto-char (point-max)) |
1495 | ;; Since logically we are done with the node with that menu, | |
1496 | ;; move on from it. | |
1497 | (Info-next-preorder)) | |
3c9179ea RS |
1498 | (t |
1499 | (error "No more nodes")))) | |
253db917 ER |
1500 | |
1501 | (defun Info-last-preorder () | |
1502 | "Go to the last node, popping up a level if there is none." | |
1503 | (interactive) | |
0a56332b RS |
1504 | (cond ((Info-no-error |
1505 | (Info-last-menu-item) | |
1506 | ;; If we go down a menu item, go to the end of the node | |
1507 | ;; so we can scroll back through it. | |
ed690657 | 1508 | (goto-char (point-max))) |
b54d0f0e RS |
1509 | ;; Keep going down, as long as there are nested menu nodes. |
1510 | (while (Info-no-error | |
1511 | (Info-last-menu-item) | |
1512 | ;; If we go down a menu item, go to the end of the node | |
1513 | ;; so we can scroll back through it. | |
1514 | (goto-char (point-max)))) | |
ed690657 | 1515 | (recenter -1)) |
5dab2fb4 RS |
1516 | ((and (not (equal (Info-extract-pointer "up") |
1517 | (Info-extract-pointer "prev")))) | |
1518 | (Info-no-error (Info-prev)) | |
ed690657 | 1519 | (goto-char (point-max)) |
b54d0f0e RS |
1520 | (while (Info-no-error |
1521 | (Info-last-menu-item) | |
1522 | ;; If we go down a menu item, go to the end of the node | |
1523 | ;; so we can scroll back through it. | |
1524 | (goto-char (point-max)))) | |
ed690657 | 1525 | (recenter -1)) |
5dab2fb4 | 1526 | ((Info-no-error (Info-up t)) |
ed690657 KH |
1527 | (goto-char (point-min)) |
1528 | (or (search-forward "\n* Menu:" nil t) | |
1529 | (goto-char (point-max)))) | |
1530 | (t (error "No previous nodes")))) | |
253db917 ER |
1531 | |
1532 | (defun Info-scroll-up () | |
3f32dc86 | 1533 | "Scroll one screenful forward in Info, considering all nodes as one sequence. |
280d11ed RS |
1534 | Once you scroll far enough in a node that its menu appears on the screen |
1535 | but after point, the next scroll moves into its first subnode. | |
1536 | ||
1537 | When you scroll past the end of a node, that goes to the next node; if | |
1538 | this node has no successor, it moves to the parent node's successor, | |
1539 | and so on. If point is inside the menu of a node, it moves to | |
1540 | subnode indicated by the following menu item. (That case won't | |
1541 | normally result from this command, but can happen in other ways.)" | |
1542 | ||
253db917 | 1543 | (interactive) |
0a56332b RS |
1544 | (if (or (< (window-start) (point-min)) |
1545 | (> (window-start) (point-max))) | |
1546 | (set-window-start (selected-window) (point))) | |
1547 | (let ((virtual-end (save-excursion | |
1548 | (goto-char (point-min)) | |
1549 | (if (search-forward "\n* Menu:" nil t) | |
1550 | (point) | |
1551 | (point-max))))) | |
1552 | (if (or (< virtual-end (window-start)) | |
1553 | (pos-visible-in-window-p virtual-end)) | |
1554 | (Info-next-preorder) | |
1555 | (scroll-up)))) | |
253db917 ER |
1556 | |
1557 | (defun Info-scroll-down () | |
3f32dc86 | 1558 | "Scroll one screenful back in Info, considering all nodes as one sequence. |
ed690657 KH |
1559 | Within the menu of a node, this goes to its last subnode. |
1560 | When you scroll past the beginning of a node, that goes to the | |
1561 | previous node or back up to the parent node." | |
253db917 | 1562 | (interactive) |
0a56332b RS |
1563 | (if (or (< (window-start) (point-min)) |
1564 | (> (window-start) (point-max))) | |
1565 | (set-window-start (selected-window) (point))) | |
b54d0f0e RS |
1566 | (let* ((current-point (point)) |
1567 | (virtual-end (save-excursion | |
1568 | (beginning-of-line) | |
1569 | (setq current-point (point)) | |
1570 | (goto-char (point-min)) | |
1571 | (search-forward "\n* Menu:" | |
1572 | current-point | |
1573 | t)))) | |
0a56332b RS |
1574 | (if (or virtual-end (pos-visible-in-window-p (point-min))) |
1575 | (Info-last-preorder) | |
1576 | (scroll-down)))) | |
253db917 | 1577 | |
56cda6f5 | 1578 | (defun Info-next-reference (&optional recur) |
552775bd RS |
1579 | "Move cursor to the next cross-reference or menu item in the node." |
1580 | (interactive) | |
1581 | (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:") | |
1bcedb3b RS |
1582 | (old-pt (point)) |
1583 | (case-fold-search t)) | |
552775bd RS |
1584 | (or (eobp) (forward-char 1)) |
1585 | (or (re-search-forward pat nil t) | |
1586 | (progn | |
1587 | (goto-char (point-min)) | |
1588 | (or (re-search-forward pat nil t) | |
1589 | (progn | |
1590 | (goto-char old-pt) | |
1591 | (error "No cross references in this node"))))) | |
1592 | (goto-char (match-beginning 0)) | |
1593 | (if (looking-at "\\* Menu:") | |
56cda6f5 RS |
1594 | (if recur |
1595 | (error "No cross references in this node") | |
1596 | (Info-next-reference t))))) | |
552775bd | 1597 | |
56cda6f5 | 1598 | (defun Info-prev-reference (&optional recur) |
552775bd RS |
1599 | "Move cursor to the previous cross-reference or menu item in the node." |
1600 | (interactive) | |
1601 | (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:") | |
1bcedb3b RS |
1602 | (old-pt (point)) |
1603 | (case-fold-search t)) | |
552775bd RS |
1604 | (or (re-search-backward pat nil t) |
1605 | (progn | |
1606 | (goto-char (point-max)) | |
1607 | (or (re-search-backward pat nil t) | |
1608 | (progn | |
1609 | (goto-char old-pt) | |
1610 | (error "No cross references in this node"))))) | |
1611 | (goto-char (match-beginning 0)) | |
1612 | (if (looking-at "\\* Menu:") | |
56cda6f5 RS |
1613 | (if recur |
1614 | (error "No cross references in this node") | |
1615 | (Info-prev-reference t))))) | |
552775bd | 1616 | |
1143a6b0 ER |
1617 | (defun Info-index (topic) |
1618 | "Look up a string in the index for this file. | |
1619 | The index is defined as the first node in the top-level menu whose | |
1620 | name contains the word \"Index\", plus any immediately following | |
1621 | nodes whose names also contain the word \"Index\". | |
1622 | If there are no exact matches to the specified topic, this chooses | |
1623 | the first match which is a case-insensitive substring of a topic. | |
1624 | Use the `,' command to see the other matches. | |
1625 | Give a blank topic name to go to the Index node itself." | |
1626 | (interactive "sIndex topic: ") | |
1627 | (let ((orignode Info-current-node) | |
1628 | (rnode nil) | |
b37daea4 | 1629 | (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)" |
1143a6b0 | 1630 | (regexp-quote topic))) |
1bcedb3b RS |
1631 | node |
1632 | (case-fold-search t)) | |
1143a6b0 ER |
1633 | (Info-goto-node "Top") |
1634 | (or (search-forward "\n* menu:" nil t) | |
1635 | (error "No index")) | |
1636 | (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t) | |
1637 | (error "No index")) | |
1638 | (goto-char (match-beginning 1)) | |
c696ac76 RS |
1639 | ;; Here, and subsequently in this function, |
1640 | ;; we bind Info-history to nil for internal node-switches | |
1641 | ;; so that we don't put junk in the history. | |
1642 | ;; In the first Info-goto-node call, above, we do update the history | |
1643 | ;; because that is what the user's previous node choice into it. | |
1644 | (let ((Info-history nil)) | |
1143a6b0 ER |
1645 | (Info-goto-node (Info-extract-menu-node-name))) |
1646 | (or (equal topic "") | |
1647 | (let ((matches nil) | |
1648 | (exact nil) | |
c696ac76 | 1649 | (Info-history nil) |
1143a6b0 ER |
1650 | found) |
1651 | (while | |
1652 | (progn | |
1653 | (goto-char (point-min)) | |
1654 | (while (re-search-forward pattern nil t) | |
1655 | (setq matches | |
110d4e80 DL |
1656 | (cons (list (match-string-no-properties 1) |
1657 | (match-string-no-properties 2) | |
1143a6b0 ER |
1658 | Info-current-node |
1659 | (string-to-int (concat "0" | |
110d4e80 | 1660 | (match-string 3)))) |
1143a6b0 ER |
1661 | matches))) |
1662 | (and (setq node (Info-extract-pointer "next" t)) | |
1663 | (string-match "\\<Index\\>" node))) | |
1664 | (Info-goto-node node)) | |
1665 | (or matches | |
1666 | (progn | |
81e14cb2 | 1667 | (Info-goto-node orignode) |
920bdaab | 1668 | (error "No `%s' in index" topic))) |
1143a6b0 ER |
1669 | ;; Here it is a feature that assoc is case-sensitive. |
1670 | (while (setq found (assoc topic matches)) | |
1671 | (setq exact (cons found exact) | |
1672 | matches (delq found matches))) | |
1673 | (setq Info-index-alternatives (nconc exact (nreverse matches))) | |
1674 | (Info-index-next 0))))) | |
1675 | ||
1676 | (defun Info-index-next (num) | |
1677 | "Go to the next matching index item from the last `i' command." | |
1678 | (interactive "p") | |
1679 | (or Info-index-alternatives | |
882e61bf | 1680 | (error "No previous `i' command")) |
1143a6b0 ER |
1681 | (while (< num 0) |
1682 | (setq num (+ num (length Info-index-alternatives)))) | |
1683 | (while (> num 0) | |
1684 | (setq Info-index-alternatives | |
1685 | (nconc (cdr Info-index-alternatives) | |
1686 | (list (car Info-index-alternatives))) | |
1687 | num (1- num))) | |
1688 | (Info-goto-node (nth 1 (car Info-index-alternatives))) | |
1689 | (if (> (nth 3 (car Info-index-alternatives)) 0) | |
1690 | (forward-line (nth 3 (car Info-index-alternatives))) | |
1691 | (forward-line 3) ; don't search in headers | |
1692 | (let ((name (car (car Info-index-alternatives)))) | |
920bdaab RS |
1693 | (Info-find-index-name name))) |
1694 | (message "Found `%s' in %s. %s" | |
1143a6b0 ER |
1695 | (car (car Info-index-alternatives)) |
1696 | (nth 2 (car Info-index-alternatives)) | |
1697 | (if (cdr Info-index-alternatives) | |
1698 | "(Press `,' for more)" | |
1699 | "(Only match)"))) | |
1700 | ||
920bdaab RS |
1701 | (defun Info-find-index-name (name) |
1702 | "Move point to the place within the current node where NAME is defined." | |
1bcedb3b RS |
1703 | (let ((case-fold-search t)) |
1704 | (if (or (re-search-forward (format | |
1705 | "[a-zA-Z]+: %s\\( \\|$\\)" | |
1706 | (regexp-quote name)) nil t) | |
1707 | (search-forward (format "`%s'" name) nil t) | |
1708 | (and (string-match "\\`.*\\( (.*)\\)\\'" name) | |
1709 | (search-forward | |
1710 | (format "`%s'" (substring name 0 (match-beginning 1))) | |
1711 | nil t)) | |
1712 | (search-forward name nil t)) | |
1713 | (beginning-of-line) | |
1714 | (goto-char (point-min))))) | |
920bdaab | 1715 | |
a384cab3 JB |
1716 | (defun Info-undefined () |
1717 | "Make command be undefined in Info." | |
1718 | (interactive) | |
1719 | (ding)) | |
1720 | ||
1721 | (defun Info-help () | |
1722 | "Enter the Info tutorial." | |
1723 | (interactive) | |
1724 | (delete-other-windows) | |
1725 | (Info-find-node "info" | |
1726 | (if (< (window-height) 23) | |
1727 | "Help-Small-Screen" | |
1728 | "Help"))) | |
1729 | ||
1730 | (defun Info-summary () | |
1731 | "Display a brief summary of all Info commands." | |
1732 | (interactive) | |
1733 | (save-window-excursion | |
1734 | (switch-to-buffer "*Help*") | |
881c84c7 | 1735 | (setq buffer-read-only nil) |
a384cab3 JB |
1736 | (erase-buffer) |
1737 | (insert (documentation 'Info-mode)) | |
9d29f94c | 1738 | (help-mode) |
a384cab3 JB |
1739 | (goto-char (point-min)) |
1740 | (let (ch flag) | |
1741 | (while (progn (setq flag (not (pos-visible-in-window-p (point-max)))) | |
1742 | (message (if flag "Type Space to see more" | |
1743 | "Type Space to return to Info")) | |
1614c867 | 1744 | (if (not (eq ?\ (setq ch (read-event)))) |
dbc4e1c1 | 1745 | (progn (setq unread-command-events (list ch)) nil) |
a384cab3 | 1746 | flag)) |
552775bd RS |
1747 | (scroll-up))) |
1748 | (bury-buffer "*Help*"))) | |
a384cab3 JB |
1749 | \f |
1750 | (defun Info-get-token (pos start all &optional errorstring) | |
1751 | "Return the token around POS, | |
1752 | POS must be somewhere inside the token | |
1753 | START is a regular expression which will match the | |
1754 | beginning of the tokens delimited string | |
1755 | ALL is a regular expression with a single | |
90a715f0 | 1756 | parenthesized subpattern which is the token to be |
a384cab3 JB |
1757 | returned. E.g. '{\(.*\)}' would return any string |
1758 | enclosed in braces around POS. | |
1759 | SIG optional fourth argument, controls action on no match | |
1760 | nil: return nil | |
1761 | t: beep | |
1762 | a string: signal an error, using that string." | |
1bcedb3b RS |
1763 | (let ((case-fold-search t)) |
1764 | (save-excursion | |
1765 | (goto-char pos) | |
1766 | ;; First look for a match for START that goes across POS. | |
1767 | (while (and (not (bobp)) (> (point) (- pos (length start))) | |
1768 | (not (looking-at start))) | |
1769 | (forward-char -1)) | |
1770 | ;; If we did not find one, search back for START | |
1771 | ;; (this finds only matches that end at or before POS). | |
1772 | (or (looking-at start) | |
1773 | (progn | |
1774 | (goto-char pos) | |
1775 | (re-search-backward start (max (point-min) (- pos 200)) 'yes))) | |
1776 | (let (found) | |
1777 | (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes) | |
1778 | (not (setq found (and (<= (match-beginning 0) pos) | |
1779 | (> (match-end 0) pos)))))) | |
1780 | (if (and found (<= (match-beginning 0) pos) | |
1781 | (> (match-end 0) pos)) | |
110d4e80 | 1782 | (match-string-no-properties 1) |
1bcedb3b RS |
1783 | (cond ((null errorstring) |
1784 | nil) | |
1785 | ((eq errorstring t) | |
1786 | (beep) | |
1787 | nil) | |
1788 | (t | |
1789 | (error "No %s around position %d" errorstring pos)))))))) | |
a384cab3 | 1790 | |
981947af | 1791 | (defun Info-mouse-follow-nearest-node (click) |
f9969361 RS |
1792 | "\\<Info-mode-map>Follow a node reference near point. |
1793 | Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click. | |
981947af | 1794 | At end of the node's text, moves to the next node, or up if none." |
f9969361 | 1795 | (interactive "e") |
9e5c2f50 RS |
1796 | (let* ((start (event-start click)) |
1797 | (window (car start)) | |
1798 | (pos (car (cdr start)))) | |
1799 | (select-window window) | |
1800 | (goto-char pos)) | |
981947af KH |
1801 | (and (not (Info-try-follow-nearest-node)) |
1802 | (save-excursion (forward-line 1) (eobp)) | |
ed690657 | 1803 | (Info-next-preorder))) |
981947af KH |
1804 | |
1805 | (defun Info-follow-nearest-node () | |
1806 | "\\<Info-mode-map>Follow a node reference near point. | |
1807 | Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is. | |
1808 | If no reference to follow, moves to the next node, or up if none." | |
1809 | (interactive) | |
1810 | (or (Info-try-follow-nearest-node) | |
ed690657 | 1811 | (Info-next-preorder))) |
981947af KH |
1812 | |
1813 | ;; Common subroutine. | |
1814 | (defun Info-try-follow-nearest-node () | |
1815 | "Follow a node reference near point. Return non-nil if successful." | |
a384cab3 JB |
1816 | (let (node) |
1817 | (cond | |
981947af KH |
1818 | ((setq node (Info-get-token (point) "\\*note[ \n]" |
1819 | "\\*note[ \n]\\([^:]*\\):")) | |
a384cab3 | 1820 | (Info-follow-reference node)) |
b37daea4 | 1821 | ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::")) |
a384cab3 | 1822 | (Info-goto-node node)) |
631ba13e RS |
1823 | ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):") |
1824 | (beginning-of-line) | |
1825 | (forward-char 2) | |
1826 | (setq node (Info-extract-menu-node-name)) | |
1827 | (Info-goto-node node)) | |
bc2ada62 | 1828 | ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)")) |
a384cab3 | 1829 | (Info-goto-node node)) |
bc2ada62 | 1830 | ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)")) |
a384cab3 | 1831 | (Info-goto-node node)) |
bc2ada62 | 1832 | ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)")) |
a384cab3 | 1833 | (Info-goto-node "Top")) |
bc2ada62 | 1834 | ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)")) |
981947af KH |
1835 | (Info-goto-node node))) |
1836 | node)) | |
a384cab3 JB |
1837 | \f |
1838 | (defvar Info-mode-map nil | |
1839 | "Keymap containing Info commands.") | |
1840 | (if Info-mode-map | |
1841 | nil | |
1842 | (setq Info-mode-map (make-keymap)) | |
1843 | (suppress-keymap Info-mode-map) | |
1844 | (define-key Info-mode-map "." 'beginning-of-buffer) | |
253db917 | 1845 | (define-key Info-mode-map " " 'Info-scroll-up) |
981947af | 1846 | (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node) |
552775bd RS |
1847 | (define-key Info-mode-map "\t" 'Info-next-reference) |
1848 | (define-key Info-mode-map "\e\t" 'Info-prev-reference) | |
e38e7367 RM |
1849 | (define-key Info-mode-map "1" 'Info-nth-menu-item) |
1850 | (define-key Info-mode-map "2" 'Info-nth-menu-item) | |
1851 | (define-key Info-mode-map "3" 'Info-nth-menu-item) | |
1852 | (define-key Info-mode-map "4" 'Info-nth-menu-item) | |
1853 | (define-key Info-mode-map "5" 'Info-nth-menu-item) | |
1854 | (define-key Info-mode-map "6" 'Info-nth-menu-item) | |
1855 | (define-key Info-mode-map "7" 'Info-nth-menu-item) | |
1856 | (define-key Info-mode-map "8" 'Info-nth-menu-item) | |
1857 | (define-key Info-mode-map "9" 'Info-nth-menu-item) | |
82a4c008 | 1858 | (define-key Info-mode-map "0" 'undefined) |
a384cab3 JB |
1859 | (define-key Info-mode-map "?" 'Info-summary) |
1860 | (define-key Info-mode-map "]" 'Info-forward-node) | |
1861 | (define-key Info-mode-map "[" 'Info-backward-node) | |
1862 | (define-key Info-mode-map "<" 'Info-top-node) | |
1863 | (define-key Info-mode-map ">" 'Info-final-node) | |
1864 | (define-key Info-mode-map "b" 'beginning-of-buffer) | |
1865 | (define-key Info-mode-map "d" 'Info-directory) | |
1866 | (define-key Info-mode-map "e" 'Info-edit) | |
1867 | (define-key Info-mode-map "f" 'Info-follow-reference) | |
1868 | (define-key Info-mode-map "g" 'Info-goto-node) | |
1869 | (define-key Info-mode-map "h" 'Info-help) | |
1143a6b0 | 1870 | (define-key Info-mode-map "i" 'Info-index) |
a384cab3 JB |
1871 | (define-key Info-mode-map "l" 'Info-last) |
1872 | (define-key Info-mode-map "m" 'Info-menu) | |
1873 | (define-key Info-mode-map "n" 'Info-next) | |
1874 | (define-key Info-mode-map "p" 'Info-prev) | |
1875 | (define-key Info-mode-map "q" 'Info-exit) | |
1876 | (define-key Info-mode-map "s" 'Info-search) | |
47fc33ca RS |
1877 | ;; For consistency with Rmail. |
1878 | (define-key Info-mode-map "\M-s" 'Info-search) | |
4fceda3c | 1879 | (define-key Info-mode-map "\M-n" 'clone-buffer) |
db0c9809 | 1880 | (define-key Info-mode-map "t" 'Info-top-node) |
a384cab3 | 1881 | (define-key Info-mode-map "u" 'Info-up) |
1143a6b0 | 1882 | (define-key Info-mode-map "," 'Info-index-next) |
803eaf50 | 1883 | (define-key Info-mode-map "\177" 'Info-scroll-down) |
981947af | 1884 | (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node) |
aea2a8da | 1885 | ) |
75a209d4 RS |
1886 | |
1887 | (defun Info-check-pointer (item) | |
1888 | ;; Non-nil if ITEM is present in this node. | |
1889 | (condition-case nil | |
1890 | (Info-extract-pointer item) | |
1891 | (error nil))) | |
1892 | ||
1893 | (easy-menu-define Info-mode-menu Info-mode-map | |
1894 | "Menu for info files." | |
1895 | '("Info" | |
1896 | ["Up" Info-up (Info-check-pointer "up")] | |
1897 | ["Next" Info-next (Info-check-pointer "next")] | |
1898 | ["Previous" Info-prev (Info-check-pointer "prev[ious]*")] | |
1899 | ("Menu item" ["You should never see this" report-emacs-bug t]) | |
1900 | ("Reference" ["You should never see this" report-emacs-bug t]) | |
1901 | ["Search..." Info-search t] | |
1902 | ["Goto node..." Info-goto-node t] | |
1903 | ["Last" Info-last Info-history] | |
1904 | ["Exit" Info-exit t])) | |
1905 | ||
1906 | (defvar Info-menu-last-node nil) | |
1907 | ;; Last node the menu was created for. | |
6d2c8e3e | 1908 | ;; Value is a list, (FILE-NAME NODE-NAME). |
75a209d4 RS |
1909 | |
1910 | (defun Info-menu-update () | |
1911 | ;; Update the Info menu for the current node. | |
1912 | (condition-case nil | |
1913 | (if (or (not (eq major-mode 'Info-mode)) | |
6d2c8e3e RS |
1914 | (equal (list Info-current-file Info-current-node) |
1915 | Info-menu-last-node)) | |
75a209d4 RS |
1916 | () |
1917 | ;; Update menu menu. | |
1918 | (let* ((Info-complete-menu-buffer (current-buffer)) | |
1919 | (items (nreverse (condition-case nil | |
1920 | (Info-complete-menu-item | |
1921 | "" (lambda (e) t) t) | |
1922 | (error nil)))) | |
1923 | entries current | |
1924 | (number 0)) | |
1925 | (while (and items (< number 9)) | |
1926 | (setq current (car items) | |
1927 | items (cdr items) | |
1928 | number (1+ number)) | |
1929 | (setq entries (cons `[,current | |
1930 | (Info-menu ,current) | |
1931 | :keys ,(format "%d" number)] | |
1932 | entries))) | |
1933 | (if items | |
1934 | (setq entries (cons ["Other..." Info-menu t] entries))) | |
1935 | (or entries | |
1936 | (setq entries (list ["No menu" nil nil]))) | |
1937 | (easy-menu-change '("Info") "Menu item" (nreverse entries))) | |
1938 | ;; Update reference menu. Code stolen from `Info-follow-reference'. | |
1939 | (let ((items nil) | |
1940 | str i entries current | |
1bcedb3b RS |
1941 | (number 0) |
1942 | (case-fold-search t)) | |
75a209d4 RS |
1943 | (save-excursion |
1944 | (goto-char (point-min)) | |
1945 | (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t) | |
1946 | (setq str (buffer-substring | |
1947 | (match-beginning 1) | |
1948 | (1- (point)))) | |
1949 | (setq i 0) | |
1950 | (while (setq i (string-match "[ \n\t]+" str i)) | |
1951 | (setq str (concat (substring str 0 i) " " | |
1952 | (substring str (match-end 0)))) | |
1953 | (setq i (1+ i))) | |
1954 | (setq items | |
1955 | (cons str items)))) | |
1956 | (while (and items (< number 9)) | |
1957 | (setq current (car items) | |
1958 | items (cdr items) | |
1959 | number (1+ number)) | |
1960 | (setq entries (cons `[,current | |
1961 | (Info-follow-reference ,current) | |
1962 | t] | |
1963 | entries))) | |
1964 | (if items | |
1965 | (setq entries (cons ["Other..." Info-follow-reference t] | |
1966 | entries))) | |
1967 | (or entries | |
1968 | (setq entries (list ["No references" nil nil]))) | |
1969 | (easy-menu-change '("Info") "Reference" (nreverse entries))) | |
1970 | ;; Update last seen node. | |
6d2c8e3e | 1971 | (setq Info-menu-last-node (list Info-current-file Info-current-node))) |
75a209d4 RS |
1972 | ;; Try to avoid entering infinite beep mode in case of errors. |
1973 | (error (ding)))) | |
1974 | ||
a384cab3 JB |
1975 | \f |
1976 | ;; Info mode is suitable only for specially formatted data. | |
1977 | (put 'info-mode 'mode-class 'special) | |
1978 | ||
1979 | (defun Info-mode () | |
1980 | "\\<Info-mode-map> | |
1981 | Info mode provides commands for browsing through the Info documentation tree. | |
1982 | Documentation in Info is divided into \"nodes\", each of which discusses | |
1983 | one topic and contains references to other nodes which discuss related | |
1984 | topics. Info has commands to follow the references and show you other nodes. | |
1985 | ||
1986 | \\[Info-help] Invoke the Info tutorial. | |
6b136ab9 | 1987 | \\[Info-exit] Quit Info: reselect previously selected buffer. |
a384cab3 JB |
1988 | |
1989 | Selecting other nodes: | |
21d5959f RS |
1990 | \\[Info-mouse-follow-nearest-node] |
1991 | Follow a node reference you click on. | |
1992 | This works with menu items, cross references, and | |
1993 | the \"next\", \"previous\" and \"up\", depending on where you click. | |
6b136ab9 | 1994 | \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node]. |
a384cab3 | 1995 | \\[Info-next] Move to the \"next\" node of this node. |
bc2ada62 | 1996 | \\[Info-prev] Move to the \"previous\" node of this node. |
a384cab3 JB |
1997 | \\[Info-up] Move \"up\" from this node. |
1998 | \\[Info-menu] Pick menu item specified by name (or abbreviation). | |
1999 | Picking a menu item causes another node to be selected. | |
aea2a8da | 2000 | \\[Info-directory] Go to the Info directory node. |
a384cab3 JB |
2001 | \\[Info-follow-reference] Follow a cross reference. Reads name of reference. |
2002 | \\[Info-last] Move to the last node you were at. | |
1143a6b0 ER |
2003 | \\[Info-index] Look up a topic in this file's Index and move to that node. |
2004 | \\[Info-index-next] (comma) Move to the next match from a previous `i' command. | |
6b136ab9 DL |
2005 | \\[Info-top-node] Go to the Top node of this file. |
2006 | \\[Info-final-node] Go to the final node in this file. | |
2007 | \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence. | |
2008 | \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence. | |
a384cab3 JB |
2009 | |
2010 | Moving within a node: | |
177c3549 RS |
2011 | \\[Info-scroll-up] Normally, scroll forward a full screen. |
2012 | Once you scroll far enough in a node that its menu appears on the screen | |
2013 | but after point, the next scroll moves into its first subnode. | |
2014 | When after all menu items (or if their is no menu), move up to | |
2015 | the parent node. | |
2016 | \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is | |
803eaf50 ER |
2017 | already visible, try to go to the previous menu entry, or up if there is none. |
2018 | \\[beginning-of-buffer] Go to beginning of node. | |
a384cab3 | 2019 | |
a384cab3 JB |
2020 | Advanced commands: |
2021 | \\[Info-exit] Quit Info: reselect previously selected buffer. | |
2022 | \\[Info-edit] Edit contents of selected node. | |
2023 | 1 Pick first item in node's menu. | |
2024 | 2, 3, 4, 5 Pick second ... fifth item in node's menu. | |
2025 | \\[Info-goto-node] Move to node specified by name. | |
2026 | You may include a filename as well, as (FILENAME)NODENAME. | |
552775bd | 2027 | \\[universal-argument] \\[info] Move to new Info file with completion. |
a384cab3 | 2028 | \\[Info-search] Search through this Info file for specified regexp, |
803eaf50 | 2029 | and select the node in which the next occurrence is found. |
552775bd RS |
2030 | \\[Info-next-reference] Move cursor to next cross-reference or menu item. |
2031 | \\[Info-prev-reference] Move cursor to previous cross-reference or menu item." | |
a384cab3 JB |
2032 | (kill-all-local-variables) |
2033 | (setq major-mode 'Info-mode) | |
2034 | (setq mode-name "Info") | |
f73299f3 | 2035 | (setq tab-width 8) |
a384cab3 | 2036 | (use-local-map Info-mode-map) |
75a209d4 RS |
2037 | (make-local-hook 'activate-menubar-hook) |
2038 | (add-hook 'activate-menubar-hook 'Info-menu-update nil t) | |
a384cab3 JB |
2039 | (set-syntax-table text-mode-syntax-table) |
2040 | (setq local-abbrev-table text-mode-abbrev-table) | |
2041 | (setq case-fold-search t) | |
2042 | (setq buffer-read-only t) | |
a384cab3 JB |
2043 | (make-local-variable 'Info-current-file) |
2044 | (make-local-variable 'Info-current-subfile) | |
2045 | (make-local-variable 'Info-current-node) | |
2046 | (make-local-variable 'Info-tag-table-marker) | |
c5fe2ff1 RS |
2047 | (setq Info-tag-table-marker (make-marker)) |
2048 | (make-local-variable 'Info-tag-table-buffer) | |
2049 | (setq Info-tag-table-buffer nil) | |
a384cab3 | 2050 | (make-local-variable 'Info-history) |
1143a6b0 | 2051 | (make-local-variable 'Info-index-alternatives) |
93480d70 RS |
2052 | ;; This is for the sake of the invisible text we use handling titles. |
2053 | (make-local-variable 'line-move-ignore-invisible) | |
2054 | (setq line-move-ignore-invisible t) | |
4fceda3c | 2055 | (add-hook (make-local-hook 'clone-buffer-hook) 'Info-clone-buffer-hook nil t) |
a384cab3 JB |
2056 | (Info-set-mode-line) |
2057 | (run-hooks 'Info-mode-hook)) | |
2058 | ||
4fceda3c SM |
2059 | (defun Info-clone-buffer-hook () |
2060 | (when (bufferp Info-tag-table-buffer) | |
2061 | (setq Info-tag-table-buffer | |
2062 | (with-current-buffer Info-tag-table-buffer (clone-buffer))) | |
2063 | (let ((m Info-tag-table-marker)) | |
2064 | (when (and (markerp m) (marker-position m)) | |
2065 | (setq Info-tag-table-marker | |
2066 | (with-current-buffer Info-tag-table-buffer | |
2067 | (copy-marker (marker-position m)))))))) | |
2068 | ||
a384cab3 JB |
2069 | (defvar Info-edit-map nil |
2070 | "Local keymap used within `e' command of Info.") | |
2071 | (if Info-edit-map | |
2072 | nil | |
2073 | (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map)) | |
2074 | (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit)) | |
2075 | ||
2076 | ;; Info-edit mode is suitable only for specially formatted data. | |
2077 | (put 'info-edit-mode 'mode-class 'special) | |
2078 | ||
2079 | (defun Info-edit-mode () | |
2080 | "Major mode for editing the contents of an Info node. | |
a426b157 | 2081 | Like text mode with the addition of `Info-cease-edit' |
a384cab3 JB |
2082 | which returns to Info mode for browsing. |
2083 | \\{Info-edit-map}" | |
a384cab3 JB |
2084 | (use-local-map Info-edit-map) |
2085 | (setq major-mode 'Info-edit-mode) | |
2086 | (setq mode-name "Info Edit") | |
2087 | (kill-local-variable 'mode-line-buffer-identification) | |
2088 | (setq buffer-read-only nil) | |
2c609f53 | 2089 | (force-mode-line-update) |
e82c28f9 KH |
2090 | (buffer-enable-undo (current-buffer)) |
2091 | (run-hooks 'Info-edit-mode-hook)) | |
2092 | ||
2093 | (defun Info-edit () | |
2094 | "Edit the contents of this Info node. | |
2095 | Allowed only if variable `Info-enable-edit' is non-nil." | |
2096 | (interactive) | |
2097 | (or Info-enable-edit | |
2098 | (error "Editing info nodes is not enabled")) | |
2099 | (Info-edit-mode) | |
8ab3e50b | 2100 | (message "%s" (substitute-command-keys |
e82c28f9 | 2101 | "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info"))) |
a384cab3 JB |
2102 | |
2103 | (defun Info-cease-edit () | |
2104 | "Finish editing Info node; switch back to Info proper." | |
2105 | (interactive) | |
2106 | ;; Do this first, so nothing has changed if user C-g's at query. | |
2107 | (and (buffer-modified-p) | |
2108 | (y-or-n-p "Save the file? ") | |
2109 | (save-buffer)) | |
2110 | (use-local-map Info-mode-map) | |
2111 | (setq major-mode 'Info-mode) | |
2112 | (setq mode-name "Info") | |
2113 | (Info-set-mode-line) | |
2114 | (setq buffer-read-only t) | |
2c609f53 | 2115 | (force-mode-line-update) |
a384cab3 JB |
2116 | (and (marker-position Info-tag-table-marker) |
2117 | (buffer-modified-p) | |
2118 | (message "Tags may have changed. Use Info-tagify if necessary"))) | |
f0a8a3f1 | 2119 | \f |
f88ab1c9 | 2120 | (defvar Info-file-list-for-emacs |
d0e41cba DL |
2121 | '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc" "message" |
2122 | ("dired" . "dired-x") ("c" . "ccmode") "viper") | |
f88ab1c9 RS |
2123 | "List of Info files that describe Emacs commands. |
2124 | An element can be a file name, or a list of the form (PREFIX . FILE) | |
2125 | where PREFIX is a name prefix and FILE is the file to look in. | |
2126 | If the element is just a file name, the file name also serves as the prefix.") | |
2127 | ||
f0a8a3f1 | 2128 | (defun Info-find-emacs-command-nodes (command) |
f88ab1c9 | 2129 | "Return a list of locations documenting COMMAND. |
f57b2cd8 RS |
2130 | The `info-file' property of COMMAND says which Info manual to search. |
2131 | If COMMAND has no property, the variable `Info-file-list-for-emacs' | |
2132 | defines heuristics for which Info manual to try. | |
f0a8a3f1 RM |
2133 | The locations are of the format used in Info-history, i.e. |
2134 | \(FILENAME NODENAME BUFFERPOS\)." | |
f0a8a3f1 | 2135 | (let ((where '()) |
b37daea4 | 2136 | (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command)) |
f88ab1c9 RS |
2137 | ":\\s *\\(.*\\)\\.$")) |
2138 | (info-file "emacs")) ;default | |
2139 | ;; Determine which info file this command is documented in. | |
2140 | (if (get command 'info-file) | |
2141 | (setq info-file (get command 'info-file)) | |
2142 | ;; If it doesn't say explicitly, test its name against | |
2143 | ;; various prefixes that we know. | |
2144 | (let ((file-list Info-file-list-for-emacs)) | |
2145 | (while file-list | |
2146 | (let* ((elt (car file-list)) | |
2147 | (name (if (consp elt) | |
2148 | (car elt) | |
2149 | elt)) | |
2150 | (file (if (consp elt) (cdr elt) elt)) | |
f57b2cd8 | 2151 | (regexp (concat "\\`" (regexp-quote name) |
f88ab1c9 RS |
2152 | "\\(\\'\\|-\\)"))) |
2153 | (if (string-match regexp (symbol-name command)) | |
2154 | (setq info-file file file-list nil)) | |
2155 | (setq file-list (cdr file-list)))))) | |
f0a8a3f1 | 2156 | (save-excursion |
f88ab1c9 RS |
2157 | (condition-case nil |
2158 | (Info-find-node info-file "Command Index") | |
2159 | ;; Some manuals may not have a separate Command Index node, | |
2160 | ;; so try just Index instead. | |
2161 | (error | |
2162 | (Info-find-node info-file "Index"))) | |
f0a8a3f1 RM |
2163 | ;; Take the index node off the Info history. |
2164 | (setq Info-history (cdr Info-history)) | |
2165 | (goto-char (point-max)) | |
2166 | (while (re-search-backward cmd-desc nil t) | |
2167 | (setq where (cons (list Info-current-file | |
110d4e80 | 2168 | (match-string-no-properties 1) |
f0a8a3f1 RM |
2169 | 0) |
2170 | where))) | |
2171 | where))) | |
2172 | ||
2173 | ;;;###autoload | |
2174 | (defun Info-goto-emacs-command-node (command) | |
e0568e86 | 2175 | "Go to the Info node in the Emacs manual for command COMMAND. |
f88ab1c9 | 2176 | The command is found by looking up in Emacs manual's Command Index |
f57b2cd8 RS |
2177 | or in another manual found via COMMAND's `info-file' property or |
2178 | the variable `Info-file-list-for-emacs'." | |
f0a8a3f1 RM |
2179 | (interactive "CFind documentation for command: ") |
2180 | (or (commandp command) | |
2181 | (signal 'wrong-type-argument (list 'commandp command))) | |
2182 | (let ((where (Info-find-emacs-command-nodes command))) | |
2183 | (if where | |
2184 | (let ((num-matches (length where))) | |
2185 | ;; Get Info running, and pop to it in another window. | |
2186 | (save-window-excursion | |
2187 | (info)) | |
c5fe2ff1 RS |
2188 | ;; FIXME It would be cool if this could use a buffer other |
2189 | ;; than *info*. | |
f0a8a3f1 RM |
2190 | (pop-to-buffer "*info*") |
2191 | (Info-find-node (car (car where)) | |
2192 | (car (cdr (car where)))) | |
2193 | (if (> num-matches 1) | |
2194 | (progn | |
2195 | ;; Info-find-node already pushed (car where) onto | |
2196 | ;; Info-history. Put the other nodes that were found on | |
2197 | ;; the history. | |
2198 | (setq Info-history (nconc (cdr where) Info-history)) | |
8ab3e50b | 2199 | (message "Found %d other entr%s. Use %s to see %s." |
cedb118c RS |
2200 | (1- num-matches) |
2201 | (if (> num-matches 2) "ies" "y") | |
8ab3e50b | 2202 | (substitute-command-keys "\\[Info-last]") |
cedb118c | 2203 | (if (> num-matches 2) "them" "it"))))) |
e9b81433 | 2204 | (error "Couldn't find documentation for %s" command)))) |
f0a8a3f1 RM |
2205 | |
2206 | ;;;###autoload | |
2207 | (defun Info-goto-emacs-key-command-node (key) | |
2208 | "Go to the Info node in the Emacs manual the command bound to KEY, a string. | |
e0568e86 | 2209 | Interactively, if the binding is execute-extended-command, a command is read. |
f88ab1c9 | 2210 | The command is found by looking up in Emacs manual's Command Index |
f57b2cd8 RS |
2211 | or in another manual found via COMMAND's `info-file' property or |
2212 | the variable `Info-file-list-for-emacs'." | |
f0a8a3f1 RM |
2213 | (interactive "kFind documentation for key:") |
2214 | (let ((command (key-binding key))) | |
2215 | (cond ((null command) | |
9e5c2f50 | 2216 | (message "%s is undefined" (key-description key))) |
f0a8a3f1 RM |
2217 | ((and (interactive-p) |
2218 | (eq command 'execute-extended-command)) | |
2219 | (Info-goto-emacs-command-node | |
2220 | (read-command "Find documentation for command: "))) | |
2221 | (t | |
2222 | (Info-goto-emacs-command-node command))))) | |
552775bd | 2223 | \f |
bbed5c3f GM |
2224 | (defface Info-title-1-face |
2225 | '((t (:family "helv" :height 240 :weight bold))) | |
2226 | "Face for Info titles at level 1." | |
2227 | :group 'info) | |
2228 | ||
2229 | (defface Info-title-2-face | |
2230 | '((t (:family "helv" :height 180 :weight bold))) | |
2231 | "Face for Info titles at level 2." | |
2232 | :group 'info) | |
2233 | ||
2234 | (defface Info-title-3-face | |
2235 | '((t (:family "helv" :height 160 :weight bold))) | |
2236 | "Face for Info titles at level 3." | |
2237 | :group 'info) | |
2238 | ||
ded3e3d8 | 2239 | (defcustom Info-title-face-alist |
bbed5c3f GM |
2240 | '((?* (face (variable-pitch bold) display (height (+ 4)))) |
2241 | (?= (face (variable-pitch bold) display (height (+ 3)))) | |
2242 | (?- (face (variable-pitch bold) display (height (+ 2))))) | |
98d8273c | 2243 | "*Alist of face or list of faces to use for pseudo-underlined titles. |
ded3e3d8 RS |
2244 | The alist key is the character the title is underlined with (?*, ?= or ?-)." |
2245 | :type '(repeat (list character face face)) | |
2246 | :group 'info) | |
98d8273c | 2247 | |
552775bd RS |
2248 | (defun Info-fontify-node () |
2249 | (save-excursion | |
1bcedb3b RS |
2250 | (let ((buffer-read-only nil) |
2251 | (case-fold-search t)) | |
552775bd | 2252 | (goto-char (point-min)) |
35d2d241 RS |
2253 | (when (looking-at "^File: [^,: \t]+,?[ \t]+") |
2254 | (goto-char (match-end 0)) | |
2255 | (while | |
2256 | (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?") | |
2257 | (goto-char (match-end 0)) | |
2258 | (if (save-excursion | |
2259 | (goto-char (match-beginning 1)) | |
2260 | (save-match-data (looking-at "Node:"))) | |
2261 | (put-text-property (match-beginning 2) (match-end 2) | |
2262 | 'face 'info-node) | |
2263 | (put-text-property (match-beginning 2) (match-end 2) | |
2264 | 'face 'info-xref) | |
2265 | (put-text-property (match-beginning 2) (match-end 2) | |
2266 | 'mouse-face 'highlight)))) | |
552775bd | 2267 | (goto-char (point-min)) |
98d8273c KH |
2268 | (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$" |
2269 | nil t) | |
bbed5c3f GM |
2270 | (let ((c (preceding-char)) |
2271 | face) | |
2272 | (cond ((= c ?*) (setq face 'Info-title-1-face)) | |
2273 | ((= c ?=) (setq face 'Info-title-2-face)) | |
2274 | (t (setq face 'Info-title-3-face))) | |
2275 | (put-text-property (match-beginning 1) (match-end 1) | |
2276 | 'face face)) | |
93480d70 RS |
2277 | ;; This is a serious problem for trying to handle multiple |
2278 | ;; frame types at once. We want this text to be invisible | |
2279 | ;; on frames that can display the font above. | |
2280 | (if (memq (framep (selected-frame)) '(x pc w32)) | |
2281 | (put-text-property (match-end 1) (match-end 2) | |
2282 | 'invisible t))) | |
98d8273c | 2283 | (goto-char (point-min)) |
7757c476 | 2284 | (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t) |
552775bd RS |
2285 | (if (= (char-after (1- (match-beginning 0))) ?\") ; hack |
2286 | nil | |
2287 | (put-text-property (match-beginning 1) (match-end 1) | |
9a87b430 RS |
2288 | 'face 'info-xref) |
2289 | (put-text-property (match-beginning 1) (match-end 1) | |
2290 | 'mouse-face 'highlight))) | |
552775bd RS |
2291 | (goto-char (point-min)) |
2292 | (if (and (search-forward "\n* Menu:" nil t) | |
2293 | (not (string-match "\\<Index\\>" Info-current-node)) | |
2294 | ;; Don't take time to annotate huge menus | |
34a0a4ee | 2295 | (< (- (point-max) (point)) Info-fontify-maximum-menu-size)) |
552775bd | 2296 | (let ((n 0)) |
b37daea4 | 2297 | (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t) |
552775bd RS |
2298 | (setq n (1+ n)) |
2299 | (if (memq n '(5 9)) ; visual aids to help with 1-9 keys | |
2300 | (put-text-property (match-beginning 0) | |
2301 | (1+ (match-beginning 0)) | |
2302 | 'face 'info-menu-5)) | |
2303 | (put-text-property (match-beginning 1) (match-end 1) | |
35d2d241 | 2304 | 'face 'info-xref) |
9a87b430 RS |
2305 | (put-text-property (match-beginning 1) (match-end 1) |
2306 | 'mouse-face 'highlight)))) | |
552775bd | 2307 | (set-buffer-modified-p nil)))) |
c5fe2ff1 RS |
2308 | \f |
2309 | ||
2310 | ;; When an Info buffer is killed, make sure the associated tags buffer | |
2311 | ;; is killed too. | |
2312 | (defun Info-kill-buffer () | |
2313 | (and (eq major-mode 'Info-mode) | |
2314 | Info-tag-table-buffer | |
2315 | (kill-buffer Info-tag-table-buffer))) | |
2316 | ||
2317 | (add-hook 'kill-buffer-hook 'Info-kill-buffer) | |
3cb6768f EL |
2318 | |
2319 | ;;; Speedbar support: | |
2320 | ;; These functions permit speedbar to display the "tags" in the | |
2321 | ;; current info node. | |
96ee3f29 | 2322 | (eval-when-compile (require 'speedbar)) |
3cb6768f | 2323 | |
96ee3f29 KH |
2324 | (defvar Info-speedbar-key-map nil |
2325 | "Keymap used when in the info display mode.") | |
3cb6768f | 2326 | |
96ee3f29 KH |
2327 | (defun Info-install-speedbar-variables () |
2328 | "Install those variables used by speedbar to enhance Info." | |
2329 | (if Info-speedbar-key-map | |
2330 | nil | |
2331 | (setq Info-speedbar-key-map (speedbar-make-specialized-keymap)) | |
2332 | ||
2333 | ;; Basic tree features | |
2334 | (define-key Info-speedbar-key-map "e" 'speedbar-edit-line) | |
2335 | (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line) | |
2336 | (define-key Info-speedbar-key-map "+" 'speedbar-expand-line) | |
2337 | (define-key Info-speedbar-key-map "-" 'speedbar-contract-line) | |
2338 | ) | |
2339 | ||
2340 | (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items | |
2341 | Info-speedbar-key-map | |
2342 | Info-speedbar-hierarchy-buttons))) | |
3cb6768f EL |
2343 | |
2344 | (defvar Info-speedbar-menu-items | |
96ee3f29 KH |
2345 | '(["Browse Node" speedbar-edit-line t] |
2346 | ["Expand Node" speedbar-expand-line | |
2347 | (save-excursion (beginning-of-line) | |
2348 | (looking-at "[0-9]+: *.\\+. "))] | |
2349 | ["Contract Node" speedbar-contract-line | |
2350 | (save-excursion (beginning-of-line) | |
2351 | (looking-at "[0-9]+: *.-. "))] | |
2352 | ) | |
3cb6768f EL |
2353 | "Additional menu-items to add to speedbar frame.") |
2354 | ||
96ee3f29 KH |
2355 | ;; Make sure our special speedbar major mode is loaded |
2356 | (if (featurep 'speedbar) | |
2357 | (Info-install-speedbar-variables) | |
2358 | (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables)) | |
2359 | ||
2360 | ;;; Info hierarchy display method | |
2361 | ;;;###autoload | |
2362 | (defun Info-speedbar-browser () | |
2363 | "Initialize speedbar to display an info node browser. | |
2364 | This will add a speedbar major display mode." | |
2365 | (interactive) | |
2366 | (require 'speedbar) | |
2367 | ;; Make sure that speedbar is active | |
2368 | (speedbar-frame-mode 1) | |
2369 | ;; Now, throw us into Info mode on speedbar. | |
2370 | (speedbar-change-initial-expansion-list "Info") | |
2371 | ) | |
2372 | ||
2373 | (defun Info-speedbar-hierarchy-buttons (directory depth &optional node) | |
2374 | "Display an Info directory hierarchy in speedbar. | |
2375 | DIRECTORY is the current directory in the attached frame. | |
2376 | DEPTH is the current indentation depth. | |
2377 | NODE is an optional argument that is used to represent the | |
2378 | specific node to expand." | |
2379 | (if (and (not node) | |
2380 | (save-excursion (goto-char (point-min)) | |
1bcedb3b RS |
2381 | (let ((case-fold-search t)) |
2382 | (looking-at "Info Nodes:")))) | |
96ee3f29 KH |
2383 | ;; Update our "current node" maybe? |
2384 | nil | |
2385 | ;; We cannot use the generic list code, that depends on all leaves | |
2386 | ;; being known at creation time. | |
2387 | (if (not node) | |
2388 | (speedbar-with-writable (insert "Info Nodes:\n"))) | |
5fdc7997 EL |
2389 | (let ((completions nil) |
2390 | (cf (selected-frame))) | |
2391 | (select-frame speedbar-attached-frame) | |
2392 | (save-window-excursion | |
2393 | (setq completions | |
2394 | (Info-speedbar-fetch-file-nodes (or node '"(dir)top")))) | |
2395 | (select-frame cf) | |
96ee3f29 KH |
2396 | (if completions |
2397 | (speedbar-with-writable | |
2398 | (while completions | |
2399 | (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node | |
2400 | (cdr (car completions)) | |
2401 | (car (car completions)) | |
2402 | 'Info-speedbar-goto-node | |
2403 | (cdr (car completions)) | |
2404 | 'info-xref depth) | |
2405 | (setq completions (cdr completions))) | |
2406 | t) | |
2407 | nil)))) | |
2408 | ||
2409 | (defun Info-speedbar-goto-node (text node indent) | |
2410 | "When user clicks on TEXT, goto an info NODE. | |
2411 | The INDENT level is ignored." | |
2412 | (select-frame speedbar-attached-frame) | |
2413 | (let* ((buff (or (get-buffer "*info*") | |
2414 | (progn (info) (get-buffer "*info*")))) | |
2415 | (bwin (get-buffer-window buff 0))) | |
2416 | (if bwin | |
2417 | (progn | |
2418 | (select-window bwin) | |
2419 | (raise-frame (window-frame bwin))) | |
2420 | (if speedbar-power-click | |
2421 | (let ((pop-up-frames t)) (select-window (display-buffer buff))) | |
2422 | (select-frame speedbar-attached-frame) | |
2423 | (switch-to-buffer buff))) | |
2424 | (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node)) | |
2425 | (file (match-string 1 node)) | |
2426 | (node (match-string 2 node))) | |
2427 | (Info-find-node file node) | |
2428 | ;; If we do a find-node, and we were in info mode, restore | |
2429 | ;; the old default method. Once we are in info mode, it makes | |
2430 | ;; sense to return to whatever method the user was using before. | |
2431 | (if (string= speedbar-initial-expansion-list-name "Info") | |
2432 | (speedbar-change-initial-expansion-list | |
2433 | speedbar-previously-used-expansion-list-name))))) | |
2434 | ||
2435 | (defun Info-speedbar-expand-node (text token indent) | |
2436 | "Expand the node the user clicked on. | |
2437 | TEXT is the text of the button we clicked on, a + or - item. | |
2438 | TOKEN is data related to this node (NAME . FILE). | |
2439 | INDENT is the current indentation depth." | |
2440 | (cond ((string-match "+" text) ;we have to expand this file | |
2441 | (speedbar-change-expand-button-char ?-) | |
2442 | (if (speedbar-with-writable | |
2443 | (save-excursion | |
2444 | (end-of-line) (forward-char 1) | |
2445 | (Info-speedbar-hierarchy-buttons nil (1+ indent) token))) | |
2446 | (speedbar-change-expand-button-char ?-) | |
2447 | (speedbar-change-expand-button-char ??))) | |
2448 | ((string-match "-" text) ;we have to contract this node | |
2449 | (speedbar-change-expand-button-char ?+) | |
2450 | (speedbar-delete-subblock indent)) | |
2451 | (t (error "Ooops... not sure what to do"))) | |
2452 | (speedbar-center-buffer-smartly)) | |
2453 | ||
2454 | (defun Info-speedbar-fetch-file-nodes (nodespec) | |
2455 | "Fetch the subnodes from the info NODESPEC. | |
2456 | NODESPEC is a string of the form: (file)node. | |
2457 | Optional THISFILE represends the filename of" | |
2458 | (save-excursion | |
2459 | ;; Set up a buffer we can use to fake-out Info. | |
2460 | (set-buffer (get-buffer-create "*info-browse-tmp*")) | |
2461 | (if (not (equal major-mode 'Info-mode)) | |
2462 | (Info-mode)) | |
2463 | ;; Get the node into this buffer | |
2464 | (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec)) | |
2465 | (file (match-string 1 nodespec)) | |
2466 | (node (match-string 2 nodespec))) | |
2467 | (Info-find-node file node)) | |
2468 | ;; Scan the created buffer | |
2469 | (goto-char (point-min)) | |
2470 | (let ((completions nil) | |
1bcedb3b | 2471 | (case-fold-search t) |
96ee3f29 KH |
2472 | (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec) |
2473 | (match-string 1 nodespec)))) | |
2474 | ;; Always skip the first one... | |
2475 | (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t) | |
2476 | (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t) | |
2477 | (let ((name (match-string 1))) | |
2478 | (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.") | |
2479 | (setq name (cons name (match-string 1))) | |
2480 | (if (looking-at " *\\(([^)]+)\\)\\.") | |
2481 | (setq name (cons name (concat (match-string 1) "Top"))) | |
2482 | (if (looking-at " \\([^.]+\\).") | |
2483 | (setq name | |
2484 | (cons name (concat "(" thisfile ")" (match-string 1)))) | |
2485 | (setq name (cons name (concat "(" thisfile ")" name)))))) | |
2486 | (setq completions (cons name completions)))) | |
2487 | (nreverse completions)))) | |
2488 | ||
2489 | ;;; Info mode node listing | |
3cb6768f EL |
2490 | (defun Info-speedbar-buttons (buffer) |
2491 | "Create a speedbar display to help navigation in an Info file. | |
2492 | BUFFER is the buffer speedbar is requesting buttons for." | |
96ee3f29 | 2493 | (if (save-excursion (goto-char (point-min)) |
1bcedb3b RS |
2494 | (let ((case-fold-search t)) |
2495 | (not (looking-at "Info Nodes:")))) | |
96ee3f29 KH |
2496 | (erase-buffer)) |
2497 | (Info-speedbar-hierarchy-buttons nil 0) | |
2498 | ) | |
49116ac0 JB |
2499 | |
2500 | (provide 'info) | |
2501 | ||
1a06eabd | 2502 | ;;; info.el ends here |