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