]> code.delx.au - gnu-emacs/blob - lisp/info-look.el
Change author's mail address.
[gnu-emacs] / lisp / info-look.el
1 ;;; info-look.el --- major-mode-sensitive Info index lookup facility.
2 ;; An older version of this was known as libc.el.
3
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
5
6 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
7 ;; Keywords: help languages
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'info)
29
30 (defgroup info-lookup nil
31 "Major mode sensitive help agent."
32 :group 'help :group 'languages)
33
34 (defvar info-lookup-mode nil
35 "Symbol of the current buffer's help mode.
36 Help is provided according to the buffer's major mode if value is nil.
37 Automatically becomes buffer local when set in any fashion.")
38 (make-variable-buffer-local 'info-lookup-mode)
39
40 (defcustom info-lookup-other-window-flag t
41 "Non-nil means pop up the Info buffer in another window."
42 :group 'info-lookup :type 'boolean)
43
44 (defcustom info-lookup-highlight-face 'highlight
45 "Face for highlighting looked up help items.
46 Setting this variable to nil disables highlighting."
47 :group 'info-lookup :type 'face)
48
49 (defvar info-lookup-highlight-overlay nil
50 "Overlay object used for highlighting.")
51
52 (defcustom info-lookup-file-name-alist
53 '(("\\`configure\\.in\\'" . autoconf-mode)
54 ("\\`aclocal\\.m4\\'" . autoconf-mode)
55 ("\\`acsite\\.m4\\'" . autoconf-mode)
56 ("\\`acinclude\\.m4\\'" . autoconf-mode))
57 "Alist of file names handled specially.
58 List elements are cons cells of the form
59
60 (REGEXP . MODE)
61
62 If a file name matches REGEXP, then use help mode MODE instead of the
63 buffer's major mode."
64 :group 'info-lookup :type '(repeat (cons (string :tag "Regexp")
65 (symbol :tag "Mode"))))
66
67 (defvar info-lookup-history nil
68 "History of previous input lines.")
69
70 (defvar info-lookup-alist nil
71 "Alist of known help topics.
72 Cons cells are of the form
73
74 (HELP-TOPIC . HELP-DATA)
75
76 HELP-TOPIC is the symbol of a help topic.
77 HELP-DATA is a HELP-TOPIC's public data set.
78 Value is an alist with elements of the form
79
80 (HELP-MODE REGEXP IGNORE-CASE DOC-SPEC PARSE-RULE OTHER-MODES)
81
82 HELP-MODE is a mode's symbol.
83 REGEXP is a regular expression matching those help items whose
84 documentation can be looked up via DOC-SPEC.
85 IGNORE-CASE is non-nil if help items are case insensitive.
86 DOC-SPEC is a list of documentation specifications of the form
87
88 (INFO-NODE TRANS-FUNC PREFIX SUFFIX)
89
90 INFO-NODE is the name (including file name part) of an Info index.
91 TRANS-FUNC is a function translating index entries into help items;
92 nil means add only those index entries matching REGEXP, a string
93 means prepend string to the first word of all index entries.
94 PREFIX and SUFFIX are parts of a regular expression. If one of
95 them is non-nil then search the help item's Info node for the
96 first occurrence of the regular expression `PREFIX ITEM SUFFIX'.
97 ITEM will be highlighted with `info-lookup-highlight-face' if this
98 variable is not nil.
99 PARSE-RULE is either the symbol name of a function or a regular
100 expression for guessing the default help item at point. Fuzzy
101 regular expressions like \"[_a-zA-Z0-9]+\" do a better job if
102 there are no clear delimiters; do not try to write too complex
103 expressions. PARSE-RULE defaults to REGEXP.
104 OTHER-MODES is a list of cross references to other help modes.")
105
106 (defsubst info-lookup->topic-value (topic)
107 (cdr (assoc topic info-lookup-alist)))
108
109 (defsubst info-lookup->mode-value (topic mode)
110 (assoc mode (info-lookup->topic-value topic)))
111
112 (defsubst info-lookup->regexp (topic mode)
113 (nth 1 (info-lookup->mode-value topic mode)))
114
115 (defsubst info-lookup->ignore-case (topic mode)
116 (nth 2 (info-lookup->mode-value topic mode)))
117
118 (defsubst info-lookup->doc-spec (topic mode)
119 (nth 3 (info-lookup->mode-value topic mode)))
120
121 (defsubst info-lookup->parse-rule (topic mode)
122 (nth 4 (info-lookup->mode-value topic mode)))
123
124 (defsubst info-lookup->other-modes (topic mode)
125 (nth 5 (info-lookup->mode-value topic mode)))
126
127 (eval-and-compile
128 (mapcar (lambda (keyword)
129 (or (boundp keyword)
130 (set keyword keyword)))
131 '(:topic :mode :regexp :ignore-case
132 :doc-spec :parse-rule :other-modes)))
133
134 (defun info-lookup-add-help (&rest arg)
135 "Add or update a help specification.
136 Function arguments are one or more options of the form
137
138 KEYWORD ARGUMENT
139
140 KEYWORD is either `:topic', `:mode', `:regexp', `:ignore-case',
141 `:doc-spec', `:parse-rule', or `:other-modes'.
142 ARGUMENT has a value as explained in the documentation of the
143 variable `info-lookup-alist'.
144
145 If no topic or mode option has been specified, then the help topic defaults
146 to `symbol', and the help mode defaults to the current major mode."
147 (apply 'info-lookup-add-help* nil arg))
148
149 (defun info-lookup-maybe-add-help (&rest arg)
150 "Add a help specification iff no one is defined.
151 See the documentation of the function `info-lookup-add-help'
152 for more details."
153 (apply 'info-lookup-add-help* t arg))
154
155 (defun info-lookup-add-help* (maybe &rest arg)
156 (let (topic mode regexp ignore-case doc-spec
157 parse-rule other-modes keyword value)
158 (setq topic 'symbol
159 mode major-mode
160 regexp "\\w+")
161 (while arg
162 (setq keyword (car arg))
163 (or (symbolp keyword)
164 (error "Junk in argument list \"%S\"" arg))
165 (setq arg (cdr arg))
166 (and (null arg)
167 (error "Keyword \"%S\" is missing an argument" keyword))
168 (setq value (car arg)
169 arg (cdr arg))
170 (cond ((eq keyword :topic)
171 (setq topic value))
172 ((eq keyword :mode)
173 (setq mode value))
174 ((eq keyword :regexp)
175 (setq regexp value))
176 ((eq keyword :ignore-case)
177 (setq ignore-case value))
178 ((eq keyword :doc-spec)
179 (setq doc-spec value))
180 ((eq keyword :parse-rule)
181 (setq parse-rule value))
182 ((eq keyword :other-modes)
183 (setq other-modes value))
184 (t
185 (error "Unknown keyword \"%S\"" keyword))))
186 (or (and maybe (info-lookup->mode-value topic mode))
187 (let* ((data (list regexp ignore-case doc-spec parse-rule other-modes))
188 (topic-cell (or (assoc topic info-lookup-alist)
189 (car (setq info-lookup-alist
190 (cons (cons topic nil)
191 info-lookup-alist)))))
192 (mode-cell (assoc mode topic-cell)))
193 (if (null mode-cell)
194 (setcdr topic-cell (cons (cons mode data) (cdr topic-cell)))
195 (setcdr mode-cell data))))
196 nil))
197
198 (defvar info-lookup-cache nil
199 "Cache storing data maintained automatically by the program.
200 Value is an alist with cons cell of the form
201
202 (HELP-TOPIC . ((HELP-MODE INITIALIZED COMPLETIONS REFER-MODES) ...))
203
204 HELP-TOPIC is the symbol of a help topic.
205 HELP-MODE is a mode's symbol.
206 INITIALIZED is nil if HELP-MODE is uninitialized, t if
207 HELP-MODE is initialized, and `0' means HELP-MODE is
208 initialized but void.
209 COMPLETIONS is an alist of documented help items.
210 REFER-MODES is a list of other help modes to use.")
211
212 (defsubst info-lookup->cache (topic)
213 (or (assoc topic info-lookup-cache)
214 (car (setq info-lookup-cache
215 (cons (cons topic nil)
216 info-lookup-cache)))))
217
218 (defun info-lookup->topic-cache (topic)
219 (cdr (info-lookup->cache topic)))
220
221 (defun info-lookup->mode-cache (topic mode)
222 (assoc mode (info-lookup->topic-cache topic)))
223
224 (defun info-lookup->initialized (topic mode)
225 (nth 1 (info-lookup->mode-cache topic mode)))
226
227 (defun info-lookup->completions (topic mode)
228 (or (info-lookup->initialized topic mode)
229 (info-lookup-setup-mode topic mode))
230 (nth 2 (info-lookup->mode-cache topic mode)))
231
232 (defun info-lookup->refer-modes (topic mode)
233 (or (info-lookup->initialized topic mode)
234 (info-lookup-setup-mode topic mode))
235 (nth 3 (info-lookup->mode-cache topic mode)))
236
237 (defun info-lookup->all-modes (topic mode)
238 (cons mode (info-lookup->refer-modes topic mode)))
239
240 (defun info-lookup-quick-all-modes (topic mode)
241 (cons mode (info-lookup->other-modes topic mode)))
242
243 ;;;###autoload
244 (defun info-lookup-reset ()
245 "Throw away all cached data.
246 This command is useful if the user wants to start at the beginning without
247 quitting Emacs, for example, after some Info documents were updated on the
248 system."
249 (interactive)
250 (setq info-lookup-cache nil))
251
252 ;;;###autoload
253 (defun info-lookup-symbol (symbol &optional mode)
254 "Display the definition of SYMBOL, as found in the relevant manual.
255 When this command is called interactively, it reads SYMBOL from the minibuffer.
256 In the minibuffer, use M-n to yank the default argument value
257 into the minibuffer so you can edit it.
258 The default symbol is the one found at point.
259
260 With prefix arg a query for the symbol help mode is offered."
261 (interactive
262 (info-lookup-interactive-arguments 'symbol current-prefix-arg))
263 (info-lookup 'symbol symbol mode))
264
265 ;;;###autoload
266 (defun info-lookup-file (file &optional mode)
267 "Display the documentation of a file.
268 When this command is called interactively, it reads FILE from the minibuffer.
269 In the minibuffer, use M-n to yank the default file name
270 into the minibuffer so you can edit it.
271 The default file name is the one found at point.
272
273 With prefix arg a query for the file help mode is offered."
274 (interactive
275 (info-lookup-interactive-arguments 'file current-prefix-arg))
276 (info-lookup 'file file mode))
277
278 (defun info-lookup-interactive-arguments (topic &optional query)
279 "Read and return argument value (and help mode) for help topic TOPIC.
280 If optional argument QUERY is non-nil, query for the help mode."
281 (let* ((mode (cond (query
282 (info-lookup-change-mode topic))
283 ((info-lookup->mode-value topic (info-lookup-select-mode))
284 info-lookup-mode)
285 ((info-lookup-change-mode topic))))
286 (completions (info-lookup->completions topic mode))
287 (default (info-lookup-guess-default topic mode))
288 (completion-ignore-case (info-lookup->ignore-case topic mode))
289 (enable-recursive-minibuffers t)
290 (value (completing-read
291 (if default
292 (format "Describe %s (default %s): " topic default)
293 (format "Describe %s: " topic))
294 completions nil nil nil 'info-lookup-history default)))
295 (list (if (equal value "") default value) mode)))
296
297 (defun info-lookup-select-mode ()
298 (when (and (not info-lookup-mode) (buffer-file-name))
299 (let ((file-name (file-name-nondirectory (buffer-file-name)))
300 (file-name-alist info-lookup-file-name-alist))
301 (while (and (not info-lookup-mode) file-name-alist)
302 (when (string-match (caar file-name-alist) file-name)
303 (setq info-lookup-mode (cdar file-name-alist)))
304 (setq file-name-alist (cdr file-name-alist)))))
305 (or info-lookup-mode (setq info-lookup-mode major-mode)))
306
307 (defun info-lookup-change-mode (topic)
308 (let* ((completions (mapcar (lambda (arg)
309 (cons (symbol-name (car arg)) (car arg)))
310 (info-lookup->topic-value topic)))
311 (mode (completing-read
312 (format "Use %s help mode: " topic)
313 completions nil t nil 'info-lookup-history)))
314 (or (setq mode (cdr (assoc mode completions)))
315 (error "No %s help available" topic))
316 (or (info-lookup->mode-value topic mode)
317 (error "No %s help available for `%s'" topic mode))
318 (setq info-lookup-mode mode)))
319
320 (defun info-lookup (topic item mode)
321 "Display the documentation of a help item."
322 (or mode (setq mode (info-lookup-select-mode)))
323 (or (info-lookup->mode-value topic mode)
324 (error "No %s help available for `%s'" topic mode))
325 (let ((entry (or (assoc (if (info-lookup->ignore-case topic mode)
326 (downcase item) item)
327 (info-lookup->completions topic mode))
328 (error "Not documented as a %s: %s" topic (or item ""))))
329 (modes (info-lookup->all-modes topic mode))
330 (window (selected-window))
331 found doc-spec node prefix suffix doc-found)
332 (if (or (not info-lookup-other-window-flag)
333 (eq (current-buffer) (get-buffer "*info*")))
334 (info)
335 (save-window-excursion (info))
336 (switch-to-buffer-other-window "*info*"))
337 (while (and (not found) modes)
338 (setq doc-spec (info-lookup->doc-spec topic (car modes)))
339 (while (and (not found) doc-spec)
340 (setq node (nth 0 (car doc-spec))
341 prefix (nth 2 (car doc-spec))
342 suffix (nth 3 (car doc-spec)))
343 (when (condition-case error-data
344 (progn
345 (Info-goto-node node)
346 (setq doc-found t))
347 (error
348 (message "Cannot access Info node %s" node)
349 (sit-for 1)
350 nil))
351 (condition-case nil
352 (progn
353 (Info-menu (or (cdr entry) item))
354 (setq found t)
355 (if (or prefix suffix)
356 (let ((case-fold-search
357 (info-lookup->ignore-case topic (car modes)))
358 (buffer-read-only nil))
359 (goto-char (point-min))
360 (re-search-forward
361 (concat prefix (regexp-quote item) suffix))
362 (goto-char (match-beginning 0))
363 (and (display-color-p) info-lookup-highlight-face
364 ;; Search again for ITEM so that the first
365 ;; occurence of ITEM will be highlighted.
366 (re-search-forward (regexp-quote item))
367 (let ((start (match-beginning 0))
368 (end (match-end 0)))
369 (if (overlayp info-lookup-highlight-overlay)
370 (move-overlay info-lookup-highlight-overlay
371 start end (current-buffer))
372 (setq info-lookup-highlight-overlay
373 (make-overlay start end))))
374 (overlay-put info-lookup-highlight-overlay
375 'face info-lookup-highlight-face)))))
376 (error nil)))
377 (setq doc-spec (cdr doc-spec)))
378 (setq modes (cdr modes)))
379 (or doc-found
380 (error "Info documentation for lookup was not found"))
381 ;; Don't leave the Info buffer if the help item couldn't be looked up.
382 (if (and info-lookup-other-window-flag found)
383 (select-window window))))
384
385 (defun info-lookup-setup-mode (topic mode)
386 "Initialize the internal data structure."
387 (or (info-lookup->initialized topic mode)
388 (let (cell data (initialized 0) completions refer-modes)
389 (if (not (info-lookup->mode-value topic mode))
390 (message "No %s help available for `%s'" topic mode)
391 ;; Recursively setup cross references.
392 ;; But refer only to non-void modes.
393 (mapcar (lambda (arg)
394 (or (info-lookup->initialized topic arg)
395 (info-lookup-setup-mode topic arg))
396 (and (eq (info-lookup->initialized topic arg) t)
397 (setq refer-modes (cons arg refer-modes))))
398 (info-lookup->other-modes topic mode))
399 (setq refer-modes (nreverse refer-modes))
400 ;; Build the full completion alist.
401 (setq completions
402 (nconc (condition-case nil
403 (info-lookup-make-completions topic mode)
404 (error nil))
405 (apply 'append
406 (mapcar (lambda (arg)
407 (info-lookup->completions topic arg))
408 refer-modes))))
409 (setq initialized t))
410 ;; Update `info-lookup-cache'.
411 (setq cell (info-lookup->mode-cache topic mode)
412 data (list initialized completions refer-modes))
413 (if (not cell)
414 (setcdr (info-lookup->cache topic)
415 (cons (cons mode data) (info-lookup->topic-cache topic)))
416 (setcdr cell data))
417 initialized)))
418
419 (defun info-lookup-make-completions (topic mode)
420 "Create a unique alist from all index entries."
421 (let ((doc-spec (info-lookup->doc-spec topic mode))
422 (regexp (concat "^\\(" (info-lookup->regexp topic mode)
423 "\\)\\([ \t].*\\)?$"))
424 node trans entry item prefix result doc-found
425 (buffer (get-buffer-create " temp-info-look")))
426 (with-current-buffer buffer
427 (Info-mode))
428 (while doc-spec
429 (setq node (nth 0 (car doc-spec))
430 trans (cond ((eq (nth 1 (car doc-spec)) nil)
431 (lambda (arg)
432 (if (string-match regexp arg)
433 (match-string 1 arg))))
434 ((stringp (nth 1 (car doc-spec)))
435 (setq prefix (nth 1 (car doc-spec)))
436 (lambda (arg)
437 (if (string-match "^\\([^: \t\n]+\\)" arg)
438 (concat prefix (match-string 1 arg)))))
439 (t (nth 1 (car doc-spec)))))
440 (with-current-buffer buffer
441 (message "Processing Info node `%s'..." node)
442 (when (condition-case error-data
443 (progn
444 (Info-goto-node node)
445 (setq doc-found t))
446 (error
447 (message "Cannot access Info node `%s'" node)
448 (sit-for 1)
449 nil))
450 (condition-case nil
451 (progn
452 (goto-char (point-min))
453 (and (search-forward "\n* Menu:" nil t)
454 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
455 (setq entry (match-string 1)
456 item (funcall trans entry))
457 ;; `trans' can return nil if the regexp doesn't match.
458 (when (and item
459 ;; Sometimes there's more than one Menu:
460 (not (string= entry "Menu")))
461 (and (info-lookup->ignore-case topic mode)
462 (setq item (downcase item)))
463 (and (string-equal entry item)
464 (setq entry nil))
465 (and (or (assoc item result)
466 (setq result (cons (cons item entry)
467 result))))))))
468 (error nil))))
469 (message "Processing Info node `%s'...done" node)
470 (setq doc-spec (cdr doc-spec)))
471 (or doc-found
472 (error "Info documentation for lookup was not found"))
473 result))
474
475 (defun info-lookup-guess-default (topic mode)
476 "Return a guess for a symbol to look up, based on text around point.
477 Try all related modes applicable to TOPIC and MODE.
478 Return nil if there is nothing appropriate in the buffer near point."
479 (let ((modes (info-lookup->all-modes topic mode))
480 guess)
481 (while (and (not guess) modes)
482 (setq guess (info-lookup-guess-default* topic (car modes))
483 modes (cdr modes)))
484 ;; Collapse whitespace characters.
485 (when guess
486 (let ((pos 0))
487 (while (string-match "[ \t\n]+" guess pos)
488 (setq pos (1+ (match-beginning 0)))
489 (setq guess (replace-match " " t t guess)))))
490 guess))
491
492 (defun info-lookup-guess-default* (topic mode)
493 (let ((case-fold-search (info-lookup->ignore-case topic mode))
494 (rule (or (info-lookup->parse-rule topic mode)
495 (info-lookup->regexp topic mode)))
496 (start (point)) end regexp subexp result)
497 (save-excursion
498 (if (symbolp rule)
499 (setq result (funcall rule))
500 (if (consp rule)
501 (setq regexp (car rule)
502 subexp (cdr rule))
503 (setq regexp rule
504 subexp 0))
505 ;; If at start of symbol, don't go back to end of previous one.
506 (if (save-match-data
507 (looking-at "[ \t\n]"))
508 (skip-chars-backward " \t\n"))
509 (setq end (point))
510 (while (and (re-search-backward regexp nil t)
511 (looking-at regexp)
512 (>= (match-end 0) end))
513 (setq result (match-string subexp)))
514 (if (not result)
515 (progn
516 (goto-char start)
517 (skip-chars-forward " \t\n")
518 (and (looking-at regexp)
519 (setq result (match-string subexp)))))))
520 result))
521
522 (defun info-lookup-guess-c-symbol ()
523 "Get the C symbol at point."
524 (condition-case nil
525 (progn
526 (skip-syntax-backward "w_")
527 (let ((start (point)) prefix name)
528 ;; Test for a leading `struct', `union', or `enum' keyword
529 ;; but ignore names like `foo_struct'.
530 (setq prefix (and (< (skip-chars-backward " \t\n") 0)
531 (< (skip-chars-backward "_a-zA-Z0-9") 0)
532 (looking-at "\\(struct\\|union\\|enum\\)\\s ")
533 (concat (match-string 1) " ")))
534 (goto-char start)
535 (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*")
536 (setq name (match-string 0)))
537 ;; Caveat! Look forward if point is at `struct' etc.
538 (and (not prefix)
539 (or (string-equal name "struct")
540 (string-equal name "union")
541 (string-equal name "enum"))
542 (looking-at "[a-z]+\\s +\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
543 (setq prefix (concat name " ")
544 name (match-string 1)))
545 (and (or prefix name)
546 (concat prefix name))))
547 (error nil)))
548
549 ;;;###autoload
550 (defun info-complete-symbol (&optional mode)
551 "Perform completion on symbol preceding point."
552 (interactive)
553 (info-complete 'symbol
554 (or mode
555 (if (info-lookup->mode-value
556 'symbol (info-lookup-select-mode))
557 info-lookup-mode
558 (info-lookup-change-mode 'symbol)))))
559
560 ;;;###autoload
561 (defun info-complete-file (&optional mode)
562 "Perform completion on file preceding point."
563 (interactive)
564 (info-complete 'file
565 (or mode
566 (if (info-lookup->mode-value
567 'file (info-lookup-select-mode))
568 info-lookup-mode
569 (info-lookup-change-mode 'file)))))
570
571 (defun info-complete (topic mode)
572 "Try to complete a help item."
573 (barf-if-buffer-read-only)
574 (or mode (setq mode (info-lookup-select-mode)))
575 (or (info-lookup->mode-value topic mode)
576 (error "No %s completion available for `%s'" topic mode))
577 (let ((modes (info-lookup-quick-all-modes topic mode))
578 (start (point))
579 try)
580 (while (and (not try) modes)
581 (setq mode (car modes)
582 modes (cdr modes)
583 try (info-lookup-guess-default* topic mode))
584 (goto-char start))
585 (and (not try)
586 (error "Found no %S to complete" topic))
587 (let ((completions (info-lookup->completions topic mode))
588 (completion-ignore-case (info-lookup->ignore-case topic mode))
589 completion)
590 (setq completion (try-completion try completions))
591 (cond ((not completion)
592 (ding)
593 (message "No match"))
594 ((stringp completion)
595 (or (assoc completion completions)
596 (setq completion (completing-read
597 (format "Complete %S: " topic)
598 completions nil t completion
599 info-lookup-history)))
600 ;; Find the original symbol and zap it.
601 (end-of-line)
602 (while (and (search-backward try nil t)
603 (< start (point))))
604 (replace-match "")
605 (insert completion))
606 (t
607 (message "%s is complete"
608 (capitalize (prin1-to-string topic))))))))
609
610 \f
611 ;;; Initialize some common modes.
612
613 (info-lookup-maybe-add-help
614 :mode 'c-mode :topic 'symbol
615 :regexp "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*"
616 :doc-spec '(("(libc)Function Index" nil
617 "^[ \t]+- \\(Function\\|Macro\\): .*\\<" "\\>")
618 ("(libc)Variable Index" nil
619 "^[ \t]+- \\(Variable\\|Macro\\): .*\\<" "\\>")
620 ("(libc)Type Index" nil
621 "^[ \t]+- Data Type: \\<" "\\>")
622 ("(termcap)Var Index" nil
623 "^[ \t]*`" "'"))
624 :parse-rule 'info-lookup-guess-c-symbol)
625
626 (info-lookup-maybe-add-help
627 :mode 'c-mode :topic 'file
628 :regexp "[_a-zA-Z0-9./+-]+"
629 :doc-spec '(("(libc)File Index")))
630
631 (info-lookup-maybe-add-help
632 :mode 'bison-mode
633 :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+"
634 :doc-spec '(("(bison)Index" nil
635 "`" "'"))
636 :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
637 :other-modes '(c-mode))
638
639 (info-lookup-maybe-add-help
640 :mode 'makefile-mode
641 :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*"
642 :doc-spec '(("(make)Name Index" nil
643 "^[ \t]*`" "'"))
644 :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+")
645
646 (info-lookup-maybe-add-help
647 :mode 'texinfo-mode
648 :regexp "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
649 :doc-spec '(("(texinfo)Command and Variable Index"
650 ;; Ignore Emacs commands and prepend a `@'.
651 (lambda (item)
652 (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item)
653 (concat "@" (match-string 1 item))))
654 "`" "'")))
655
656 (info-lookup-maybe-add-help
657 :mode 'm4-mode
658 :regexp "[_a-zA-Z][_a-zA-Z0-9]*"
659 :doc-spec '(("(m4)Macro index"))
660 :parse-rule "[_a-zA-Z0-9]+")
661
662 (info-lookup-maybe-add-help
663 :mode 'autoconf-mode
664 :regexp "A[CM]_[_A-Z0-9]+"
665 :doc-spec '(("(autoconf)Macro Index" "AC_"
666 "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
667 ("(automake)Index" nil
668 "^[ \t]*`" "'"))
669 ;; Autoconf symbols are M4 macros. Thus use M4's parser.
670 :parse-rule 'ignore
671 :other-modes '(m4-mode))
672
673 (info-lookup-maybe-add-help
674 :mode 'awk-mode
675 :regexp "[_a-zA-Z]+"
676 :doc-spec '(("(gawk)Index"
677 (lambda (item)
678 (let ((case-fold-search nil))
679 (cond
680 ;; `BEGIN' and `END'.
681 ((string-match "^\\([A-Z]+\\) special pattern\\b" item)
682 (match-string 1 item))
683 ;; `if', `while', `do', ...
684 ((string-match "^\\([a-z]+\\) statement\\b" item)
685 (if (not (string-equal (match-string 1 item) "control"))
686 (match-string 1 item)))
687 ;; `NR', `NF', ...
688 ((string-match "^[A-Z]+$" item)
689 item)
690 ;; Built-in functions (matches to many entries).
691 ((string-match "^[a-z]+$" item)
692 item))))
693 "`" "\\([ \t]*([^)]*)\\)?'")))
694
695 (info-lookup-maybe-add-help
696 :mode 'perl-mode
697 :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
698 :doc-spec '(("(perl5)Function Index"
699 (lambda (item)
700 (if (string-match "^\\([a-zA-Z0-9]+\\)" item)
701 (match-string 1 item)))
702 "^" "\\b")
703 ("(perl5)Variable Index"
704 (lambda (item)
705 ;; Work around bad formatted array variables.
706 (let ((sym (cond ((or (string-match "^\\$\\(.\\|@@\\)$" item)
707 (string-match "^\\$\\^[A-Z]$" item))
708 item)
709 ((string-match
710 "^\\([$%@]\\|@@\\)?[_a-zA-Z0-9]+" item)
711 (match-string 0 item))
712 (t ""))))
713 (if (string-match "@@" sym)
714 (setq sym (concat (substring sym 0 (match-beginning 0))
715 (substring sym (1- (match-end 0))))))
716 (if (string-equal sym "") nil sym)))
717 "^" "\\b"))
718 :parse-rule "[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)")
719
720 (info-lookup-maybe-add-help
721 :mode 'latex-mode
722 :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
723 :doc-spec '(("(latex)Command Index" nil
724 "`" "\\({[^}]*}\\)?'")))
725
726 (info-lookup-maybe-add-help
727 :mode 'emacs-lisp-mode
728 :regexp "[^()' \t\n]+"
729 :doc-spec '(("(emacs)Command Index")
730 ("(emacs)Variable Index")
731 ("(elisp)Index"
732 (lambda (item)
733 (let ((sym (intern-soft item)))
734 (cond ((null sym)
735 (if (string-equal item "nil") item))
736 ((or (boundp sym) (fboundp sym))
737 item))))
738 "^[ \t]+- [^:]+:[ \t]*" "\\b")))
739
740 (info-lookup-maybe-add-help
741 :mode 'lisp-interaction-mode
742 :regexp "[^()' \t\n]+"
743 :parse-rule 'ignore
744 :other-modes '(emacs-lisp-mode))
745
746 (info-lookup-maybe-add-help
747 :mode 'lisp-mode
748 :regexp "[^()' \t\n]+"
749 :parse-rule 'ignore
750 :other-modes '(emacs-lisp-mode))
751
752 (info-lookup-maybe-add-help
753 :mode 'scheme-mode
754 :regexp "[^()' \t\n]+"
755 :ignore-case t
756 ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm>
757 :doc-spec '(("(r5rs)Index" nil
758 "^[ \t]+- [^:]+:[ \t]*" "\\b")))
759
760 (info-lookup-maybe-add-help
761 :mode 'octave-mode
762 :regexp "[_a-zA-Z0-9]+"
763 :doc-spec '(("(octave)Function Index" nil
764 "^ - [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil)
765 ("(octave)Variable Index" nil "^ - [^:]+:[ ]+" nil)
766 ;; Catch lines of the form "xyz statement"
767 ("(octave)Concept Index"
768 (lambda (item)
769 (cond
770 ((string-match "^\\([A-Z]+\\) statement\\b" item)
771 (match-string 1 item))
772 (t nil)))
773 nil; "^ - [^:]+:[ ]+" don't think this prefix is useful here.
774 nil)))
775 \f
776 (provide 'info-look)
777
778 ;;; info-look.el ends here