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,96,97,98,99,2001,03,04,05 Free Software Foundation, Inc.
6 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
7 ;; (did not show signs of life (Nov 2001) -stef)
8 ;; Keywords: help languages
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Really cool code to lookup info indexes.
30 ;; Try especially info-lookup-symbol (aka C-h S).
36 (defgroup info-lookup nil
37 "Major mode sensitive help agent."
38 :group
'help
:group
'languages
)
40 (defvar info-lookup-mode nil
41 "Symbol of the current buffer's help mode.
42 Help is provided according to the buffer's major mode if value is nil.
43 Automatically becomes buffer local when set in any fashion.")
44 (make-variable-buffer-local 'info-lookup-mode
)
46 (defcustom info-lookup-other-window-flag t
47 "Non-nil means pop up the Info buffer in another window."
48 :group
'info-lookup
:type
'boolean
)
50 (defcustom info-lookup-highlight-face
'match
51 "Face for highlighting looked up help items.
52 Setting this variable to nil disables highlighting."
53 :group
'info-lookup
:type
'face
)
55 (defvar info-lookup-highlight-overlay nil
56 "Overlay object used for highlighting.")
58 (defcustom info-lookup-file-name-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
65 If a file name matches REGEXP, then use help mode MODE instead of the
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
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
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'
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
)
158 (setq keyword
(car arg
))
159 (or (symbolp keyword
)
160 (error "Junk in argument list \"%S\"" arg
))
163 (error "Keyword \"%S\" is missing an argument" keyword
))
164 (setq value
(car arg
)
166 (cond ((eq keyword
:topic
)
170 ((eq keyword
:regexp
)
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
)))
190 (setcdr topic-cell
(cons (cons mode data
) (cdr topic-cell
)))
191 (setcdr mode-cell data
))))
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
)))
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
246 (setq info-lookup-cache nil
))
248 ;;;###autoload (put 'info-lookup-symbol 'info-file "emacs")
250 (defun info-lookup-symbol (symbol &optional mode
)
251 "Display the definition of SYMBOL, as found in the relevant manual.
252 When this command is called interactively, it reads SYMBOL from the minibuffer.
253 In the minibuffer, use M-n to yank the default argument value
254 into the minibuffer so you can edit it.
255 The default symbol is the one found at point.
257 With prefix arg a query for the symbol help mode is offered."
259 (info-lookup-interactive-arguments 'symbol current-prefix-arg
))
260 (info-lookup 'symbol symbol mode
))
262 ;;;###autoload (put 'info-lookup-file 'info-file "emacs")
264 (defun info-lookup-file (file &optional mode
)
265 "Display the documentation of a file.
266 When this command is called interactively, it reads FILE from the minibuffer.
267 In the minibuffer, use M-n to yank the default file name
268 into the minibuffer so you can edit it.
269 The default file name is the one found at point.
271 With prefix arg a query for the file help mode is offered."
273 (info-lookup-interactive-arguments 'file current-prefix-arg
))
274 (info-lookup 'file file mode
))
276 (defun info-lookup-interactive-arguments (topic &optional query
)
277 "Read and return argument value (and help mode) for help topic TOPIC.
278 If optional argument QUERY is non-nil, query for the help mode."
279 (let* ((mode (cond (query
280 (info-lookup-change-mode topic
))
281 ((info-lookup->mode-value topic
(info-lookup-select-mode))
283 ((info-lookup-change-mode topic
))))
284 (completions (info-lookup->completions topic mode
))
285 (default (info-lookup-guess-default topic mode
))
286 (completion-ignore-case (info-lookup->ignore-case topic mode
))
287 (enable-recursive-minibuffers t
)
288 (value (completing-read
290 (format "Describe %s (default %s): " topic default
)
291 (format "Describe %s: " topic
))
292 completions nil nil nil
'info-lookup-history default
)))
293 (list (if (equal value
"") default value
) mode
)))
295 (defun info-lookup-select-mode ()
296 (when (and (not info-lookup-mode
) (buffer-file-name))
297 (let ((file-name (file-name-nondirectory (buffer-file-name)))
298 (file-name-alist info-lookup-file-name-alist
))
299 (while (and (not info-lookup-mode
) file-name-alist
)
300 (when (string-match (caar file-name-alist
) file-name
)
301 (setq info-lookup-mode
(cdar file-name-alist
)))
302 (setq file-name-alist
(cdr file-name-alist
)))))
303 (or info-lookup-mode
(setq info-lookup-mode major-mode
)))
305 (defun info-lookup-change-mode (topic)
306 (let* ((completions (mapcar (lambda (arg)
307 (cons (symbol-name (car arg
)) (car arg
)))
308 (info-lookup->topic-value topic
)))
309 (mode (completing-read
310 (format "Use %s help mode: " topic
)
311 completions nil t nil
'info-lookup-history
)))
312 (or (setq mode
(cdr (assoc mode completions
)))
313 (error "No %s help available" topic
))
314 (or (info-lookup->mode-value topic mode
)
315 (error "No %s help available for `%s'" topic mode
))
316 (setq info-lookup-mode mode
)))
318 (defun info-lookup (topic item mode
)
319 "Display the documentation of a help item."
320 (or mode
(setq mode
(info-lookup-select-mode)))
321 (or (info-lookup->mode-value topic mode
)
322 (error "No %s help available for `%s'" topic mode
))
323 (let* ((completions (info-lookup->completions topic mode
))
324 (ignore-case (info-lookup->ignore-case topic mode
))
325 (entry (or (assoc (if ignore-case
(downcase item
) item
) completions
)
326 (assoc-string item completions t
)
327 (error "Not documented as a %s: %s" topic
(or item
""))))
328 (modes (info-lookup->all-modes topic mode
))
329 (window (selected-window))
330 found doc-spec node prefix suffix doc-found
)
331 (if (not (eq major-mode
'Info-mode
))
332 (if (not info-lookup-other-window-flag
)
335 (save-window-excursion (info))
336 ;; Determine whether or not the Info buffer is visible in
337 ;; another frame on the same display. If it is, simply raise
338 ;; that frame. Otherwise, display it in another window.
339 (let* ((window (get-buffer-window "*info*" t
))
340 (info-frame (and window
(window-frame window
))))
342 (display-multi-frame-p)
343 (memq info-frame
(frames-on-display-list))
344 (not (eq info-frame
(selected-frame))))
345 (select-frame info-frame
)
346 (switch-to-buffer-other-window "*info*"))))))
347 (while (and (not found
) modes
)
348 (setq doc-spec
(info-lookup->doc-spec topic
(car modes
)))
349 (while (and (not found
) doc-spec
)
350 (setq node
(nth 0 (car doc-spec
))
351 prefix
(nth 2 (car doc-spec
))
352 suffix
(nth 3 (car doc-spec
)))
353 (when (condition-case error-data
355 (Info-goto-node node
)
358 (message "Cannot access Info node %s" node
)
363 ;; Don't use Info-menu, it forces case-fold-search to t
364 (let ((case-fold-search nil
))
366 (concat "^\\* " (regexp-quote (or (cdr entry
) (car entry
)))
368 (Info-follow-nearest-node)
370 (if (or prefix suffix
)
371 (let ((case-fold-search
372 (info-lookup->ignore-case topic
(car modes
)))
373 (buffer-read-only nil
))
374 (goto-char (point-min))
376 (concat prefix
(regexp-quote (car entry
)) suffix
))
377 (goto-char (match-beginning 0))
378 (and (display-color-p) info-lookup-highlight-face
379 ;; Search again for ITEM so that the first
380 ;; occurrence of ITEM will be highlighted.
381 (re-search-forward (regexp-quote (car entry
)))
382 (let ((start (match-beginning 0))
384 (if (overlayp info-lookup-highlight-overlay
)
385 (move-overlay info-lookup-highlight-overlay
386 start end
(current-buffer))
387 (setq info-lookup-highlight-overlay
388 (make-overlay start end
))))
389 (overlay-put info-lookup-highlight-overlay
390 'face info-lookup-highlight-face
)))))
392 (setq doc-spec
(cdr doc-spec
)))
393 (setq modes
(cdr modes
)))
394 ;; Alert the user if case was munged, and do this after bringing up the
395 ;; info buffer since that can print messages
396 (unless (or ignore-case
397 (string-equal item
(car entry
)))
398 (message "Found in different case: %s" (car entry
)))
400 (error "Info documentation for lookup was not found"))
401 ;; Don't leave the Info buffer if the help item couldn't be looked up.
402 (if (and info-lookup-other-window-flag found
)
403 (select-window window
))))
405 (defun info-lookup-setup-mode (topic mode
)
406 "Initialize the internal data structure."
407 (or (info-lookup->initialized topic mode
)
408 (let (cell data
(initialized 0) completions refer-modes
)
409 (if (not (info-lookup->mode-value topic mode
))
410 (message "No %s help available for `%s'" topic mode
)
411 ;; Recursively setup cross references.
412 ;; But refer only to non-void modes.
413 (dolist (arg (info-lookup->other-modes topic mode
))
414 (or (info-lookup->initialized topic arg
)
415 (info-lookup-setup-mode topic arg
))
416 (and (eq (info-lookup->initialized topic arg
) t
)
417 (setq refer-modes
(cons arg refer-modes
))))
418 (setq refer-modes
(nreverse refer-modes
))
419 ;; Build the full completion alist.
421 (nconc (condition-case nil
422 (info-lookup-make-completions topic mode
)
425 (mapcar (lambda (arg)
426 (info-lookup->completions topic arg
))
428 (setq initialized t
))
429 ;; Update `info-lookup-cache'.
430 (setq cell
(info-lookup->mode-cache topic mode
)
431 data
(list initialized completions refer-modes
))
433 (setcdr (info-lookup->cache topic
)
434 (cons (cons mode data
) (info-lookup->topic-cache topic
)))
438 (defun info-lookup-make-completions (topic mode
)
439 "Create a unique alist from all index entries."
440 (let ((doc-spec (info-lookup->doc-spec topic mode
))
441 (regexp (concat "^\\(" (info-lookup->regexp topic mode
)
442 "\\)\\([ \t].*\\)?$"))
443 node trans entry item prefix result doc-found
444 (buffer (get-buffer-create " temp-info-look")))
445 (with-current-buffer buffer
448 (setq node
(nth 0 (car doc-spec
))
449 trans
(cond ((eq (nth 1 (car doc-spec
)) nil
)
451 (if (string-match regexp arg
)
452 (match-string 1 arg
))))
453 ((stringp (nth 1 (car doc-spec
)))
454 (setq prefix
(nth 1 (car doc-spec
)))
456 (if (string-match "^\\([^: \t\n]+\\)" arg
)
457 (concat prefix
(match-string 1 arg
)))))
458 (t (nth 1 (car doc-spec
)))))
459 (with-current-buffer buffer
460 (message "Processing Info node `%s'..." node
)
461 (when (condition-case error-data
463 (Info-goto-node node
)
466 (message "Cannot access Info node `%s'" node
)
471 (goto-char (point-min))
472 (and (search-forward "\n* Menu:" nil t
)
473 (while (re-search-forward "\n\\* \\(.*\\): " nil t
)
474 (setq entry
(match-string 1)
475 item
(funcall trans entry
))
476 ;; `trans' can return nil if the regexp doesn't match.
478 ;; Sometimes there's more than one Menu:
479 (not (string= entry
"Menu")))
480 (and (info-lookup->ignore-case topic mode
)
481 (setq item
(downcase item
)))
482 (and (string-equal entry item
)
484 (and (or (assoc item result
)
485 (setq result
(cons (cons item entry
)
488 (message "Processing Info node `%s'...done" node
)
489 (setq doc-spec
(cdr doc-spec
)))
491 (error "Info documentation for lookup was not found"))
494 (defun info-lookup-guess-default (topic mode
)
495 "Return a guess for a symbol to look up, based on text around point.
496 Try all related modes applicable to TOPIC and MODE.
497 Return nil if there is nothing appropriate in the buffer near point."
498 (let ((modes (info-lookup->all-modes topic mode
))
500 (while (and (not guess
) modes
)
501 (setq guess
(info-lookup-guess-default* topic
(car modes
))
503 ;; Collapse whitespace characters.
506 (while (string-match "[ \t\n]+" guess pos
)
507 (setq pos
(1+ (match-beginning 0)))
508 (setq guess
(replace-match " " t t guess
)))))
511 (defun info-lookup-guess-default* (topic mode
)
512 (let ((case-fold-search (info-lookup->ignore-case topic mode
))
513 (rule (or (info-lookup->parse-rule topic mode
)
514 (info-lookup->regexp topic mode
)))
515 (start (point)) end regexp subexp result
)
518 (setq result
(funcall rule
))
520 (setq regexp
(car rule
)
524 ;; If at start of symbol, don't go back to end of previous one.
526 (looking-at "[ \t\n]"))
527 (skip-chars-backward " \t\n"))
529 (while (and (re-search-backward regexp nil t
)
531 (>= (match-end 0) end
))
532 (setq result
(match-string subexp
)))
536 (skip-chars-forward " \t\n")
537 (and (looking-at regexp
)
538 (setq result
(match-string subexp
)))))))
541 (defun info-lookup-guess-c-symbol ()
542 "Get the C symbol at point."
545 (skip-syntax-backward "w_")
546 (let ((start (point)) prefix name
)
547 ;; Test for a leading `struct', `union', or `enum' keyword
548 ;; but ignore names like `foo_struct'.
549 (setq prefix
(and (< (skip-chars-backward " \t\n") 0)
550 (< (skip-chars-backward "_a-zA-Z0-9") 0)
551 (looking-at "\\(struct\\|union\\|enum\\)\\s ")
552 (concat (match-string 1) " ")))
554 (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*")
555 (setq name
(match-string 0)))
556 ;; Caveat! Look forward if point is at `struct' etc.
558 (or (string-equal name
"struct")
559 (string-equal name
"union")
560 (string-equal name
"enum"))
561 (looking-at "[a-z]+\\s +\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
562 (setq prefix
(concat name
" ")
563 name
(match-string 1)))
564 (and (or prefix name
)
565 (concat prefix name
))))
569 (defun info-complete-symbol (&optional mode
)
570 "Perform completion on symbol preceding point."
572 (info-complete 'symbol
574 (if (info-lookup->mode-value
575 'symbol
(info-lookup-select-mode))
577 (info-lookup-change-mode 'symbol
)))))
580 (defun info-complete-file (&optional mode
)
581 "Perform completion on file preceding point."
585 (if (info-lookup->mode-value
586 'file
(info-lookup-select-mode))
588 (info-lookup-change-mode 'file
)))))
590 (defun info-complete (topic mode
)
591 "Try to complete a help item."
592 (barf-if-buffer-read-only)
593 (or mode
(setq mode
(info-lookup-select-mode)))
594 (or (info-lookup->mode-value topic mode
)
595 (error "No %s completion available for `%s'" topic mode
))
596 (let ((modes (info-lookup-quick-all-modes topic mode
))
599 (while (and (not try
) modes
)
600 (setq mode
(car modes
)
602 try
(info-lookup-guess-default* topic mode
))
605 (error "Found no %S to complete" topic
))
606 (let ((completions (info-lookup->completions topic mode
))
607 (completion-ignore-case (info-lookup->ignore-case topic mode
))
609 (setq completion
(try-completion try completions
))
610 (cond ((not completion
)
612 (message "No match"))
613 ((stringp completion
)
614 (or (assoc completion completions
)
615 (setq completion
(completing-read
616 (format "Complete %S: " topic
)
617 completions nil t completion
618 info-lookup-history
)))
619 ;; Find the original symbol and zap it.
621 (while (and (search-backward try nil t
)
626 (message "%s is complete"
627 (capitalize (prin1-to-string topic
))))))))
630 ;;; Initialize some common modes.
632 (info-lookup-maybe-add-help
633 :mode
'c-mode
:topic
'symbol
634 :regexp
"\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*"
635 :doc-spec
'(("(libc)Function Index" nil
636 "^[ \t]+-+ \\(Function\\|Macro\\): .*\\<" "\\>")
637 ;; prefix/suffix has to match things like
638 ;; " -- Macro: int F_DUPFD"
639 ;; " -- Variable: char * tzname [2]"
640 ;; "`DBL_MAX'" (texinfo @table)
641 ;; suffix "\\>" is not used because that sends DBL_MAX to
642 ;; DBL_MAX_EXP ("_" is a non-word char)
643 ("(libc)Variable Index" nil
644 "^\\([ \t]+-+ \\(Variable\\|Macro\\): .*\\<\\|`\\)"
646 ("(libc)Type Index" nil
647 "^[ \t]+-+ Data Type: \\<" "\\>")
648 ("(termcap)Var Index" nil
650 :parse-rule
'info-lookup-guess-c-symbol
)
652 (info-lookup-maybe-add-help
653 :mode
'c-mode
:topic
'file
654 :regexp
"[_a-zA-Z0-9./+-]+"
655 :doc-spec
'(("(libc)File Index")))
657 (info-lookup-maybe-add-help
659 :regexp
"[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+"
660 :doc-spec
'(("(bison)Index" nil
662 :parse-rule
"[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
663 :other-modes
'(c-mode))
665 (info-lookup-maybe-add-help
667 :regexp
"\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*"
668 :doc-spec
'(("(make)Name Index" nil
670 ("(automake)Macro and Variable Index" nil
672 :parse-rule
"\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+"
673 :other-modes
'(automake-mode))
675 (info-lookup-maybe-add-help
677 :regexp
"@\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
678 :doc-spec
'(("(texinfo)Command and Variable Index"
679 ;; Ignore Emacs commands and prepend a `@'.
681 (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item
)
682 (concat "@" (match-string 1 item
))))
685 (info-lookup-maybe-add-help
687 :regexp
"[_a-zA-Z][_a-zA-Z0-9]*"
688 :doc-spec
'(("(m4)Macro index"))
689 :parse-rule
"[_a-zA-Z0-9]+")
691 (info-lookup-maybe-add-help
693 :regexp
"A[CM]_[_A-Z0-9]+"
694 :doc-spec
'(;; Autoconf Macro Index entries are without an "AC_" prefix,
695 ;; but with "AH_" or "AU_" for those. So add "AC_" if there
696 ;; isn't already an "A._".
697 ("(autoconf)Autoconf Macro Index"
699 (if (string-match "^A._" item
) item
(concat "AC_" item
)))
700 "^[ \t]+-+ \\(Macro\\|Variable\\): .*\\<" "\\>")
701 ;; M4 Macro Index entries are without "AS_" prefixes, and
702 ;; mostly without "m4_" prefixes. "dnl" is an exception, not
703 ;; wanting any prefix. So AS_ is added back to upper-case
704 ;; names, m4_ to others which don't already an m4_.
705 ("(autoconf)M4 Macro Index"
707 (let ((case-fold-search nil
))
708 (cond ((or (string-equal item
"dnl")
709 (string-match "^m4_" item
))
711 ((string-match "^[A-Z0-9_]+$" item
)
714 (concat "m4_" item
)))))
715 "^[ \t]+-+ Macro: .*\\<" "\\>")
716 ;; Autotest Macro Index entries are without "AT_".
717 ("(autoconf)Autotest Macro Index" "AT_"
718 "^[ \t]+-+ Macro: .*\\<" "\\>")
719 ;; This is for older versions (probably pre autoconf 2.5x):
720 ("(autoconf)Macro Index" "AC_"
721 "^[ \t]+-+ \\(Macro\\|Variable\\): .*\\<" "\\>")
722 ;; Automake has index entries for its notes on various autoconf
723 ;; macros (eg. AC_PROG_CC). Ensure this is after the autoconf
724 ;; index, so as to prefer the autoconf docs.
725 ("(automake)Macro and Variable Index" nil
727 ;; Autoconf symbols are M4 macros. Thus use M4's parser.
729 :other-modes
'(m4-mode))
731 (info-lookup-maybe-add-help
734 :doc-spec
'(("(gawk)Index"
736 (let ((case-fold-search nil
))
738 ;; `BEGIN' and `END'.
739 ((string-match "^\\([A-Z]+\\) special pattern\\b" item
)
740 (match-string 1 item
))
741 ;; `if', `while', `do', ...
742 ((string-match "^\\([a-z]+\\) statement\\b" item
)
743 (if (not (string-equal (match-string 1 item
) "control"))
744 (match-string 1 item
)))
746 ((string-match "^[A-Z]+$" item
)
748 ;; Built-in functions (matches to many entries).
749 ((string-match "^[a-z]+$" item
)
751 "`" "\\([ \t]*([^)]*)\\)?'")))
753 (info-lookup-maybe-add-help
755 :regexp
"[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
756 :doc-spec
'(("(perl5)Function Index"
758 (if (string-match "^\\([a-zA-Z0-9]+\\)" item
)
759 (match-string 1 item
)))
761 ("(perl5)Variable Index"
763 ;; Work around bad formatted array variables.
764 (let ((sym (cond ((or (string-match "^\\$\\(.\\|@@\\)$" item
)
765 (string-match "^\\$\\^[A-Z]$" item
))
768 "^\\([$%@]\\|@@\\)?[_a-zA-Z0-9]+" item
)
769 (match-string 0 item
))
771 (if (string-match "@@" sym
)
772 (setq sym
(concat (substring sym
0 (match-beginning 0))
773 (substring sym
(1- (match-end 0))))))
774 (if (string-equal sym
"") nil sym
)))
776 :parse-rule
"[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)")
778 (info-lookup-maybe-add-help
780 :regexp
"[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
781 :other-modes
'(perl-mode))
783 (info-lookup-maybe-add-help
785 :regexp
"\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
786 :doc-spec
'(("(latex)Command Index" nil
787 "`" "\\({[^}]*}\\)?'")))
789 (info-lookup-maybe-add-help
790 :mode
'emacs-lisp-mode
791 :regexp
"[^][()'\" \t\n]+"
792 :doc-spec
'(;; Commands with key sequences appear in nodes as `foo' and
793 ;; those without as `M-x foo'.
794 ("(emacs)Command Index" nil
"`\\(M-x[ \t\n]+\\)?" "'")
795 ;; Variables normally appear in nodes as just `foo'.
796 ("(emacs)Variable Index" nil
"`" "'")
797 ;; Almost all functions, variables, etc appear in nodes as
798 ;; " -- Function: foo" etc. A small number of aliases and
799 ;; symbols appear only as `foo', and will miss out on exact
800 ;; positions. Allowing `foo' would hit too many false matches
801 ;; for things that should go to Function: etc, and those latter
802 ;; are much more important. Perhaps this could change if some
803 ;; sort of fallback match scheme existed.
804 ("(elisp)Index" nil
"^ -+ .*: " "\\( \\|$\\)")))
806 (info-lookup-maybe-add-help
807 :mode
'lisp-interaction-mode
808 :regexp
"[^][()'\" \t\n]+"
810 :other-modes
'(emacs-lisp-mode))
812 (info-lookup-maybe-add-help
814 :regexp
"[^()'\" \t\n]+"
816 :other-modes
'(emacs-lisp-mode))
818 (info-lookup-maybe-add-help
820 :regexp
"[^()`',\" \t\n]+"
822 ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm>
823 :doc-spec
'(("(r5rs)Index" nil
824 "^[ \t]+-+ [^:]+:[ \t]*" "\\b")))
826 (info-lookup-maybe-add-help
828 :regexp
"[_a-zA-Z0-9]+"
829 :doc-spec
'(("(octave)Function Index" nil
830 "^ -+ [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil
)
831 ("(octave)Variable Index" nil
"^ -+ [^:]+:[ ]+" nil
)
832 ;; Catch lines of the form "xyz statement"
833 ("(octave)Concept Index"
836 ((string-match "^\\([A-Z]+\\) statement\\b" item
)
837 (match-string 1 item
))
839 nil
; "^ -+ [^:]+:[ ]+" don't think this prefix is useful here.
842 (info-lookup-maybe-add-help
845 :regexp
"[a-zA-Z_%]+"
846 :doc-spec
'( ("(maxima)Function and Variable Index" nil
847 "^ -+ [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil
)))
849 (info-lookup-maybe-add-help
850 :mode
'inferior-maxima-mode
851 :other-modes
'(maxima-mode))
853 ;; coreutils and bash builtins overlap in places, eg. printf, so there's a
854 ;; question which should come first. Some of the coreutils descriptions are
855 ;; more detailed, but if bash is usually /bin/sh on a GNU system then the
856 ;; builtins will be what's normally run.
858 ;; Maybe special variables like $? should be matched as $?, not just ?.
859 ;; This would avoid a clash between variable $! and negation !, or variable
860 ;; $# and comment # (though comment # is not currently indexed in bash).
861 ;; Unfortunately if $? etc is the symbol, then we wouldn't be taken to the
862 ;; exact spot in the relevant node, since the bash manual has just `?' etc
863 ;; there. Maybe an extension to the prefix/suffix scheme could help this.
865 (info-lookup-maybe-add-help
866 :mode
'sh-mode
:topic
'symbol
867 ;; bash has "." and ":" in its index, but those chars will probably never
868 ;; work in info, so don't bother matching them in the regexp.
869 :regexp
"\\([a-zA-Z0-9_-]+\\|[!{}@*#?$]\\|\\[\\[?\\|]]?\\)"
870 :doc-spec
'(("(bash)Builtin Index" nil
"^`" "[ .']")
871 ("(bash)Reserved Word Index" nil
"^`" "[ .']")
872 ("(bash)Variable Index" nil
"^`" "[ .']")
873 ;; coreutils (version 4.5.10) doesn't have a separate program
874 ;; index, so exclude extraneous stuff (most of it) by demanding
875 ;; "[a-z]+" in the trans-func.
877 (lambda (item) (if (string-match "\\`[a-z]+\\'" item
) item
)))
878 ;; diff (version 2.8.1) has only a few programs, index entries
879 ;; are things like "foo invocation".
882 (if (string-match "\\`\\([a-z]+\\) invocation\\'" item
)
883 (match-string 1 item
))))
884 ;; there's no plain "sed" index entry as such, mung another
885 ;; hopefully unique one to get to the invocation section
886 ("(sed)Concept Index"
888 (if (string-equal item
"Standard input, processing as input")
890 ;; there's no plain "awk" or "gawk" index entries, mung other
891 ;; hopefully unique ones to get to the command line options
894 (cond ((string-equal item
"gawk, extensions, disabling")
896 ((string-equal item
"gawk, versions of, information about, printing")
899 ;; This misses some things which occur as node names but not in the
900 ;; index. Unfortunately it also picks up the wrong one of multiple
901 ;; entries for the same term in some cases. --fx
902 (info-lookup-maybe-add-help
904 :regexp
"[[:alnum:]_]+\\(?:()\\)?"
905 :doc-spec
'(("(cfengine-Reference)Variable Index"
907 ;; Index entries may be like `IsPlain()'
908 (if (string-match "\\([[:alnum:]_]+\\)()" item
)
909 (match-string 1 item
)
911 ;; This gets functions in evaluated classes. Other
912 ;; possible patterns don't seem to work too well.
917 ;;; arch-tag: 0f1e3ea3-32a2-4461-bbab-3cff93539a74
918 ;;; info-look.el ends here