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