(Funibyte_char_to_multibyte): Export.
[emacs.git] / lisp / info-look.el
blob1de84d3e4216b7d59367f791e7a8318fc480b574
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 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)
15 ;; any later version.
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.
27 ;;; Commentary:
29 ;; Really cool code to lookup info indexes.
30 ;; Try especially info-lookup-symbol (aka C-h TAB).
32 ;;; Code:
34 (require 'info)
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 'highlight
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
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* ((completions (info-lookup->completions topic mode))
322 (ignore-case (info-lookup->ignore-case topic mode))
323 (entry (or (assoc (if ignore-case (downcase item) item) completions)
324 (assoc-ignore-case item completions)
325 (error "Not documented as a %s: %s" topic (or item ""))))
326 (modes (info-lookup->all-modes topic mode))
327 (window (selected-window))
328 found doc-spec node prefix suffix doc-found)
329 (if (or (not info-lookup-other-window-flag)
330 (eq (current-buffer) (get-buffer "*info*")))
331 (info)
332 (progn
333 (save-window-excursion (info))
334 ;; Determine whether or not the Info buffer is visible in
335 ;; another frame on the same display. If it is, simply raise
336 ;; that frame. Otherwise, display it in another window.
337 (let* ((window (get-buffer-window "*info*" t))
338 (info-frame (and window (window-frame window))))
339 (if (and info-frame
340 (display-multi-frame-p)
341 (memq info-frame (frames-on-display-list)))
342 (select-frame info-frame)
343 (switch-to-buffer-other-window "*info*")))))
344 (while (and (not found) modes)
345 (setq doc-spec (info-lookup->doc-spec topic (car modes)))
346 (while (and (not found) doc-spec)
347 (setq node (nth 0 (car doc-spec))
348 prefix (nth 2 (car doc-spec))
349 suffix (nth 3 (car doc-spec)))
350 (when (condition-case error-data
351 (progn
352 (Info-goto-node node)
353 (setq doc-found t))
354 (error
355 (message "Cannot access Info node %s" node)
356 (sit-for 1)
357 nil))
358 (condition-case nil
359 (progn
360 ;; Don't use Info-menu, it forces case-fold-search to t
361 (let ((case-fold-search nil))
362 (re-search-forward
363 (concat "^\\* " (regexp-quote (or (cdr entry) (car entry)))
364 ":")))
365 (Info-follow-nearest-node)
366 (setq found t)
367 (if (or prefix suffix)
368 (let ((case-fold-search
369 (info-lookup->ignore-case topic (car modes)))
370 (buffer-read-only nil))
371 (goto-char (point-min))
372 (re-search-forward
373 (concat prefix (regexp-quote (car entry)) suffix))
374 (goto-char (match-beginning 0))
375 (and (display-color-p) info-lookup-highlight-face
376 ;; Search again for ITEM so that the first
377 ;; occurrence of ITEM will be highlighted.
378 (re-search-forward (regexp-quote (car entry)))
379 (let ((start (match-beginning 0))
380 (end (match-end 0)))
381 (if (overlayp info-lookup-highlight-overlay)
382 (move-overlay info-lookup-highlight-overlay
383 start end (current-buffer))
384 (setq info-lookup-highlight-overlay
385 (make-overlay start end))))
386 (overlay-put info-lookup-highlight-overlay
387 'face info-lookup-highlight-face)))))
388 (error nil)))
389 (setq doc-spec (cdr doc-spec)))
390 (setq modes (cdr modes)))
391 ;; Alert the user if case was munged, and do this after bringing up the
392 ;; info buffer since that can print messages
393 (unless (or ignore-case
394 (string-equal item (car entry)))
395 (message "Found in different case: %s" (car entry)))
396 (or doc-found
397 (error "Info documentation for lookup was not found"))
398 ;; Don't leave the Info buffer if the help item couldn't be looked up.
399 (if (and info-lookup-other-window-flag found)
400 (select-window window))))
402 (defun info-lookup-setup-mode (topic mode)
403 "Initialize the internal data structure."
404 (or (info-lookup->initialized topic mode)
405 (let (cell data (initialized 0) completions refer-modes)
406 (if (not (info-lookup->mode-value topic mode))
407 (message "No %s help available for `%s'" topic mode)
408 ;; Recursively setup cross references.
409 ;; But refer only to non-void modes.
410 (mapcar (lambda (arg)
411 (or (info-lookup->initialized topic arg)
412 (info-lookup-setup-mode topic arg))
413 (and (eq (info-lookup->initialized topic arg) t)
414 (setq refer-modes (cons arg refer-modes))))
415 (info-lookup->other-modes topic mode))
416 (setq refer-modes (nreverse refer-modes))
417 ;; Build the full completion alist.
418 (setq completions
419 (nconc (condition-case nil
420 (info-lookup-make-completions topic mode)
421 (error nil))
422 (apply 'append
423 (mapcar (lambda (arg)
424 (info-lookup->completions topic arg))
425 refer-modes))))
426 (setq initialized t))
427 ;; Update `info-lookup-cache'.
428 (setq cell (info-lookup->mode-cache topic mode)
429 data (list initialized completions refer-modes))
430 (if (not cell)
431 (setcdr (info-lookup->cache topic)
432 (cons (cons mode data) (info-lookup->topic-cache topic)))
433 (setcdr cell data))
434 initialized)))
436 (defun info-lookup-make-completions (topic mode)
437 "Create a unique alist from all index entries."
438 (let ((doc-spec (info-lookup->doc-spec topic mode))
439 (regexp (concat "^\\(" (info-lookup->regexp topic mode)
440 "\\)\\([ \t].*\\)?$"))
441 node trans entry item prefix result doc-found
442 (buffer (get-buffer-create " temp-info-look")))
443 (with-current-buffer buffer
444 (Info-mode))
445 (while doc-spec
446 (setq node (nth 0 (car doc-spec))
447 trans (cond ((eq (nth 1 (car doc-spec)) nil)
448 (lambda (arg)
449 (if (string-match regexp arg)
450 (match-string 1 arg))))
451 ((stringp (nth 1 (car doc-spec)))
452 (setq prefix (nth 1 (car doc-spec)))
453 (lambda (arg)
454 (if (string-match "^\\([^: \t\n]+\\)" arg)
455 (concat prefix (match-string 1 arg)))))
456 (t (nth 1 (car doc-spec)))))
457 (with-current-buffer buffer
458 (message "Processing Info node `%s'..." node)
459 (when (condition-case error-data
460 (progn
461 (Info-goto-node node)
462 (setq doc-found t))
463 (error
464 (message "Cannot access Info node `%s'" node)
465 (sit-for 1)
466 nil))
467 (condition-case nil
468 (progn
469 (goto-char (point-min))
470 (and (search-forward "\n* Menu:" nil t)
471 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
472 (setq entry (match-string 1)
473 item (funcall trans entry))
474 ;; `trans' can return nil if the regexp doesn't match.
475 (when (and item
476 ;; Sometimes there's more than one Menu:
477 (not (string= entry "Menu")))
478 (and (info-lookup->ignore-case topic mode)
479 (setq item (downcase item)))
480 (and (string-equal entry item)
481 (setq entry nil))
482 (and (or (assoc item result)
483 (setq result (cons (cons item entry)
484 result))))))))
485 (error nil))))
486 (message "Processing Info node `%s'...done" node)
487 (setq doc-spec (cdr doc-spec)))
488 (or doc-found
489 (error "Info documentation for lookup was not found"))
490 result))
492 (defun info-lookup-guess-default (topic mode)
493 "Return a guess for a symbol to look up, based on text around point.
494 Try all related modes applicable to TOPIC and MODE.
495 Return nil if there is nothing appropriate in the buffer near point."
496 (let ((modes (info-lookup->all-modes topic mode))
497 guess)
498 (while (and (not guess) modes)
499 (setq guess (info-lookup-guess-default* topic (car modes))
500 modes (cdr modes)))
501 ;; Collapse whitespace characters.
502 (when guess
503 (let ((pos 0))
504 (while (string-match "[ \t\n]+" guess pos)
505 (setq pos (1+ (match-beginning 0)))
506 (setq guess (replace-match " " t t guess)))))
507 guess))
509 (defun info-lookup-guess-default* (topic mode)
510 (let ((case-fold-search (info-lookup->ignore-case topic mode))
511 (rule (or (info-lookup->parse-rule topic mode)
512 (info-lookup->regexp topic mode)))
513 (start (point)) end regexp subexp result)
514 (save-excursion
515 (if (symbolp rule)
516 (setq result (funcall rule))
517 (if (consp rule)
518 (setq regexp (car rule)
519 subexp (cdr rule))
520 (setq regexp rule
521 subexp 0))
522 ;; If at start of symbol, don't go back to end of previous one.
523 (if (save-match-data
524 (looking-at "[ \t\n]"))
525 (skip-chars-backward " \t\n"))
526 (setq end (point))
527 (while (and (re-search-backward regexp nil t)
528 (looking-at regexp)
529 (>= (match-end 0) end))
530 (setq result (match-string subexp)))
531 (if (not result)
532 (progn
533 (goto-char start)
534 (skip-chars-forward " \t\n")
535 (and (looking-at regexp)
536 (setq result (match-string subexp)))))))
537 result))
539 (defun info-lookup-guess-c-symbol ()
540 "Get the C symbol at point."
541 (condition-case nil
542 (progn
543 (skip-syntax-backward "w_")
544 (let ((start (point)) prefix name)
545 ;; Test for a leading `struct', `union', or `enum' keyword
546 ;; but ignore names like `foo_struct'.
547 (setq prefix (and (< (skip-chars-backward " \t\n") 0)
548 (< (skip-chars-backward "_a-zA-Z0-9") 0)
549 (looking-at "\\(struct\\|union\\|enum\\)\\s ")
550 (concat (match-string 1) " ")))
551 (goto-char start)
552 (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*")
553 (setq name (match-string 0)))
554 ;; Caveat! Look forward if point is at `struct' etc.
555 (and (not prefix)
556 (or (string-equal name "struct")
557 (string-equal name "union")
558 (string-equal name "enum"))
559 (looking-at "[a-z]+\\s +\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
560 (setq prefix (concat name " ")
561 name (match-string 1)))
562 (and (or prefix name)
563 (concat prefix name))))
564 (error nil)))
566 ;;;###autoload
567 (defun info-complete-symbol (&optional mode)
568 "Perform completion on symbol preceding point."
569 (interactive)
570 (info-complete 'symbol
571 (or mode
572 (if (info-lookup->mode-value
573 'symbol (info-lookup-select-mode))
574 info-lookup-mode
575 (info-lookup-change-mode 'symbol)))))
577 ;;;###autoload
578 (defun info-complete-file (&optional mode)
579 "Perform completion on file preceding point."
580 (interactive)
581 (info-complete 'file
582 (or mode
583 (if (info-lookup->mode-value
584 'file (info-lookup-select-mode))
585 info-lookup-mode
586 (info-lookup-change-mode 'file)))))
588 (defun info-complete (topic mode)
589 "Try to complete a help item."
590 (barf-if-buffer-read-only)
591 (or mode (setq mode (info-lookup-select-mode)))
592 (or (info-lookup->mode-value topic mode)
593 (error "No %s completion available for `%s'" topic mode))
594 (let ((modes (info-lookup-quick-all-modes topic mode))
595 (start (point))
596 try)
597 (while (and (not try) modes)
598 (setq mode (car modes)
599 modes (cdr modes)
600 try (info-lookup-guess-default* topic mode))
601 (goto-char start))
602 (and (not try)
603 (error "Found no %S to complete" topic))
604 (let ((completions (info-lookup->completions topic mode))
605 (completion-ignore-case (info-lookup->ignore-case topic mode))
606 completion)
607 (setq completion (try-completion try completions))
608 (cond ((not completion)
609 (ding)
610 (message "No match"))
611 ((stringp completion)
612 (or (assoc completion completions)
613 (setq completion (completing-read
614 (format "Complete %S: " topic)
615 completions nil t completion
616 info-lookup-history)))
617 ;; Find the original symbol and zap it.
618 (end-of-line)
619 (while (and (search-backward try nil t)
620 (< start (point))))
621 (replace-match "")
622 (insert completion))
624 (message "%s is complete"
625 (capitalize (prin1-to-string topic))))))))
628 ;;; Initialize some common modes.
630 (info-lookup-maybe-add-help
631 :mode 'c-mode :topic 'symbol
632 :regexp "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*"
633 :doc-spec '(("(libc)Function Index" nil
634 "^[ \t]+- \\(Function\\|Macro\\): .*\\<" "\\>")
635 ("(libc)Variable Index" nil
636 "^[ \t]+- \\(Variable\\|Macro\\): .*\\<" "\\>")
637 ("(libc)Type Index" nil
638 "^[ \t]+- Data Type: \\<" "\\>")
639 ("(termcap)Var Index" nil
640 "^[ \t]*`" "'"))
641 :parse-rule 'info-lookup-guess-c-symbol)
643 (info-lookup-maybe-add-help
644 :mode 'c-mode :topic 'file
645 :regexp "[_a-zA-Z0-9./+-]+"
646 :doc-spec '(("(libc)File Index")))
648 (info-lookup-maybe-add-help
649 :mode 'bison-mode
650 :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+"
651 :doc-spec '(("(bison)Index" nil
652 "`" "'"))
653 :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
654 :other-modes '(c-mode))
656 (info-lookup-maybe-add-help
657 :mode 'makefile-mode
658 :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*"
659 :doc-spec '(("(make)Name Index" nil
660 "^[ \t]*`" "'")
661 ("(automake)Macro and Variable Index" nil
662 "^[ \t]*`" "'"))
663 :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+"
664 :other-modes '(automake-mode))
666 (info-lookup-maybe-add-help
667 :mode 'texinfo-mode
668 :regexp "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
669 :doc-spec '(("(texinfo)Command and Variable Index"
670 ;; Ignore Emacs commands and prepend a `@'.
671 (lambda (item)
672 (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item)
673 (concat "@" (match-string 1 item))))
674 "`" "'")))
676 (info-lookup-maybe-add-help
677 :mode 'm4-mode
678 :regexp "[_a-zA-Z][_a-zA-Z0-9]*"
679 :doc-spec '(("(m4)Macro index"))
680 :parse-rule "[_a-zA-Z0-9]+")
682 (info-lookup-maybe-add-help
683 :mode 'autoconf-mode
684 :regexp "A[CM]_[_A-Z0-9]+"
685 :doc-spec '(("(autoconf)Autoconf Macro Index" "AC_"
686 "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
687 ("(automake)Macro and Variable Index" nil
688 "^[ \t]*`" "'")
689 ;; These are for older versions (probably pre autoconf 2.5x):
690 ("(autoconf)Macro Index" "AC_"
691 "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
692 ("(automake)Macro and Variable Index" nil
693 "^[ \t]*`" "'"))
694 ;; Autoconf symbols are M4 macros. Thus use M4's parser.
695 :parse-rule 'ignore
696 :other-modes '(m4-mode))
698 (info-lookup-maybe-add-help
699 :mode 'awk-mode
700 :regexp "[_a-zA-Z]+"
701 :doc-spec '(("(gawk)Index"
702 (lambda (item)
703 (let ((case-fold-search nil))
704 (cond
705 ;; `BEGIN' and `END'.
706 ((string-match "^\\([A-Z]+\\) special pattern\\b" item)
707 (match-string 1 item))
708 ;; `if', `while', `do', ...
709 ((string-match "^\\([a-z]+\\) statement\\b" item)
710 (if (not (string-equal (match-string 1 item) "control"))
711 (match-string 1 item)))
712 ;; `NR', `NF', ...
713 ((string-match "^[A-Z]+$" item)
714 item)
715 ;; Built-in functions (matches to many entries).
716 ((string-match "^[a-z]+$" item)
717 item))))
718 "`" "\\([ \t]*([^)]*)\\)?'")))
720 (info-lookup-maybe-add-help
721 :mode 'perl-mode
722 :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
723 :doc-spec '(("(perl5)Function Index"
724 (lambda (item)
725 (if (string-match "^\\([a-zA-Z0-9]+\\)" item)
726 (match-string 1 item)))
727 "^" "\\b")
728 ("(perl5)Variable Index"
729 (lambda (item)
730 ;; Work around bad formatted array variables.
731 (let ((sym (cond ((or (string-match "^\\$\\(.\\|@@\\)$" item)
732 (string-match "^\\$\\^[A-Z]$" item))
733 item)
734 ((string-match
735 "^\\([$%@]\\|@@\\)?[_a-zA-Z0-9]+" item)
736 (match-string 0 item))
737 (t ""))))
738 (if (string-match "@@" sym)
739 (setq sym (concat (substring sym 0 (match-beginning 0))
740 (substring sym (1- (match-end 0))))))
741 (if (string-equal sym "") nil sym)))
742 "^" "\\b"))
743 :parse-rule "[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)")
745 (info-lookup-maybe-add-help
746 :mode 'cperl-mode
747 :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*"
748 :other-modes '(perl-mode))
750 (info-lookup-maybe-add-help
751 :mode 'latex-mode
752 :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)"
753 :doc-spec '(("(latex)Command Index" nil
754 "`" "\\({[^}]*}\\)?'")))
756 (info-lookup-maybe-add-help
757 :mode 'emacs-lisp-mode
758 :regexp "[^][()'\" \t\n]+"
759 :doc-spec '(("(emacs)Command Index")
760 ("(emacs)Variable Index")
761 ("(elisp)Index")))
763 (info-lookup-maybe-add-help
764 :mode 'lisp-interaction-mode
765 :regexp "[^][()'\" \t\n]+"
766 :parse-rule 'ignore
767 :other-modes '(emacs-lisp-mode))
769 (info-lookup-maybe-add-help
770 :mode 'lisp-mode
771 :regexp "[^()'\" \t\n]+"
772 :parse-rule 'ignore
773 :other-modes '(emacs-lisp-mode))
775 (info-lookup-maybe-add-help
776 :mode 'scheme-mode
777 :regexp "[^()'\" \t\n]+"
778 :ignore-case t
779 ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm>
780 :doc-spec '(("(r5rs)Index" nil
781 "^[ \t]+- [^:]+:[ \t]*" "\\b")))
783 (info-lookup-maybe-add-help
784 :mode 'octave-mode
785 :regexp "[_a-zA-Z0-9]+"
786 :doc-spec '(("(octave)Function Index" nil
787 "^ - [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil)
788 ("(octave)Variable Index" nil "^ - [^:]+:[ ]+" nil)
789 ;; Catch lines of the form "xyz statement"
790 ("(octave)Concept Index"
791 (lambda (item)
792 (cond
793 ((string-match "^\\([A-Z]+\\) statement\\b" item)
794 (match-string 1 item))
795 (t nil)))
796 nil; "^ - [^:]+:[ ]+" don't think this prefix is useful here.
797 nil)))
799 (provide 'info-look)
801 ;;; info-look.el ends here