diff options
| author | Richard M. Stallman | 1998-02-17 03:25:05 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-17 03:25:05 +0000 |
| commit | d2c2b883830f03cb9035bb8ca91661f73b8e280b (patch) | |
| tree | 7a45cdf17c81aae1d63c1cb2f99c4f7a6b72a145 | |
| parent | cc6e2aaa2ae4f98baa4f450f4732f36e9a5c4061 (diff) | |
| download | emacs-d2c2b883830f03cb9035bb8ca91661f73b8e280b.tar.gz emacs-d2c2b883830f03cb9035bb8ca91661f73b8e280b.zip | |
(info-complete): Rewrite minibuffer completion code.
(info-lookup-minor-mode, turn-on-info-lookup):
Added minor mode interface.
(info-lookup-minor-mode-string): New variable.
(info-lookup-minor-mode-map): New variable.
Provide a work-around if the custom library is not available.
(info-lookup-other-window-flag)
(info-lookup-highlight-face): Variables customized.
(info-lookup-alist): No longer customizable.
(info-lookup-add-help, info-lookup-maybe-add-help): Interface
functions for adding new modes.
(info-lookup-add-help*): New function.
(info-lookup-symbol-alist, info-lookup-file-alist): Variables deleted.
This info is specified now by calling info-lookup-maybe-add-help
and info-lookup-add-help.
| -rw-r--r-- | lisp/info-look.el | 471 |
1 files changed, 300 insertions, 171 deletions
diff --git a/lisp/info-look.el b/lisp/info-look.el index 010d073bdce..c7667fa91a8 100644 --- a/lisp/info-look.el +++ b/lisp/info-look.el | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | ;;; info-look.el --- major-mode-sensitive Info index lookup facility. | 1 | ;;; info-look.el --- major-mode-sensitive Info index lookup facility. |
| 2 | ;; An older version of this was known as libc.el. | 2 | ;; An older version of this was known as libc.el. |
| 3 | 3 | ||
| 4 | ;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. | 4 | ;; Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: Ralph Schleicher <rs@purple.UL.BaWue.DE> | 6 | ;; Author: Ralph Schleicher <rs@purple.UL.BaWue.DE> |
| 7 | ;; Keywords: help languages | 7 | ;; Keywords: help languages |
| @@ -26,19 +26,33 @@ | |||
| 26 | ;;; Code: | 26 | ;;; Code: |
| 27 | 27 | ||
| 28 | (require 'info) | 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) | ||
| 29 | 41 | ||
| 30 | (defvar info-lookup-mode nil | 42 | (defvar info-lookup-mode nil |
| 31 | "*Symbol of the current buffer's help mode. | 43 | "Symbol of the current buffer's help mode. |
| 32 | Provide help according to the buffer's major mode if value is nil. | 44 | Help is provided according to the buffer's major mode if value is nil. |
| 33 | Automatically becomes buffer local when set in any fashion.") | 45 | Automatically becomes buffer local when set in any fashion.") |
| 34 | (make-variable-buffer-local 'info-lookup-mode) | 46 | (make-variable-buffer-local 'info-lookup-mode) |
| 35 | 47 | ||
| 36 | (defvar info-lookup-other-window-flag t | 48 | (defcustom info-lookup-other-window-flag t |
| 37 | "*Non-nil means pop up the Info buffer in another window.") | 49 | "Non-nil means pop up the Info buffer in another window." |
| 50 | :group 'info-lookup :type 'boolean) | ||
| 38 | 51 | ||
| 39 | (defvar info-lookup-highlight-face 'highlight | 52 | (defcustom info-lookup-highlight-face 'highlight |
| 40 | "*Face for highlighting looked up help items. | 53 | "Face for highlighting looked up help items. |
| 41 | Setting this variable to nil disables highlighting.") | 54 | Setting this variable to nil disables highlighting." |
| 55 | :group 'info-lookup :type 'face) | ||
| 42 | 56 | ||
| 43 | (defvar info-lookup-highlight-overlay nil | 57 | (defvar info-lookup-highlight-overlay nil |
| 44 | "Overlay object used for highlighting.") | 58 | "Overlay object used for highlighting.") |
| @@ -46,15 +60,14 @@ Setting this variable to nil disables highlighting.") | |||
| 46 | (defvar info-lookup-history nil | 60 | (defvar info-lookup-history nil |
| 47 | "History of previous input lines.") | 61 | "History of previous input lines.") |
| 48 | 62 | ||
| 49 | (defvar info-lookup-alist '((symbol . info-lookup-symbol-alist) | 63 | (defvar info-lookup-alist nil |
| 50 | (file . info-lookup-file-alist)) | 64 | "Alist of known help topics. |
| 51 | "*Alist of known help topics. | ||
| 52 | Cons cells are of the form | 65 | Cons cells are of the form |
| 53 | 66 | ||
| 54 | (HELP-TOPIC . VARIABLE) | 67 | (HELP-TOPIC . HELP-DATA) |
| 55 | 68 | ||
| 56 | HELP-TOPIC is the symbol of a help topic. | 69 | HELP-TOPIC is the symbol of a help topic. |
| 57 | VARIABLE is a variable storing HELP-TOPIC's public data. | 70 | HELP-DATA is a HELP-TOPIC's public data set. |
| 58 | Value is an alist with elements of the form | 71 | Value is an alist with elements of the form |
| 59 | 72 | ||
| 60 | (HELP-MODE REGEXP IGNORE-CASE DOC-SPEC PARSE-RULE OTHER-MODES) | 73 | (HELP-MODE REGEXP IGNORE-CASE DOC-SPEC PARSE-RULE OTHER-MODES) |
| @@ -84,7 +97,7 @@ PARSE-RULE is either the symbol name of a function or a regular | |||
| 84 | OTHER-MODES is a list of cross references to other help modes.") | 97 | OTHER-MODES is a list of cross references to other help modes.") |
| 85 | 98 | ||
| 86 | (defsubst info-lookup->topic-value (topic) | 99 | (defsubst info-lookup->topic-value (topic) |
| 87 | (symbol-value (cdr (assoc topic info-lookup-alist)))) | 100 | (cdr (assoc topic info-lookup-alist))) |
| 88 | 101 | ||
| 89 | (defsubst info-lookup->mode-value (topic mode) | 102 | (defsubst info-lookup->mode-value (topic mode) |
| 90 | (assoc mode (info-lookup->topic-value topic))) | 103 | (assoc mode (info-lookup->topic-value topic))) |
| @@ -104,6 +117,77 @@ OTHER-MODES is a list of cross references to other help modes.") | |||
| 104 | (defsubst info-lookup->other-modes (topic mode) | 117 | (defsubst info-lookup->other-modes (topic mode) |
| 105 | (nth 5 (info-lookup->mode-value topic mode))) | 118 | (nth 5 (info-lookup->mode-value topic mode))) |
| 106 | 119 | ||
| 120 | (eval-and-compile | ||
| 121 | (mapcar (lambda (keyword) | ||
| 122 | (or (boundp keyword) | ||
| 123 | (set keyword keyword))) | ||
| 124 | '(:topic :mode :regexp :ignore-case | ||
| 125 | :doc-spec :parse-rule :other-modes))) | ||
| 126 | |||
| 127 | (defun info-lookup-add-help (&rest arg) | ||
| 128 | "Add or update a help specification. | ||
| 129 | Function arguments are one or more options of the form | ||
| 130 | |||
| 131 | KEYWORD ARGUMENT | ||
| 132 | |||
| 133 | KEYWORD is either `:topic', `:mode', `:regexp', `:ignore-case', | ||
| 134 | `:doc-spec', `:parse-rule', or `:other-modes'. | ||
| 135 | ARGUMENT has a value as explained in the documentation of the | ||
| 136 | variable `info-lookup-alist'. | ||
| 137 | |||
| 138 | If no topic or mode option has been specified, then the help topic defaults | ||
| 139 | to `symbol', and the help mode defaults to the current major mode." | ||
| 140 | (apply 'info-lookup-add-help* nil arg)) | ||
| 141 | |||
| 142 | (defun info-lookup-maybe-add-help (&rest arg) | ||
| 143 | "Add a help specification iff no one is defined. | ||
| 144 | See the documentation of the function `info-lookup-add-help' | ||
| 145 | for more details." | ||
| 146 | (apply 'info-lookup-add-help* t arg)) | ||
| 147 | |||
| 148 | (defun info-lookup-add-help* (maybe &rest arg) | ||
| 149 | (let (topic mode regexp ignore-case doc-spec | ||
| 150 | parse-rule other-modes keyword value) | ||
| 151 | (setq topic 'symbol | ||
| 152 | mode major-mode | ||
| 153 | regexp "\\w+") | ||
| 154 | (while arg | ||
| 155 | (setq keyword (car arg)) | ||
| 156 | (or (symbolp keyword) | ||
| 157 | (error "Junk in argument list \"%S\"" arg)) | ||
| 158 | (setq arg (cdr arg)) | ||
| 159 | (and (null arg) | ||
| 160 | (error "Keyword \"%S\" is missing an argument" keyword)) | ||
| 161 | (setq value (car arg) | ||
| 162 | arg (cdr arg)) | ||
| 163 | (cond ((eq keyword :topic) | ||
| 164 | (setq topic value)) | ||
| 165 | ((eq keyword :mode) | ||
| 166 | (setq mode value)) | ||
| 167 | ((eq keyword :regexp) | ||
| 168 | (setq regexp value)) | ||
| 169 | ((eq keyword :ignore-case) | ||
| 170 | (setq ignore-case value)) | ||
| 171 | ((eq keyword :doc-spec) | ||
| 172 | (setq doc-spec value)) | ||
| 173 | ((eq keyword :parse-rule) | ||
| 174 | (setq parse-rule value)) | ||
| 175 | ((eq keyword :other-modes) | ||
| 176 | (setq other-modes value)) | ||
| 177 | (t | ||
| 178 | (error "Unknown keyword \"%S\"" keyword)))) | ||
| 179 | (or (and maybe (info-lookup->mode-value topic mode)) | ||
| 180 | (let* ((data (list regexp ignore-case doc-spec parse-rule other-modes)) | ||
| 181 | (topic-cell (or (assoc topic info-lookup-alist) | ||
| 182 | (car (setq info-lookup-alist | ||
| 183 | (cons (cons topic nil) | ||
| 184 | info-lookup-alist))))) | ||
| 185 | (mode-cell (assoc mode topic-cell))) | ||
| 186 | (if (null mode-cell) | ||
| 187 | (setcdr topic-cell (cons (cons mode data) (cdr topic-cell))) | ||
| 188 | (setcdr mode-cell data)))) | ||
| 189 | nil)) | ||
| 190 | |||
| 107 | (defvar info-lookup-cache nil | 191 | (defvar info-lookup-cache nil |
| 108 | "Cache storing data maintained automatically by the program. | 192 | "Cache storing data maintained automatically by the program. |
| 109 | Value is an alist with cons cell of the form | 193 | Value is an alist with cons cell of the form |
| @@ -146,136 +230,6 @@ REFER-MODES is a list of other help modes to use.") | |||
| 146 | (defsubst info-lookup->all-modes (topic mode) | 230 | (defsubst info-lookup->all-modes (topic mode) |
| 147 | (cons mode (info-lookup->refer-modes topic mode))) | 231 | (cons mode (info-lookup->refer-modes topic mode))) |
| 148 | 232 | ||
| 149 | (defvar info-lookup-symbol-alist | ||
| 150 | '((autoconf-mode | ||
| 151 | "A[CM]_[_A-Z0-9]+" nil | ||
| 152 | (("(autoconf)Macro Index" "AC_" | ||
| 153 | "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>") | ||
| 154 | ("(automake)Index" nil | ||
| 155 | "^[ \t]*`" "'")) | ||
| 156 | ;; Autoconf symbols are M4 macros. Thus use M4's parser. | ||
| 157 | ignore | ||
| 158 | (m4-mode)) | ||
| 159 | (bison-mode | ||
| 160 | "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+" nil | ||
| 161 | (("(bison)Index" nil | ||
| 162 | "`" "'")) | ||
| 163 | "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)" | ||
| 164 | (c-mode)) | ||
| 165 | (c-mode | ||
| 166 | "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*" nil | ||
| 167 | (("(libc)Function Index" nil | ||
| 168 | "^[ \t]+- \\(Function\\|Macro\\): .*\\<" "\\>") | ||
| 169 | ("(libc)Variable Index" nil | ||
| 170 | "^[ \t]+- \\(Variable\\|Macro\\): .*\\<" "\\>") | ||
| 171 | ("(libc)Type Index" nil | ||
| 172 | "^[ \t]+- Data Type: \\<" "\\>") | ||
| 173 | ("(termcap)Var Index" nil | ||
| 174 | "^[ \t]*`" "'")) | ||
| 175 | info-lookup-guess-c-symbol) | ||
| 176 | (emacs-lisp-mode | ||
| 177 | "[-_a-zA-Z+=*:&%$#@!^~][-_a-zA-Z0-9+=*:&%$#@!^~]*" nil | ||
| 178 | ("(elisp)Index" nil | ||
| 179 | "^[ \t]+- \\(Function\\|Macro\\|User Option\\|Variable\\): .*\\<" | ||
| 180 | "\\>")) | ||
| 181 | (m4-mode | ||
| 182 | "[_a-zA-Z][_a-zA-Z0-9]*" nil | ||
| 183 | (("(m4)Macro index")) | ||
| 184 | "[_a-zA-Z0-9]+") | ||
| 185 | (makefile-mode | ||
| 186 | "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*" nil | ||
| 187 | (("(make)Name Index" nil | ||
| 188 | "^[ \t]*`" "'")) | ||
| 189 | "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+") | ||
| 190 | (texinfo-mode | ||
| 191 | "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)" nil | ||
| 192 | (("(texinfo)Command and Variable Index" | ||
| 193 | ;; Ignore Emacs commands and prepend a `@'. | ||
| 194 | (lambda (item) | ||
| 195 | (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item) | ||
| 196 | (concat "@" (match-string 1 item)))) | ||
| 197 | "`" "'"))) | ||
| 198 | (awk-mode ;;; Added by Peter Galbraith <galbraith@mixing.qc.dfo.ca> | ||
| 199 | "[_a-zA-Z]+" | ||
| 200 | nil ; Don't ignore-case | ||
| 201 | (("(gawk)Index" ; info node | ||
| 202 | (lambda (item) ; TRANS-FUNC index-entry-->help-item | ||
| 203 | ;; In awk-mode, we want entries like: | ||
| 204 | ;; * BEGIN special pattern: BEGIN/END. | ||
| 205 | ;; * break statement: Break Statement. | ||
| 206 | ;; * FS: Field Separators. | ||
| 207 | ;; * gsub: String Functions. | ||
| 208 | ;; * system: I/O Functions. | ||
| 209 | ;; * systime: Time Functions. | ||
| 210 | ;; | ||
| 211 | ;; But not: | ||
| 212 | ;; * time of day: Time Functions. | ||
| 213 | ;; ^^^^^^^^^^^ More than one word. | ||
| 214 | ;; | ||
| 215 | ;; However, info-look's info-lookup-make-completions doesn't pass | ||
| 216 | ;; the whole line to the TRANS-FUNC, but only up to the first | ||
| 217 | ;; colon. So I can't use all the available info to decide what to | ||
| 218 | ;; keep. Therefore, I have to `set-buffer' to the *info* buffer. | ||
| 219 | ;; | ||
| 220 | ;; Also, info-look offers no way to add non-indexed entries like | ||
| 221 | ;; `cos' and other gawk Numeric Built-in Functions (or does it?) | ||
| 222 | ;; as in ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/func-doc.el | ||
| 223 | ;; and http://www.ifi.uio.no/~jensthi/word-help.el (which adds a | ||
| 224 | ;; heap of stuff for latex!) | ||
| 225 | (let ((case-fold-search nil)) | ||
| 226 | (cond | ||
| 227 | ((string-match "\\([^ ]+\\) *\\(special pattern\\|statement\\)$" | ||
| 228 | item) | ||
| 229 | (match-string 1 item)) | ||
| 230 | ((string-match "^[A-Z]+$" item) ;This will grab FS and the like. | ||
| 231 | item) | ||
| 232 | ((string-match "^[a-z]+$" item) | ||
| 233 | (save-excursion | ||
| 234 | (set-buffer "*info*") | ||
| 235 | (if (looking-at " *\\(String\\|I/O\\|Time\\) Functions") | ||
| 236 | item)))))) | ||
| 237 | "`" "'"))) ;Append PREFIX and SUFFIX to finetune | ||
| 238 | ; displayed location in Info node. | ||
| 239 | ;; Perl -- Added by Peter Galbraith <galbraith@mixing.qc.dfo.ca> | ||
| 240 | ;; Perl Version 5 Info files are available in CPAN sites, at: | ||
| 241 | ;; http://www.perl.com/CPAN/doc/manual/info/ | ||
| 242 | ;; | ||
| 243 | ;; ftp://ftp.funet.fi/pub/languages/perl/CPAN/doc/manual/texinfo/ | ||
| 244 | ;; ftp://ftp.pasteur.fr/pub/computing/unix/perl/CPAN/doc/manual/texinfo/ | ||
| 245 | ;; ftp://mango.softwords.bc.ca/pub/perl/CPAN/doc/manual/texinfo/ | ||
| 246 | ;; ftp://uiarchive.cso.uiuc.edu/pub/lang/perl/CPAN/doc/manual/texinfo/ | ||
| 247 | (perl-mode | ||
| 248 | "$?[^ \n\t{(]+" | ||
| 249 | nil ; Don't ignore-case | ||
| 250 | (("(perl5)Function Index" ; info node | ||
| 251 | (lambda (item) ; TRANS-FUNC index-entry-->help-item | ||
| 252 | (if (string-match "^\\([a-z0-9]+\\)" item) | ||
| 253 | (match-string 1 item))) | ||
| 254 | "^" nil) | ||
| 255 | ("(perl5)Variable Index" ; info node | ||
| 256 | (lambda (item) ; TRANS-FUNC index-entry-->help-item | ||
| 257 | (if (string-match "^\\([^ \n\t{(]+\\)" item) ;First word | ||
| 258 | (match-string 1 item))) | ||
| 259 | "^" nil))) | ||
| 260 | ;; LaTeX -- Added by Peter Galbraith <galbraith@mixing.qc.dfo.ca> | ||
| 261 | ;; Info file available at: | ||
| 262 | ;; ftp://ftp.dante.de:pub/tex/info/latex2e-help-texinfo/latex2e.texi | ||
| 263 | (latex-mode "[\\a-zA-Z]+" nil (("(latex)Command Index" nil "`" nil))) | ||
| 264 | (emacs-lisp-mode | ||
| 265 | "[^][ ()\n\t.\"'#]+" nil | ||
| 266 | (("(elisp)Index" | ||
| 267 | (lambda (item) | ||
| 268 | (if (string-match "[^ ]+" item) ;First word | ||
| 269 | (match-string 0 item))) | ||
| 270 | "" "") | ||
| 271 | ("(emacs)Command Index" | ||
| 272 | (lambda (item) | ||
| 273 | (if (string-match "[^ ]+" item) ;First word | ||
| 274 | (match-string 0 item))) | ||
| 275 | "" "")))) | ||
| 276 | "*Alist of help specifications for symbol names. | ||
| 277 | See the documentation of the variable `info-lookup-alist' for more details.") | ||
| 278 | |||
| 279 | (defvar info-lookup-file-alist | 233 | (defvar info-lookup-file-alist |
| 280 | '((c-mode | 234 | '((c-mode |
| 281 | "[_a-zA-Z0-9./+-]+" nil | 235 | "[_a-zA-Z0-9./+-]+" nil |
| @@ -594,42 +548,217 @@ Return nil if there is nothing appropriate." | |||
| 594 | (or (info-lookup->mode-value topic mode) | 548 | (or (info-lookup->mode-value topic mode) |
| 595 | (error "No %s completion available for `%s'" topic mode)) | 549 | (error "No %s completion available for `%s'" topic mode)) |
| 596 | (let ((modes (info-lookup->all-modes topic mode)) | 550 | (let ((modes (info-lookup->all-modes topic mode)) |
| 597 | (start (point)) | 551 | (completions (info-lookup->completions topic mode)) |
| 598 | (completion-list (info-lookup->completions topic mode)) | 552 | (completion-ignore-case (info-lookup->ignore-case topic mode)) |
| 599 | try completion) | 553 | (start (point)) try completion) |
| 600 | (while (and (not try) modes) | 554 | (while (and (not try) modes) |
| 601 | (setq mode (car modes) | 555 | (setq mode (car modes) |
| 602 | modes (cdr modes) | 556 | modes (cdr modes) |
| 603 | try (info-lookup-guess-default* topic mode)) | 557 | try (info-lookup-guess-default* topic mode)) |
| 604 | (goto-char start)) | 558 | (goto-char start)) |
| 605 | (and (not try) | 559 | (and (not try) |
| 606 | (error "Found no %s to complete" topic)) | 560 | (error "Found no %S to complete" topic)) |
| 607 | (setq completion (try-completion try completion-list)) | 561 | (setq completion (try-completion try completions)) |
| 608 | (cond ((not completion) | 562 | (cond ((not completion) |
| 609 | (message "No %s match" topic) | 563 | (ding) |
| 610 | (ding)) | 564 | (message "No match")) |
| 611 | ((stringp completion) | 565 | ((stringp completion) |
| 566 | (or (assoc completion completions) | ||
| 567 | (setq completion (completing-read | ||
| 568 | (format "Complete %S: " topic) | ||
| 569 | completions nil t completion | ||
| 570 | info-lookup-history))) | ||
| 612 | (delete-region (- start (length try)) start) | 571 | (delete-region (- start (length try)) start) |
| 613 | (insert completion) | 572 | (insert completion)) |
| 614 | (if (or (string-equal try completion) | 573 | (t |
| 615 | (and (boundp 'info-look-completion) | 574 | (message "%s is complete" (capitalize (prin1-to-string topic))))))) |
| 616 | info-look-completion | 575 | |
| 617 | (= (point) (car info-look-completion)) | 576 | |
| 618 | (equal completion (car (cdr info-look-completion))))) | 577 | ;;; Info-lookup minor mode. |
| 619 | ;; Show completion list | 578 | |
| 620 | (let ((list (all-completions completion completion-list))) | 579 | (defvar info-lookup-minor-mode nil |
| 621 | (with-output-to-temp-buffer "*Completions*" | 580 | "Non-`nil' enables Info-lookup mode.") |
| 622 | (display-completion-list list)) | 581 | (make-variable-buffer-local 'info-lookup-minor-mode) |
| 623 | (if (member completion list) | 582 | |
| 624 | (message "Complete but not unique")))) | 583 | (defvar info-lookup-minor-mode-string " Info" |
| 625 | (setq info-look-completion (list (point) completion))) | 584 | "Indicator included in the mode line when in Info-lookup mode.") |
| 626 | (t | 585 | |
| 627 | (message "%s is complete" topic))))) | 586 | (or (assq 'info-lookup-minor-mode minor-mode-alist) |
| 628 | 587 | (setq minor-mode-alist (cons '(info-lookup-minor-mode | |
| 629 | (defvar info-look-completion nil | 588 | info-lookup-minor-mode-string) |
| 630 | "info-look cache for last completion and point to display completion or not") | 589 | minor-mode-alist))) |
| 631 | (make-variable-buffer-local 'info-look-completion) | 590 | |
| 632 | 591 | (defvar info-lookup-minor-mode-map (make-sparse-keymap) | |
| 592 | "Minor mode map for Info-lookup mode.") | ||
| 593 | |||
| 594 | (or (assq 'info-lookup-minor-mode minor-mode-map-alist) | ||
| 595 | (setq minor-mode-map-alist (cons (cons 'info-lookup-minor-mode | ||
| 596 | info-lookup-minor-mode-map) | ||
| 597 | minor-mode-map-alist))) | ||
| 598 | |||
| 599 | ;;;### autoload | ||
| 600 | (defun info-lookup-minor-mode (&optional arg) | ||
| 601 | "Minor mode for looking up the documentation of a symbol or file. | ||
| 602 | Special commands: | ||
| 603 | |||
| 604 | \\{info-lookup-minor-mode-map}" | ||
| 605 | (interactive "P") | ||
| 606 | (setq info-lookup-minor-mode (if (null arg) | ||
| 607 | (not info-lookup-minor-mode) | ||
| 608 | (> (prefix-numeric-value arg) 0))) | ||
| 609 | (set-buffer-modified-p (buffer-modified-p))) | ||
| 610 | |||
| 611 | (define-key info-lookup-minor-mode-map | ||
| 612 | "\C-c\C-hf" 'info-lookup-symbol) ; Describe function. | ||
| 613 | (define-key info-lookup-minor-mode-map | ||
| 614 | "\C-c\C-hv" 'info-lookup-symbol) ; Describe variable. | ||
| 615 | (define-key info-lookup-minor-mode-map | ||
| 616 | "\C-c\C-ht" 'info-lookup-symbol) ; Describe type. | ||
| 617 | (define-key info-lookup-minor-mode-map | ||
| 618 | "\C-c\C-hp" 'info-lookup-file) ; Describe program. | ||
| 619 | (define-key info-lookup-minor-mode-map | ||
| 620 | "\C-c\C-if" 'info-complete-symbol) ; Complete function. | ||
| 621 | (define-key info-lookup-minor-mode-map | ||
| 622 | "\C-c\C-iv" 'info-complete-symbol) ; Complete variable. | ||
| 623 | (define-key info-lookup-minor-mode-map | ||
| 624 | "\C-c\C-it" 'info-complete-symbol) ; Complete type. | ||
| 625 | (define-key info-lookup-minor-mode-map | ||
| 626 | "\C-c\C-ip" 'info-complete-file) ; Complete program. | ||
| 627 | |||
| 628 | ;;;### autoload | ||
| 629 | (defun turn-on-info-lookup () | ||
| 630 | "Unconditionally turn on Info-lookup mode." | ||
| 631 | (info-lookup-minor-mode 1)) | ||
| 632 | |||
| 633 | |||
| 634 | ;;; Initialize some common modes. | ||
| 635 | |||
| 636 | (info-lookup-maybe-add-help | ||
| 637 | :mode 'c-mode :topic 'symbol | ||
| 638 | :regexp "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*" | ||
| 639 | :doc-spec '(("(libc)Function Index" nil | ||
| 640 | "^[ \t]+- \\(Function\\|Macro\\): .*\\<" "\\>") | ||
| 641 | ("(libc)Variable Index" nil | ||
| 642 | "^[ \t]+- \\(Variable\\|Macro\\): .*\\<" "\\>") | ||
| 643 | ("(libc)Type Index" nil | ||
| 644 | "^[ \t]+- Data Type: \\<" "\\>") | ||
| 645 | ("(termcap)Var Index" nil | ||
| 646 | "^[ \t]*`" "'")) | ||
| 647 | :parse-rule 'info-lookup-guess-c-symbol) | ||
| 648 | |||
| 649 | (info-lookup-maybe-add-help | ||
| 650 | :mode 'c-mode :topic 'file | ||
| 651 | :regexp "[_a-zA-Z0-9./+-]+" | ||
| 652 | :doc-spec '(("(libc)File Index"))) | ||
| 653 | |||
| 654 | (info-lookup-maybe-add-help | ||
| 655 | :mode 'bison-mode | ||
| 656 | :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+" | ||
| 657 | :doc-spec '(("(bison)Index" nil | ||
| 658 | "`" "'")) | ||
| 659 | :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)" | ||
| 660 | :other-modes '(c-mode)) | ||
| 661 | |||
| 662 | (info-lookup-maybe-add-help | ||
| 663 | :mode 'makefile-mode | ||
| 664 | :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*" | ||
| 665 | :doc-spec '(("(make)Name Index" nil | ||
| 666 | "^[ \t]*`" "'")) | ||
| 667 | :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+") | ||
| 668 | |||
| 669 | (info-lookup-maybe-add-help | ||
| 670 | :mode 'texinfo-mode | ||
| 671 | :regexp "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)" | ||
| 672 | :doc-spec '(("(texinfo)Command and Variable Index" | ||
| 673 | ;; Ignore Emacs commands and prepend a `@'. | ||
| 674 | (lambda (item) | ||
| 675 | (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item) | ||
| 676 | (concat "@" (match-string 1 item)))) | ||
| 677 | "`" "'"))) | ||
| 678 | |||
| 679 | (info-lookup-maybe-add-help | ||
| 680 | :mode 'm4-mode | ||
| 681 | :regexp "[_a-zA-Z][_a-zA-Z0-9]*" | ||
| 682 | :doc-spec '(("(m4)Macro index")) | ||
| 683 | :parse-rule "[_a-zA-Z0-9]+") | ||
| 684 | |||
| 685 | (info-lookup-maybe-add-help | ||
| 686 | :mode 'autoconf-mode | ||
| 687 | :regexp "A[CM]_[_A-Z0-9]+" | ||
| 688 | :doc-spec '(("(autoconf)Macro Index" "AC_" | ||
| 689 | "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>") | ||
| 690 | ("(automake)Index" nil | ||
| 691 | "^[ \t]*`" "'")) | ||
| 692 | ;; Autoconf symbols are M4 macros. Thus use M4's parser. | ||
| 693 | :parse-rule 'ignore | ||
| 694 | :other-modes '(m4-mode)) | ||
| 695 | |||
| 696 | (info-lookup-maybe-add-help | ||
| 697 | :mode 'awk-mode | ||
| 698 | :regexp "[_a-zA-Z]+" | ||
| 699 | :doc-spec '(("(gawk)Index" | ||
| 700 | (lambda (item) | ||
| 701 | (let ((case-fold-search nil)) | ||
| 702 | (cond | ||
| 703 | ;; `BEGIN' and `END'. | ||
| 704 | ((string-match "^\\([A-Z]+\\) special pattern\\b" item) | ||
| 705 | (match-string 1 item)) | ||
| 706 | ;; `if', `while', `do', ... | ||
| 707 | ((string-match "^\\([a-z]+\\) statement\\b" item) | ||
| 708 | (if (not (string-equal (match-string 1 item) "control")) | ||
| 709 | (match-string 1 item))) | ||
| 710 | ;; `NR', `NF', ... | ||
| 711 | ((string-match "^[A-Z]+$" item) | ||
| 712 | item) | ||
| 713 | ;; Built-in functions (matches to many entries). | ||
| 714 | ((string-match "^[a-z]+$" item) | ||
| 715 | item)))) | ||
| 716 | "`" "\\([ \t]*([^)]*)\\)?'"))) | ||
| 717 | |||
| 718 | (info-lookup-maybe-add-help | ||
| 719 | :mode 'perl-mode | ||
| 720 | :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*" | ||
| 721 | :doc-spec '(("(perl5)Function Index" | ||
| 722 | (lambda (item) | ||
| 723 | (if (string-match "^\\([a-zA-Z0-9]+\\)" item) | ||
| 724 | (match-string 1 item))) | ||
| 725 | "^" "\\b") | ||
| 726 | ("(perl5)Variable Index" | ||
| 727 | (lambda (item) | ||
| 728 | ;; Work around bad formatted array variables. | ||
| 729 | (let ((sym (cond ((or (string-match "^\\$\\(.\\|@@\\)$" item) | ||
| 730 | (string-match "^\\$\\^[A-Z]$" item)) | ||
| 731 | item) | ||
| 732 | ((string-match | ||
| 733 | "^\\([$%@]\\|@@\\)?[_a-zA-Z0-9]+" item) | ||
| 734 | (match-string 0 item)) | ||
| 735 | (t "")))) | ||
| 736 | (if (string-match "@@" sym) | ||
| 737 | (setq sym (concat (substring sym 0 (match-beginning 0)) | ||
| 738 | (substring sym (1- (match-end 0)))))) | ||
| 739 | (if (string-equal sym "") nil sym))) | ||
| 740 | "^" "\\b")) | ||
| 741 | :parse-rule "[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)") | ||
| 742 | |||
| 743 | (info-lookup-maybe-add-help | ||
| 744 | :mode 'latex-mode | ||
| 745 | :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)" | ||
| 746 | :doc-spec '(("(latex2e)Command Index" nil | ||
| 747 | "`" "\\({[^}]*}\\)?'"))) | ||
| 748 | |||
| 749 | (info-lookup-maybe-add-help | ||
| 750 | :mode 'emacs-lisp-mode | ||
| 751 | :regexp "[^()' \t\n]+" | ||
| 752 | :doc-spec '(("(emacs)Command Index") | ||
| 753 | ("(emacs)Variable Index"))) | ||
| 754 | |||
| 755 | (info-lookup-maybe-add-help | ||
| 756 | :mode 'lisp-interaction-mode | ||
| 757 | :regexp "[^()' \t\n]+" | ||
| 758 | :parse-rule 'ignore | ||
| 759 | :other-modes '(emacs-lisp-mode)) | ||
| 760 | |||
| 761 | |||
| 633 | (provide 'info-look) | 762 | (provide 'info-look) |
| 634 | 763 | ||
| 635 | ;;; info-look.el ends here | 764 | ;;; info-look.el ends here |