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