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