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