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