325
|
1 ;; Info package for Emacs -- could use a "create node" feature.
|
|
2 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; This file is part of GNU Emacs.
|
|
5
|
|
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 ;; it under the terms of the GNU General Public License as published by
|
|
8 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
9 ;; any later version.
|
|
10
|
|
11 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 ;; GNU General Public License for more details.
|
|
15
|
|
16 ;; You should have received a copy of the GNU General Public License
|
|
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 (defvar Info-history nil
|
|
21 "List of info nodes user has visited.
|
|
22 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
|
|
23
|
|
24 (defvar Info-enable-edit nil
|
|
25 "Non-nil means the \\<info-mode-map>\\[Info-edit] command in Info can edit the current node.")
|
|
26
|
|
27 (defvar Info-enable-active-nodes t
|
|
28 "Non-nil allows Info to execute Lisp code associated with nodes.
|
|
29 The Lisp code is executed when the node is selected.")
|
|
30
|
540
|
31 (defvar Info-default-directory-list nil
|
|
32 "List of default directories to search for Info documentation files.
|
|
33 This value is used as the default for `Info-directory-list'. It is set
|
|
34 in paths.el.")
|
|
35
|
|
36 (defvar Info-directory-list nil
|
325
|
37 "List of directories to search for Info documentation files.
|
540
|
38 nil means not yet initialized. In this case, Info uses the environment
|
|
39 variable INFODIR to initialize it, or `Info-default-directory-list'
|
|
40 if there is no INFODIR variable in the environment.")
|
325
|
41
|
|
42 (defvar Info-current-file nil
|
|
43 "Info file that Info is now looking at, or nil.")
|
|
44
|
|
45 (defvar Info-current-subfile nil
|
|
46 "Info subfile that is actually in the *info* buffer now,
|
|
47 or nil if current info file is not split into subfiles.")
|
|
48
|
|
49 (defvar Info-current-node nil
|
|
50 "Name of node that Info is now looking at, or nil.")
|
|
51
|
|
52 (defvar Info-tag-table-marker (make-marker)
|
|
53 "Marker pointing at beginning of current Info file's tag table.
|
|
54 Marker points nowhere if file has no tag table.")
|
|
55
|
|
56 ;;;###autoload
|
|
57 (defun info (&optional file)
|
|
58 "Enter Info, the documentation browser.
|
|
59 Optional argument FILE specifies the file to examine;
|
|
60 the default is the top-level directory of Info.
|
|
61
|
|
62 In interactive use, a prefix argument directs this command
|
|
63 to read a file name from the minibuffer."
|
|
64 (interactive (if current-prefix-arg
|
|
65 (list (read-file-name "Info file name: " nil nil t))))
|
540
|
66 (or Info-directory-list
|
|
67 (setq Info-directory-list
|
|
68 (let ((path (getenv "INFOPATH")))
|
|
69 (if path
|
|
70 (let ((list nil)
|
|
71 idx)
|
|
72 (while (> (length path) 0)
|
|
73 (setq idx (or (string-match ":" path) (length path))
|
|
74 list (cons (substring path 0 idx) list)
|
|
75 path (substring path (min (1+ idx)
|
|
76 (length path)))))
|
|
77 (nreverse list))
|
|
78 Info-default-directory-list))))
|
325
|
79 (if file
|
|
80 (Info-goto-node (concat "(" file ")"))
|
|
81 (if (get-buffer "*info*")
|
|
82 (switch-to-buffer "*info*")
|
|
83 (Info-directory))))
|
|
84
|
|
85 ;; Go to an info node specified as separate filename and nodename.
|
|
86 ;; no-going-back is non-nil if recovering from an error in this function;
|
|
87 ;; it says do not attempt further (recursive) error recovery.
|
|
88 (defun Info-find-node (filename nodename &optional no-going-back)
|
|
89 ;; Convert filename to lower case if not found as specified.
|
|
90 ;; Expand it.
|
|
91 (if filename
|
|
92 (let (temp temp-downcase found)
|
|
93 (setq filename (substitute-in-file-name filename))
|
|
94 (let ((dirs (if (string-match "^\\./" filename)
|
|
95 ;; If specified name starts with `./'
|
|
96 ;; then just try current directory.
|
|
97 '("./")
|
|
98 Info-directory-list)))
|
|
99 ;; Search the directory list for file FILENAME.
|
|
100 (while (and dirs (not found))
|
|
101 (setq temp (expand-file-name filename (car dirs)))
|
|
102 (setq temp-downcase
|
|
103 (expand-file-name (downcase filename) (car dirs)))
|
|
104 ;; Try several variants of specified name.
|
|
105 ;; Try downcasing, appending `.info', or both.
|
|
106 (cond ((file-exists-p temp)
|
|
107 (setq found temp))
|
|
108 ((file-exists-p temp-downcase)
|
|
109 (setq found temp-downcase))
|
|
110 ((file-exists-p (concat temp ".info"))
|
|
111 (setq found (concat temp ".info")))
|
|
112 ((file-exists-p (concat temp-downcase ".info"))
|
|
113 (setq found (concat temp-downcase ".info"))))
|
|
114 (setq dirs (cdr dirs))))
|
|
115 (if found
|
|
116 (setq filename found)
|
|
117 (error "Info file %s does not exist" filename))))
|
|
118 ;; Record the node we are leaving.
|
|
119 (if (and Info-current-file (not no-going-back))
|
|
120 (setq Info-history
|
|
121 (cons (list Info-current-file Info-current-node (point))
|
|
122 Info-history)))
|
|
123 ;; Go into info buffer.
|
|
124 (switch-to-buffer "*info*")
|
|
125 (buffer-flush-undo (current-buffer))
|
|
126 (or (eq major-mode 'Info-mode)
|
|
127 (Info-mode))
|
|
128 (widen)
|
|
129 (setq Info-current-node nil)
|
|
130 (unwind-protect
|
|
131 (progn
|
|
132 ;; Switch files if necessary
|
|
133 (or (null filename)
|
|
134 (equal Info-current-file filename)
|
|
135 (let ((buffer-read-only nil))
|
|
136 (setq Info-current-file nil
|
|
137 Info-current-subfile nil
|
|
138 buffer-file-name nil)
|
|
139 (erase-buffer)
|
|
140 (insert-file-contents filename t)
|
|
141 (set-buffer-modified-p nil)
|
|
142 (setq default-directory (file-name-directory filename))
|
|
143 ;; See whether file has a tag table. Record the location if yes.
|
|
144 (set-marker Info-tag-table-marker nil)
|
|
145 (goto-char (point-max))
|
|
146 (forward-line -8)
|
|
147 (or (equal nodename "*")
|
|
148 (not (search-forward "\^_\nEnd tag table\n" nil t))
|
|
149 (let (pos)
|
|
150 ;; We have a tag table. Find its beginning.
|
|
151 ;; Is this an indirect file?
|
|
152 (search-backward "\nTag table:\n")
|
|
153 (setq pos (point))
|
|
154 (if (save-excursion
|
|
155 (forward-line 2)
|
|
156 (looking-at "(Indirect)\n"))
|
|
157 ;; It is indirect. Copy it to another buffer
|
|
158 ;; and record that the tag table is in that buffer.
|
|
159 (save-excursion
|
|
160 (let ((buf (current-buffer)))
|
|
161 (set-buffer (get-buffer-create " *info tag table*"))
|
|
162 (buffer-flush-undo (current-buffer))
|
|
163 (setq case-fold-search t)
|
|
164 (erase-buffer)
|
|
165 (insert-buffer-substring buf)
|
|
166 (set-marker Info-tag-table-marker
|
|
167 (match-end 0))))
|
|
168 (set-marker Info-tag-table-marker pos))))
|
|
169 (setq Info-current-file
|
|
170 (file-name-sans-versions buffer-file-name))))
|
|
171 (if (equal nodename "*")
|
|
172 (progn (setq Info-current-node nodename)
|
|
173 (Info-set-mode-line))
|
|
174 ;; Search file for a suitable node.
|
|
175 ;; First get advice from tag table if file has one.
|
|
176 ;; Also, if this is an indirect info file,
|
|
177 ;; read the proper subfile into this buffer.
|
|
178 (let ((guesspos (point-min)))
|
|
179 (if (marker-position Info-tag-table-marker)
|
|
180 (save-excursion
|
|
181 (set-buffer (marker-buffer Info-tag-table-marker))
|
|
182 (goto-char Info-tag-table-marker)
|
|
183 (if (search-forward (concat "Node: " nodename "\177") nil t)
|
|
184 (progn
|
|
185 (setq guesspos (read (current-buffer)))
|
|
186 ;; If this is an indirect file,
|
|
187 ;; determine which file really holds this node
|
|
188 ;; and read it in.
|
|
189 (if (not (eq (current-buffer) (get-buffer "*info*")))
|
|
190 (setq guesspos
|
|
191 (Info-read-subfile guesspos))))
|
|
192 (error "No such node: \"%s\"" nodename))))
|
|
193 (goto-char (max (point-min) (- guesspos 1000))))
|
|
194 ;; Now search from our advised position (or from beg of buffer)
|
|
195 ;; to find the actual node.
|
|
196 (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]")))
|
|
197 (catch 'foo
|
|
198 (while (search-forward "\n\^_" nil t)
|
|
199 (forward-line 1)
|
|
200 (let ((beg (point)))
|
|
201 (forward-line 1)
|
|
202 (if (re-search-backward regexp beg t)
|
|
203 (throw 'foo t))))
|
|
204 (error "No such node: %s" nodename)))
|
|
205 (Info-select-node)))
|
|
206 ;; If we did not finish finding the specified node,
|
|
207 ;; go back to the previous one.
|
|
208 (or Info-current-node no-going-back
|
|
209 (let ((hist (car Info-history)))
|
|
210 (setq Info-history (cdr Info-history))
|
|
211 (Info-find-node (nth 0 hist) (nth 1 hist) t)
|
|
212 (goto-char (nth 2 hist)))))
|
|
213 (goto-char (point-min)))
|
|
214
|
|
215 (defun Info-read-subfile (nodepos)
|
|
216 (set-buffer (marker-buffer Info-tag-table-marker))
|
|
217 (goto-char (point-min))
|
|
218 (search-forward "\n\^_")
|
|
219 (let (lastfilepos
|
|
220 lastfilename)
|
|
221 (forward-line 2)
|
|
222 (catch 'foo
|
|
223 (while (not (looking-at "\^_"))
|
|
224 (if (not (eolp))
|
|
225 (let ((beg (point))
|
|
226 thisfilepos thisfilename)
|
|
227 (search-forward ": ")
|
|
228 (setq thisfilename (buffer-substring beg (- (point) 2)))
|
|
229 (setq thisfilepos (read (current-buffer)))
|
|
230 ;; read in version 19 stops at the end of number.
|
|
231 ;; Advance to the next line.
|
|
232 (forward-line 1)
|
|
233 (if (> thisfilepos nodepos)
|
|
234 (throw 'foo t))
|
|
235 (setq lastfilename thisfilename)
|
|
236 (setq lastfilepos thisfilepos))
|
|
237 (forward-line 1))))
|
|
238 (set-buffer (get-buffer "*info*"))
|
|
239 (or (equal Info-current-subfile lastfilename)
|
|
240 (let ((buffer-read-only nil))
|
|
241 (setq buffer-file-name nil)
|
|
242 (widen)
|
|
243 (erase-buffer)
|
|
244 (insert-file-contents lastfilename)
|
|
245 (set-buffer-modified-p nil)
|
|
246 (setq Info-current-subfile lastfilename)))
|
|
247 (goto-char (point-min))
|
|
248 (search-forward "\n\^_")
|
|
249 (+ (- nodepos lastfilepos) (point))))
|
|
250
|
|
251 ;; Select the info node that point is in.
|
|
252 (defun Info-select-node ()
|
|
253 (save-excursion
|
|
254 ;; Find beginning of node.
|
|
255 (search-backward "\n\^_")
|
|
256 (forward-line 2)
|
|
257 ;; Get nodename spelled as it is in the node.
|
|
258 (re-search-forward "Node:[ \t]*")
|
|
259 (setq Info-current-node
|
|
260 (buffer-substring (point)
|
|
261 (progn
|
|
262 (skip-chars-forward "^,\t\n")
|
|
263 (point))))
|
|
264 (Info-set-mode-line)
|
|
265 ;; Find the end of it, and narrow.
|
|
266 (beginning-of-line)
|
|
267 (let (active-expression)
|
|
268 (narrow-to-region (point)
|
|
269 (if (re-search-forward "\n[\^_\f]" nil t)
|
|
270 (prog1
|
|
271 (1- (point))
|
|
272 (if (looking-at "[\n\^_\f]*execute: ")
|
|
273 (progn
|
|
274 (goto-char (match-end 0))
|
|
275 (setq active-expression
|
|
276 (read (current-buffer))))))
|
|
277 (point-max)))
|
|
278 (if Info-enable-active-nodes (eval active-expression)))))
|
|
279
|
|
280 (defun Info-set-mode-line ()
|
|
281 (setq mode-line-buffer-identification
|
|
282 (concat
|
|
283 "Info: ("
|
|
284 (if Info-current-file
|
|
285 (file-name-nondirectory Info-current-file)
|
|
286 "")
|
|
287 ")"
|
|
288 (or Info-current-node ""))))
|
|
289
|
|
290 ;; Go to an info node specified with a filename-and-nodename string
|
|
291 ;; of the sort that is found in pointers in nodes.
|
|
292
|
|
293 (defun Info-goto-node (nodename)
|
|
294 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
|
|
295 (interactive "sGoto node: ")
|
|
296 (let (filename)
|
|
297 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
|
|
298 nodename)
|
|
299 (setq filename (if (= (match-beginning 1) (match-end 1))
|
|
300 ""
|
|
301 (substring nodename (match-beginning 2) (match-end 2)))
|
|
302 nodename (substring nodename (match-beginning 3) (match-end 3)))
|
|
303 (let ((trim (string-match "\\s *\\'" filename)))
|
|
304 (if trim (setq filename (substring filename 0 trim))))
|
|
305 (let ((trim (string-match "\\s *\\'" nodename)))
|
|
306 (if trim (setq nodename (substring nodename 0 trim))))
|
|
307 (Info-find-node (if (equal filename "") nil filename)
|
|
308 (if (equal nodename "") "Top" nodename))))
|
|
309
|
540
|
310 (defun Info-restore-point (hl)
|
|
311 "If this node has been visited, restore the point value when we left."
|
|
312 (if hl
|
|
313 (if (and (equal (nth 0 (car hl)) Info-current-file)
|
|
314 (equal (nth 1 (car hl)) Info-current-node))
|
|
315 (goto-char (nth 2 (car hl)))
|
|
316 (Info-restore-point (cdr hl)))))
|
|
317
|
325
|
318 (defvar Info-last-search nil
|
|
319 "Default regexp for \\<info-mode-map>\\[Info-search] command to search for.")
|
|
320
|
|
321 (defun Info-search (regexp)
|
|
322 "Search for REGEXP, starting from point, and select node it's found in."
|
|
323 (interactive "sSearch (regexp): ")
|
|
324 (if (equal regexp "")
|
|
325 (setq regexp Info-last-search)
|
|
326 (setq Info-last-search regexp))
|
|
327 (let ((found ()) current
|
|
328 (onode Info-current-node)
|
|
329 (ofile Info-current-file)
|
|
330 (opoint (point))
|
|
331 (osubfile Info-current-subfile))
|
|
332 (save-excursion
|
|
333 (save-restriction
|
|
334 (widen)
|
|
335 (if (null Info-current-subfile)
|
|
336 (progn (re-search-forward regexp) (setq found (point)))
|
|
337 (condition-case err
|
|
338 (progn (re-search-forward regexp) (setq found (point)))
|
|
339 (search-failed nil)))))
|
|
340 (if (not found) ;can only happen in subfile case -- else would have erred
|
|
341 (unwind-protect
|
|
342 (let ((list ()))
|
|
343 (set-buffer (marker-buffer Info-tag-table-marker))
|
|
344 (goto-char (point-min))
|
|
345 (search-forward "\n\^_\nIndirect:")
|
|
346 (save-restriction
|
|
347 (narrow-to-region (point)
|
|
348 (progn (search-forward "\n\^_")
|
|
349 (1- (point))))
|
|
350 (goto-char (point-min))
|
|
351 (search-forward (concat "\n" osubfile ": "))
|
|
352 (beginning-of-line)
|
|
353 (while (not (eobp))
|
|
354 (re-search-forward "\\(^.*\\): [0-9]+$")
|
|
355 (goto-char (+ (match-end 1) 2))
|
|
356 (setq list (cons (cons (read (current-buffer))
|
|
357 (buffer-substring (match-beginning 1)
|
|
358 (match-end 1)))
|
|
359 list))
|
|
360 (goto-char (1+ (match-end 0))))
|
|
361 (setq list (nreverse list)
|
|
362 current (car (car list))
|
|
363 list (cdr list)))
|
|
364 (while list
|
|
365 (message "Searching subfile %s..." (cdr (car list)))
|
|
366 (Info-read-subfile (car (car list)))
|
|
367 (setq list (cdr list))
|
|
368 (goto-char (point-min))
|
|
369 (if (re-search-forward regexp nil t)
|
|
370 (setq found (point) list ())))
|
|
371 (if found
|
|
372 (message "")
|
|
373 (signal 'search-failed (list regexp))))
|
|
374 (if (not found)
|
|
375 (progn (Info-read-subfile opoint)
|
|
376 (goto-char opoint)
|
|
377 (Info-select-node)))))
|
|
378 (widen)
|
|
379 (goto-char found)
|
|
380 (Info-select-node)
|
|
381 (or (and (equal onode Info-current-node)
|
|
382 (equal ofile Info-current-file))
|
|
383 (setq Info-history (cons (list ofile onode opoint)
|
|
384 Info-history)))))
|
|
385
|
|
386 ;; Extract the value of the node-pointer named NAME.
|
|
387 ;; If there is none, use ERRORNAME in the error message;
|
|
388 ;; if ERRORNAME is nil, just return nil.
|
|
389 (defun Info-extract-pointer (name &optional errorname)
|
|
390 (save-excursion
|
|
391 (goto-char (point-min))
|
|
392 (forward-line 1)
|
|
393 (if (re-search-backward (concat name ":") nil t)
|
|
394 (progn
|
|
395 (goto-char (match-end 0))
|
|
396 (Info-following-node-name))
|
|
397 (if (eq errorname t)
|
|
398 nil
|
|
399 (error (concat "Node has no " (capitalize (or errorname name))))))))
|
|
400
|
|
401 (defun Info-following-node-name (&optional allowedchars)
|
|
402 (skip-chars-forward " \t")
|
|
403 (buffer-substring
|
|
404 (point)
|
|
405 (progn
|
|
406 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
|
|
407 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
|
|
408 (if (looking-at "(")
|
|
409 (skip-chars-forward "^)")))
|
|
410 (skip-chars-backward " ")
|
|
411 (point))))
|
|
412
|
|
413 (defun Info-next ()
|
|
414 "Go to the next node of this node."
|
|
415 (interactive)
|
|
416 (Info-goto-node (Info-extract-pointer "next")))
|
|
417
|
|
418 (defun Info-prev ()
|
|
419 "Go to the previous node of this node."
|
|
420 (interactive)
|
|
421 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
|
|
422
|
|
423 (defun Info-up ()
|
|
424 "Go to the superior node of this node."
|
|
425 (interactive)
|
540
|
426 (Info-goto-node (Info-extract-pointer "up"))
|
|
427 (Info-restore-point Info-history))
|
325
|
428
|
|
429 (defun Info-last ()
|
|
430 "Go back to the last node visited."
|
|
431 (interactive)
|
|
432 (or Info-history
|
|
433 (error "This is the first Info node you looked at"))
|
|
434 (let (filename nodename opoint)
|
|
435 (setq filename (car (car Info-history)))
|
|
436 (setq nodename (car (cdr (car Info-history))))
|
|
437 (setq opoint (car (cdr (cdr (car Info-history)))))
|
|
438 (setq Info-history (cdr Info-history))
|
|
439 (Info-find-node filename nodename)
|
|
440 (setq Info-history (cdr Info-history))
|
|
441 (goto-char opoint)))
|
|
442
|
|
443 (defun Info-directory ()
|
|
444 "Go to the Info directory node."
|
|
445 (interactive)
|
|
446 (Info-find-node "dir" "top"))
|
|
447
|
|
448 (defun Info-follow-reference (footnotename)
|
|
449 "Follow cross reference named NAME to the node it refers to.
|
|
450 NAME may be an abbreviation of the reference name."
|
|
451 (interactive
|
|
452 (let ((completion-ignore-case t)
|
|
453 completions default (start-point (point)) str i)
|
|
454 (save-excursion
|
|
455 (goto-char (point-min))
|
|
456 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
|
|
457 (setq str (buffer-substring
|
|
458 (match-beginning 1)
|
|
459 (1- (point))))
|
|
460 ;; See if this one should be the default.
|
|
461 (and (null default)
|
|
462 (< (match-beginning 0) start-point)
|
|
463 (<= start-point (point))
|
|
464 (setq default t))
|
|
465 (setq i 0)
|
|
466 (while (setq i (string-match "[ \n\t]+" str i))
|
|
467 (setq str (concat (substring str 0 i) " "
|
|
468 (substring str (match-end 0))))
|
|
469 (setq i (1+ i)))
|
|
470 ;; Record as a completion and perhaps as default.
|
|
471 (if (eq default t) (setq default str))
|
|
472 (setq completions
|
|
473 (cons (cons str nil)
|
|
474 completions))))
|
|
475 (if completions
|
|
476 (list (completing-read (if default
|
|
477 (concat "Follow reference named: ("
|
|
478 default ") ")
|
|
479 "Follow reference named: ")
|
|
480 completions default t))
|
|
481 (error "No cross-references in this node"))))
|
|
482 (let (target beg i (str (concat "\\*note " footnotename)))
|
|
483 (while (setq i (string-match " " str i))
|
|
484 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
|
|
485 (setq i (+ i 6)))
|
|
486 (save-excursion
|
|
487 (goto-char (point-min))
|
|
488 (or (re-search-forward str nil t)
|
|
489 (error "No cross-reference named %s" footnotename))
|
|
490 (goto-char (+ (match-beginning 0) 5))
|
|
491 (setq target
|
|
492 (Info-extract-menu-node-name "Bad format cross reference" t)))
|
|
493 (while (setq i (string-match "[ \t\n]+" target i))
|
|
494 (setq target (concat (substring target 0 i) " "
|
|
495 (substring target (match-end 0))))
|
|
496 (setq i (+ i 1)))
|
|
497 (Info-goto-node target)))
|
|
498
|
|
499 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
|
|
500 (skip-chars-forward " \t\n")
|
|
501 (let ((beg (point))
|
|
502 str i)
|
|
503 (skip-chars-forward "^:")
|
|
504 (forward-char 1)
|
|
505 (setq str
|
|
506 (if (looking-at ":")
|
|
507 (buffer-substring beg (1- (point)))
|
|
508 (skip-chars-forward " \t\n")
|
|
509 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
|
|
510 (while (setq i (string-match "\n" str i))
|
|
511 (aset str i ?\ ))
|
|
512 str))
|
|
513
|
|
514 (defun Info-menu-item-sequence (list)
|
|
515 (while list
|
|
516 (Info-menu-item (car list))
|
|
517 (setq list (cdr list))))
|
|
518
|
|
519 (defun Info-menu (menu-item)
|
|
520 "Go to node for menu item named (or abbreviated) NAME.
|
|
521 Completion is allowed, and the menu item point is on is the default."
|
|
522 (interactive
|
|
523 (let ((completions '())
|
|
524 ;; If point is within a menu item, use that item as the default
|
|
525 (default nil)
|
|
526 (p (point))
|
|
527 (last nil))
|
|
528 (save-excursion
|
|
529 (goto-char (point-min))
|
|
530 (if (not (search-forward "\n* menu:" nil t))
|
|
531 (error "No menu in this node"))
|
|
532 (while (re-search-forward
|
|
533 "\n\\* \\([^:\t\n]*\\):" nil t)
|
|
534 (if (and (null default)
|
|
535 (prog1 (if last (< last p) nil)
|
|
536 (setq last (match-beginning 0)))
|
|
537 (<= p last))
|
|
538 (setq default (car (car completions))))
|
|
539 (setq completions (cons (cons (buffer-substring
|
|
540 (match-beginning 1)
|
|
541 (match-end 1))
|
|
542 (match-beginning 1))
|
|
543 completions)))
|
|
544 (if (and (null default) last
|
|
545 (< last p)
|
|
546 (<= p (progn (end-of-line) (point))))
|
|
547 (setq default (car (car completions)))))
|
|
548 (let ((item nil))
|
|
549 (while (null item)
|
|
550 (setq item (let ((completion-ignore-case t))
|
|
551 (completing-read (if default
|
|
552 (format "Menu item (default %s): "
|
|
553 default)
|
|
554 "Menu item: ")
|
|
555 completions nil t)))
|
540
|
556 ;; we rely on the fact that completing-read accepts an input
|
|
557 ;; of "" even when the require-match argument is true and ""
|
|
558 ;; is not a valid possibility
|
325
|
559 (if (string= item "")
|
|
560 (if default
|
|
561 (setq item default)
|
|
562 ;; ask again
|
|
563 (setq item nil))))
|
|
564 (list item))))
|
|
565 ;; there is a problem here in that if several menu items have the same
|
|
566 ;; name you can only go to the node of the first with this command.
|
|
567 (Info-goto-node (Info-extract-menu-item menu-item)))
|
|
568
|
|
569 (defun Info-extract-menu-item (menu-item)
|
|
570 (setq menu-item (regexp-quote menu-item))
|
|
571 (save-excursion
|
|
572 (goto-char (point-min))
|
|
573 (or (search-forward "\n* menu:" nil t)
|
|
574 (error "No menu in this node"))
|
|
575 (or (re-search-forward (concat "\n* " menu-item ":") nil t)
|
|
576 (re-search-forward (concat "\n* " menu-item) nil t)
|
|
577 (error "No such item in menu"))
|
|
578 (beginning-of-line)
|
|
579 (forward-char 2)
|
|
580 (Info-extract-menu-node-name)))
|
|
581
|
|
582 ;; If COUNT is nil, use the last item in the menu.
|
|
583 (defun Info-extract-menu-counting (count)
|
|
584 (save-excursion
|
|
585 (goto-char (point-min))
|
|
586 (or (search-forward "\n* menu:" nil t)
|
|
587 (error "No menu in this node"))
|
|
588 (if count
|
|
589 (or (search-forward "\n* " nil t count)
|
|
590 (error "Too few items in menu"))
|
|
591 (while (search-forward "\n* " nil t)
|
|
592 nil))
|
|
593 (Info-extract-menu-node-name)))
|
|
594
|
|
595 (defun Info-first-menu-item ()
|
|
596 "Go to the node of the first menu item."
|
|
597 (interactive)
|
|
598 (Info-goto-node (Info-extract-menu-counting 1)))
|
|
599
|
|
600 (defun Info-second-menu-item ()
|
|
601 "Go to the node of the second menu item."
|
|
602 (interactive)
|
|
603 (Info-goto-node (Info-extract-menu-counting 2)))
|
|
604
|
|
605 (defun Info-third-menu-item ()
|
|
606 "Go to the node of the third menu item."
|
|
607 (interactive)
|
|
608 (Info-goto-node (Info-extract-menu-counting 3)))
|
|
609
|
|
610 (defun Info-fourth-menu-item ()
|
|
611 "Go to the node of the fourth menu item."
|
|
612 (interactive)
|
|
613 (Info-goto-node (Info-extract-menu-counting 4)))
|
|
614
|
|
615 (defun Info-fifth-menu-item ()
|
|
616 "Go to the node of the fifth menu item."
|
|
617 (interactive)
|
|
618 (Info-goto-node (Info-extract-menu-counting 5)))
|
|
619
|
|
620 (defun Info-top-node ()
|
|
621 "Go to the Top node of this file."
|
|
622 (interactive)
|
|
623 (Info-goto-node "Top"))
|
|
624
|
|
625 (defun Info-final-node ()
|
|
626 "Go to the final node in this file."
|
|
627 (interactive)
|
|
628 (Info-goto-node "Top")
|
|
629 (let (Info-history)
|
|
630 ;; Go to the last node in the menu of Top.
|
|
631 (Info-goto-node (Info-extract-menu-counting nil))
|
|
632 ;; If the last node in the menu is not last in pointer structure,
|
|
633 ;; move forward until we can't go any farther.
|
|
634 (while (Info-forward-node t t) nil)
|
|
635 ;; Then keep moving down to last subnode, unless we reach an index.
|
|
636 (while (and (not (string-match "\\<index\\>" Info-current-node))
|
|
637 (save-excursion (search-forward "\n* Menu:" nil t)))
|
|
638 (Info-goto-node (Info-extract-menu-counting nil)))))
|
|
639
|
|
640 (defun Info-forward-node (&optional not-down no-error)
|
|
641 "Go forward one node, considering all nodes as forming one sequence."
|
|
642 (interactive)
|
|
643 (goto-char (point-min))
|
|
644 (forward-line 1)
|
|
645 ;; three possibilities, in order of priority:
|
|
646 ;; 1. next node is in a menu in this node (but not in an index)
|
|
647 ;; 2. next node is next at same level
|
|
648 ;; 3. next node is up and next
|
|
649 (cond ((and (not not-down)
|
|
650 (save-excursion (search-forward "\n* menu:" nil t))
|
|
651 (not (string-match "\\<index\\>" Info-current-node)))
|
|
652 (Info-first-menu-item)
|
|
653 t)
|
|
654 ((save-excursion (search-backward "next:" nil t))
|
|
655 (Info-next)
|
|
656 t)
|
|
657 ((and (save-excursion (search-backward "up:" nil t))
|
|
658 (not (equal (downcase (Info-extract-pointer "up")) "top")))
|
|
659 (let ((old-node Info-current-node))
|
|
660 (Info-up)
|
|
661 (let (Info-history success)
|
|
662 (unwind-protect
|
|
663 (setq success (Info-forward-node t no-error))
|
|
664 (or success (Info-goto-node old-node))))))
|
|
665 (no-error nil)
|
|
666 (t (error "No pointer forward from this node"))))
|
|
667
|
|
668 (defun Info-backward-node ()
|
|
669 "Go backward one node, considering all nodes as forming one sequence."
|
|
670 (interactive)
|
|
671 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
|
|
672 (upnode (Info-extract-pointer "up" t)))
|
|
673 (cond ((and upnode (string-match "(" upnode))
|
|
674 (error "First node in file"))
|
|
675 ((and upnode (or (null prevnode)
|
|
676 (equal (downcase prevnode) (downcase upnode))))
|
|
677 (Info-up))
|
|
678 (prevnode
|
|
679 ;; If we move back at the same level,
|
|
680 ;; go down to find the last subnode*.
|
|
681 (Info-prev)
|
|
682 (let (Info-history)
|
|
683 (while (and (not (string-match "\\<index\\>" Info-current-node))
|
|
684 (save-excursion (search-forward "\n* Menu:" nil t)))
|
|
685 (Info-goto-node (Info-extract-menu-counting nil)))))
|
|
686 (t
|
|
687 (error "No pointer backward from this node")))))
|
|
688
|
|
689 (defun Info-exit ()
|
|
690 "Exit Info by selecting some other buffer."
|
|
691 (interactive)
|
|
692 (switch-to-buffer (prog1 (other-buffer (current-buffer))
|
|
693 (bury-buffer (current-buffer)))))
|
|
694
|
|
695 (defun Info-undefined ()
|
|
696 "Make command be undefined in Info."
|
|
697 (interactive)
|
|
698 (ding))
|
|
699
|
|
700 (defun Info-help ()
|
|
701 "Enter the Info tutorial."
|
|
702 (interactive)
|
|
703 (delete-other-windows)
|
|
704 (Info-find-node "info"
|
|
705 (if (< (window-height) 23)
|
|
706 "Help-Small-Screen"
|
|
707 "Help")))
|
|
708
|
|
709 (defun Info-summary ()
|
|
710 "Display a brief summary of all Info commands."
|
|
711 (interactive)
|
|
712 (save-window-excursion
|
|
713 (switch-to-buffer "*Help*")
|
|
714 (erase-buffer)
|
|
715 (insert (documentation 'Info-mode))
|
|
716 (goto-char (point-min))
|
|
717 (let (ch flag)
|
|
718 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
|
|
719 (message (if flag "Type Space to see more"
|
|
720 "Type Space to return to Info"))
|
|
721 (if (/= ?\ (setq ch (read-char)))
|
|
722 (progn (setq unread-command-char ch) nil)
|
|
723 flag))
|
|
724 (scroll-up)))))
|
|
725
|
|
726 (defun Info-get-token (pos start all &optional errorstring)
|
|
727 "Return the token around POS,
|
|
728 POS must be somewhere inside the token
|
|
729 START is a regular expression which will match the
|
|
730 beginning of the tokens delimited string
|
|
731 ALL is a regular expression with a single
|
|
732 parenthized subpattern which is the token to be
|
|
733 returned. E.g. '{\(.*\)}' would return any string
|
|
734 enclosed in braces around POS.
|
|
735 SIG optional fourth argument, controls action on no match
|
|
736 nil: return nil
|
|
737 t: beep
|
|
738 a string: signal an error, using that string."
|
|
739 (save-excursion
|
|
740 (goto-char pos)
|
|
741 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
|
|
742 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
|
|
743 (not (and (<= (match-beginning 0) pos)
|
|
744 (> (match-end 0) pos)))))
|
|
745 (if (and (<= (match-beginning 0) pos)
|
|
746 (> (match-end 0) pos))
|
|
747 (buffer-substring (match-beginning 1) (match-end 1))
|
|
748 (cond ((null errorstring)
|
|
749 nil)
|
|
750 ((eq errorstring t)
|
|
751 (beep)
|
|
752 nil)
|
|
753 (t
|
|
754 (error "No %s around position %d" errorstring pos))))))
|
|
755
|
540
|
756 (defun Info-follow-nearest-node (click)
|
325
|
757 "\\<Info-mode-map>Follow a node reference near point. Like \\[Info-menu], \\Info-follow-reference], \\[Info-next], \\[Info-previous] or \\Info-up] command.
|
|
758 At end of the node's text, moves to the next node."
|
540
|
759 (interactive "K")
|
|
760 (let* ((relative-coordinates (coordinates-in-window-p (mouse-coords click)
|
325
|
761 (selected-window)))
|
|
762 (rel-x (car relative-coordinates))
|
540
|
763 (rel-y (cdr relative-coordinates)))
|
325
|
764 (move-to-window-line rel-y)
|
|
765 (move-to-column rel-x))
|
|
766 (let (node)
|
|
767 (cond
|
|
768 ((setq node (Info-get-token (point) "\\*note " "\\*note \\([^:]*\\):" t))
|
|
769 (Info-follow-reference node))
|
|
770 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::" t))
|
|
771 (Info-goto-node node))
|
|
772 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):" t))
|
|
773 (Info-menu node))
|
|
774 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)" t))
|
|
775 (Info-goto-node node))
|
|
776 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)" t))
|
|
777 (Info-goto-node node))
|
|
778 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)" t))
|
|
779 (Info-goto-node "Top"))
|
|
780 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)" t))
|
|
781 (Info-goto-node node))
|
|
782 ((save-excursion (forward-line 1) (eobp))
|
|
783 (Info-next)))
|
|
784 ))
|
|
785
|
|
786 (defvar Info-mode-map nil
|
|
787 "Keymap containing Info commands.")
|
|
788 (if Info-mode-map
|
|
789 nil
|
|
790 (setq Info-mode-map (make-keymap))
|
|
791 (suppress-keymap Info-mode-map)
|
|
792 (define-key Info-mode-map "." 'beginning-of-buffer)
|
|
793 (define-key Info-mode-map " " 'scroll-up)
|
|
794 (define-key Info-mode-map "1" 'Info-first-menu-item)
|
|
795 (define-key Info-mode-map "2" 'Info-second-menu-item)
|
|
796 (define-key Info-mode-map "3" 'Info-third-menu-item)
|
|
797 (define-key Info-mode-map "4" 'Info-fourth-menu-item)
|
|
798 (define-key Info-mode-map "5" 'Info-fifth-menu-item)
|
|
799 (define-key Info-mode-map "6" 'undefined)
|
|
800 (define-key Info-mode-map "7" 'undefined)
|
|
801 (define-key Info-mode-map "8" 'undefined)
|
|
802 (define-key Info-mode-map "9" 'undefined)
|
|
803 (define-key Info-mode-map "0" 'undefined)
|
|
804 (define-key Info-mode-map "?" 'Info-summary)
|
|
805 (define-key Info-mode-map "]" 'Info-forward-node)
|
|
806 (define-key Info-mode-map "[" 'Info-backward-node)
|
|
807 (define-key Info-mode-map "<" 'Info-top-node)
|
|
808 (define-key Info-mode-map ">" 'Info-final-node)
|
|
809 (define-key Info-mode-map "b" 'beginning-of-buffer)
|
|
810 (define-key Info-mode-map "d" 'Info-directory)
|
|
811 (define-key Info-mode-map "e" 'Info-edit)
|
|
812 (define-key Info-mode-map "f" 'Info-follow-reference)
|
|
813 (define-key Info-mode-map "g" 'Info-goto-node)
|
|
814 (define-key Info-mode-map "h" 'Info-help)
|
|
815 (define-key Info-mode-map "l" 'Info-last)
|
|
816 (define-key Info-mode-map "m" 'Info-menu)
|
|
817 (define-key Info-mode-map "n" 'Info-next)
|
|
818 (define-key Info-mode-map "p" 'Info-prev)
|
|
819 (define-key Info-mode-map "q" 'Info-exit)
|
|
820 (define-key Info-mode-map "s" 'Info-search)
|
|
821 (define-key Info-mode-map "u" 'Info-up)
|
540
|
822 (define-key Info-mode-map "\177" 'scroll-down)
|
|
823 )
|
325
|
824
|
|
825 ;; Info mode is suitable only for specially formatted data.
|
|
826 (put 'info-mode 'mode-class 'special)
|
|
827
|
|
828 (defun Info-mode ()
|
|
829 "\\<Info-mode-map>
|
|
830 Info mode provides commands for browsing through the Info documentation tree.
|
|
831 Documentation in Info is divided into \"nodes\", each of which discusses
|
|
832 one topic and contains references to other nodes which discuss related
|
|
833 topics. Info has commands to follow the references and show you other nodes.
|
|
834
|
|
835 \\[Info-help] Invoke the Info tutorial.
|
|
836
|
|
837 Selecting other nodes:
|
|
838 \\[Info-next] Move to the \"next\" node of this node.
|
|
839 \\[Info-previous] Move to the \"previous\" node of this node.
|
|
840 \\[Info-up] Move \"up\" from this node.
|
|
841 \\[Info-menu] Pick menu item specified by name (or abbreviation).
|
|
842 Picking a menu item causes another node to be selected.
|
540
|
843 \\[Info-directory] Go to the Info directory node.
|
325
|
844 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
|
|
845 \\[Info-last] Move to the last node you were at.
|
|
846
|
|
847 Moving within a node:
|
|
848 \\[scroll-up] scroll forward a full screen. \\[scroll-down] scroll backward.
|
|
849 \\[beginning-of-buffer] Go to beginning of node.
|
|
850
|
|
851 Advanced commands:
|
|
852 \\[Info-exit] Quit Info: reselect previously selected buffer.
|
|
853 \\[Info-edit] Edit contents of selected node.
|
|
854 1 Pick first item in node's menu.
|
|
855 2, 3, 4, 5 Pick second ... fifth item in node's menu.
|
|
856 \\[Info-goto-node] Move to node specified by name.
|
|
857 You may include a filename as well, as (FILENAME)NODENAME.
|
|
858 \\[Info-search] Search through this Info file for specified regexp,
|
|
859 and select the node in which the next occurrence is found."
|
|
860 (kill-all-local-variables)
|
|
861 (setq major-mode 'Info-mode)
|
|
862 (setq mode-name "Info")
|
|
863 (use-local-map Info-mode-map)
|
|
864 (set-syntax-table text-mode-syntax-table)
|
|
865 (setq local-abbrev-table text-mode-abbrev-table)
|
|
866 (setq case-fold-search t)
|
|
867 (setq buffer-read-only t)
|
|
868 (make-local-variable 'Info-current-file)
|
|
869 (make-local-variable 'Info-current-subfile)
|
|
870 (make-local-variable 'Info-current-node)
|
|
871 (make-local-variable 'Info-tag-table-marker)
|
|
872 (make-local-variable 'Info-history)
|
|
873 (Info-set-mode-line)
|
|
874 (run-hooks 'Info-mode-hook))
|
|
875
|
|
876 (defvar Info-edit-map nil
|
|
877 "Local keymap used within `e' command of Info.")
|
|
878 (if Info-edit-map
|
|
879 nil
|
|
880 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
|
|
881 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
|
|
882
|
|
883 ;; Info-edit mode is suitable only for specially formatted data.
|
|
884 (put 'info-edit-mode 'mode-class 'special)
|
|
885
|
|
886 (defun Info-edit-mode ()
|
|
887 "Major mode for editing the contents of an Info node.
|
|
888 Like text mode with the addition of Info-cease-edit
|
|
889 which returns to Info mode for browsing.
|
|
890 \\{Info-edit-map}"
|
|
891 )
|
|
892
|
|
893 (defun Info-edit ()
|
|
894 "Edit the contents of this Info node.
|
|
895 Allowed only if variable `Info-enable-edit' is non-nil."
|
|
896 (interactive)
|
|
897 (or Info-enable-edit
|
|
898 (error "Editing info nodes is not enabled"))
|
|
899 (use-local-map Info-edit-map)
|
|
900 (setq major-mode 'Info-edit-mode)
|
|
901 (setq mode-name "Info Edit")
|
|
902 (kill-local-variable 'mode-line-buffer-identification)
|
|
903 (setq buffer-read-only nil)
|
|
904 ;; Make mode line update.
|
|
905 (set-buffer-modified-p (buffer-modified-p))
|
|
906 (message (substitute-command-keys
|
|
907 "Editing: Type \\<info-mode-map>\\[Info-cease-edit] to return to info")))
|
|
908
|
|
909 (defun Info-cease-edit ()
|
|
910 "Finish editing Info node; switch back to Info proper."
|
|
911 (interactive)
|
|
912 ;; Do this first, so nothing has changed if user C-g's at query.
|
|
913 (and (buffer-modified-p)
|
|
914 (y-or-n-p "Save the file? ")
|
|
915 (save-buffer))
|
|
916 (use-local-map Info-mode-map)
|
|
917 (setq major-mode 'Info-mode)
|
|
918 (setq mode-name "Info")
|
|
919 (Info-set-mode-line)
|
|
920 (setq buffer-read-only t)
|
|
921 ;; Make mode line update.
|
|
922 (set-buffer-modified-p (buffer-modified-p))
|
|
923 (and (marker-position Info-tag-table-marker)
|
|
924 (buffer-modified-p)
|
|
925 (message "Tags may have changed. Use Info-tagify if necessary")))
|
359
|
926
|
|
927 (defun Info-find-emacs-command-nodes (command)
|
|
928 "Return a list of locations documenting COMMAND in the Emacs Info manual.
|
|
929 The locations are of the format used in Info-history, i.e.
|
|
930 \(FILENAME NODENAME BUFFERPOS\)."
|
|
931 (require 'info)
|
|
932 (let ((where '())
|
|
933 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
|
|
934 ":\\s *\\(.*\\)\\.$")))
|
|
935 (save-excursion
|
|
936 (Info-find-node "emacs" "Command Index")
|
|
937 ;; Take the index node off the Info history.
|
|
938 (setq Info-history (cdr Info-history))
|
|
939 (goto-char (point-max))
|
|
940 (while (re-search-backward cmd-desc nil t)
|
|
941 (setq where (cons (list Info-current-file
|
|
942 (buffer-substring
|
|
943 (match-beginning 1)
|
|
944 (match-end 1))
|
|
945 0)
|
|
946 where)))
|
|
947 where)))
|
|
948
|
|
949 ;;;###autoload
|
|
950 (defun Info-goto-emacs-command-node (command)
|
|
951 "Go to the Info node in the Emacs manual for command COMMAND."
|
|
952 (interactive "CFind documentation for command: ")
|
|
953 (or (commandp command)
|
|
954 (signal 'wrong-type-argument (list 'commandp command)))
|
|
955 (let ((where (Info-find-emacs-command-nodes command)))
|
|
956 (if where
|
|
957 (let ((num-matches (length where)))
|
|
958 ;; Get Info running, and pop to it in another window.
|
|
959 (save-window-excursion
|
|
960 (info))
|
|
961 (pop-to-buffer "*info*")
|
|
962 (Info-find-node (car (car where))
|
|
963 (car (cdr (car where))))
|
|
964 (if (> num-matches 1)
|
|
965 (progn
|
|
966 ;; Info-find-node already pushed (car where) onto
|
|
967 ;; Info-history. Put the other nodes that were found on
|
|
968 ;; the history.
|
|
969 (setq Info-history (nconc (cdr where) Info-history))
|
|
970 (message (substitute-command-keys
|
|
971 "Found %d other entr%. Use \\[Info-last] to see %s."
|
|
972 (1- num-matches)
|
|
973 (if (> num-matches 2) "ies" "y")
|
|
974 (if (> num-matches 2) "them" "it"))))))
|
|
975 (error "Couldn't find documentation for %s." command))))
|
|
976 ;;;###autoload
|
|
977 (define-key help-map "\C-f" 'Info-goto-emacs-command-node)
|
|
978
|
|
979 ;;;###autoload
|
|
980 (defun Info-goto-emacs-key-command-node (key)
|
|
981 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
|
|
982 Interactively, if the binding is execute-extended-command, a command is read."
|
|
983 (interactive "kFind documentation for key:")
|
|
984 (let ((command (key-binding key)))
|
|
985 (cond ((null command)
|
|
986 (message "%s is undefined" (key-description keys)))
|
|
987 ((and (interactive-p)
|
|
988 (eq command 'execute-extended-command))
|
|
989 (Info-goto-emacs-command-node
|
|
990 (read-command "Find documentation for command: ")))
|
|
991 (t
|
|
992 (Info-goto-emacs-command-node command)))))
|
|
993 ;;;###autoload
|
|
994 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node)
|
584
|
995
|
|
996 (provide 'info)
|
|
997
|