Commit | Line | Data |
---|---|---|
423428a8 | 1 | ;;; info-look.el --- major-mode-sensitive Info index lookup facility -*- lexical-binding: t -*- |
5a79736d RS |
2 | ;; An older version of this was known as libc.el. |
3 | ||
ab422c4d | 4 | ;; Copyright (C) 1995-1999, 2001-2013 Free Software Foundation, Inc. |
5a79736d | 5 | |
3b361901 | 6 | ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org> |
fdba4ab4 | 7 | ;; (did not show signs of life (Nov 2001) -stef) |
5a79736d RS |
8 | ;; Keywords: help languages |
9 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
5a79736d | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
5a79736d RS |
16 | |
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. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
5a79736d | 24 | |
41b1cae7 SM |
25 | ;;; Commentary: |
26 | ||
27 | ;; Really cool code to lookup info indexes. | |
b3a3e4e1 | 28 | ;; Try especially info-lookup-symbol (aka C-h S). |
41b1cae7 | 29 | |
6db17b02 GM |
30 | ;; Some additional sources of (Tex)info files for non-GNU packages: |
31 | ;; | |
32 | ;; Scheme: <URL:http://groups.csail.mit.edu/mac/ftpdir/scm/r5rs.info.tar.gz> | |
33 | ;; LaTeX: | |
34 | ;; <URL:ftp://ctan.tug.org/tex-archive/info/latex2e-help-texinfo/latex2e.texi> | |
35 | ;; (or CTAN mirrors) | |
36 | ;; Perl: <URL:ftp://ftp.cpan.org/pub/CPAN/doc/manual/texinfo/> (or CPAN mirrors) | |
37 | ||
5a79736d RS |
38 | ;;; Code: |
39 | ||
40 | (require 'info) | |
d2c2b883 RS |
41 | |
42 | (defgroup info-lookup nil | |
43 | "Major mode sensitive help agent." | |
44 | :group 'help :group 'languages) | |
5a79736d RS |
45 | |
46 | (defvar info-lookup-mode nil | |
d2c2b883 RS |
47 | "Symbol of the current buffer's help mode. |
48 | Help is provided according to the buffer's major mode if value is nil. | |
5a79736d RS |
49 | Automatically becomes buffer local when set in any fashion.") |
50 | (make-variable-buffer-local 'info-lookup-mode) | |
51 | ||
d2c2b883 RS |
52 | (defcustom info-lookup-other-window-flag t |
53 | "Non-nil means pop up the Info buffer in another window." | |
54 | :group 'info-lookup :type 'boolean) | |
5a79736d | 55 | |
8270a848 | 56 | (defcustom info-lookup-highlight-face 'match |
d2c2b883 RS |
57 | "Face for highlighting looked up help items. |
58 | Setting this variable to nil disables highlighting." | |
59 | :group 'info-lookup :type 'face) | |
5a79736d RS |
60 | |
61 | (defvar info-lookup-highlight-overlay nil | |
62 | "Overlay object used for highlighting.") | |
63 | ||
9d37318d | 64 | (defcustom info-lookup-file-name-alist |
28a2ca5d | 65 | '(("\\`ac\\(local\\|site\\|include\\)\\.m4\\'" . autoconf-mode)) |
9d37318d KH |
66 | "Alist of file names handled specially. |
67 | List elements are cons cells of the form | |
68 | ||
69 | (REGEXP . MODE) | |
70 | ||
71 | If a file name matches REGEXP, then use help mode MODE instead of the | |
72 | buffer's major mode." | |
73 | :group 'info-lookup :type '(repeat (cons (string :tag "Regexp") | |
74 | (symbol :tag "Mode")))) | |
75 | ||
5a79736d RS |
76 | (defvar info-lookup-history nil |
77 | "History of previous input lines.") | |
78 | ||
d2c2b883 RS |
79 | (defvar info-lookup-alist nil |
80 | "Alist of known help topics. | |
5a79736d RS |
81 | Cons cells are of the form |
82 | ||
d2c2b883 | 83 | (HELP-TOPIC . HELP-DATA) |
5a79736d RS |
84 | |
85 | HELP-TOPIC is the symbol of a help topic. | |
d2c2b883 | 86 | HELP-DATA is a HELP-TOPIC's public data set. |
5a79736d RS |
87 | Value is an alist with elements of the form |
88 | ||
89 | (HELP-MODE REGEXP IGNORE-CASE DOC-SPEC PARSE-RULE OTHER-MODES) | |
90 | ||
91 | HELP-MODE is a mode's symbol. | |
92 | REGEXP is a regular expression matching those help items whose | |
93 | documentation can be looked up via DOC-SPEC. | |
94 | IGNORE-CASE is non-nil if help items are case insensitive. | |
95 | DOC-SPEC is a list of documentation specifications of the form | |
96 | ||
97 | (INFO-NODE TRANS-FUNC PREFIX SUFFIX) | |
98 | ||
99 | INFO-NODE is the name (including file name part) of an Info index. | |
100 | TRANS-FUNC is a function translating index entries into help items; | |
101 | nil means add only those index entries matching REGEXP, a string | |
102 | means prepend string to the first word of all index entries. | |
103 | PREFIX and SUFFIX are parts of a regular expression. If one of | |
104 | them is non-nil then search the help item's Info node for the | |
105 | first occurrence of the regular expression `PREFIX ITEM SUFFIX'. | |
106 | ITEM will be highlighted with `info-lookup-highlight-face' if this | |
107 | variable is not nil. | |
108 | PARSE-RULE is either the symbol name of a function or a regular | |
109 | expression for guessing the default help item at point. Fuzzy | |
110 | regular expressions like \"[_a-zA-Z0-9]+\" do a better job if | |
111 | there are no clear delimiters; do not try to write too complex | |
112 | expressions. PARSE-RULE defaults to REGEXP. | |
113 | OTHER-MODES is a list of cross references to other help modes.") | |
114 | ||
115 | (defsubst info-lookup->topic-value (topic) | |
d2c2b883 | 116 | (cdr (assoc topic info-lookup-alist))) |
5a79736d RS |
117 | |
118 | (defsubst info-lookup->mode-value (topic mode) | |
119 | (assoc mode (info-lookup->topic-value topic))) | |
120 | ||
121 | (defsubst info-lookup->regexp (topic mode) | |
122 | (nth 1 (info-lookup->mode-value topic mode))) | |
123 | ||
124 | (defsubst info-lookup->ignore-case (topic mode) | |
125 | (nth 2 (info-lookup->mode-value topic mode))) | |
126 | ||
127 | (defsubst info-lookup->doc-spec (topic mode) | |
128 | (nth 3 (info-lookup->mode-value topic mode))) | |
129 | ||
130 | (defsubst info-lookup->parse-rule (topic mode) | |
131 | (nth 4 (info-lookup->mode-value topic mode))) | |
132 | ||
133 | (defsubst info-lookup->other-modes (topic mode) | |
134 | (nth 5 (info-lookup->mode-value topic mode))) | |
135 | ||
d2c2b883 RS |
136 | (defun info-lookup-add-help (&rest arg) |
137 | "Add or update a help specification. | |
48e96771 | 138 | Function arguments are specified as keyword/argument pairs: |
d2c2b883 | 139 | |
48e96771 | 140 | \(KEYWORD . ARGUMENT) |
d2c2b883 RS |
141 | |
142 | KEYWORD is either `:topic', `:mode', `:regexp', `:ignore-case', | |
143 | `:doc-spec', `:parse-rule', or `:other-modes'. | |
144 | ARGUMENT has a value as explained in the documentation of the | |
145 | variable `info-lookup-alist'. | |
146 | ||
147 | If no topic or mode option has been specified, then the help topic defaults | |
148 | to `symbol', and the help mode defaults to the current major mode." | |
149 | (apply 'info-lookup-add-help* nil arg)) | |
150 | ||
151 | (defun info-lookup-maybe-add-help (&rest arg) | |
4837b516 | 152 | "Add a help specification if none is defined. |
d2c2b883 RS |
153 | See the documentation of the function `info-lookup-add-help' |
154 | for more details." | |
155 | (apply 'info-lookup-add-help* t arg)) | |
156 | ||
157 | (defun info-lookup-add-help* (maybe &rest arg) | |
158 | (let (topic mode regexp ignore-case doc-spec | |
159 | parse-rule other-modes keyword value) | |
160 | (setq topic 'symbol | |
161 | mode major-mode | |
162 | regexp "\\w+") | |
163 | (while arg | |
164 | (setq keyword (car arg)) | |
165 | (or (symbolp keyword) | |
166 | (error "Junk in argument list \"%S\"" arg)) | |
167 | (setq arg (cdr arg)) | |
168 | (and (null arg) | |
169 | (error "Keyword \"%S\" is missing an argument" keyword)) | |
170 | (setq value (car arg) | |
171 | arg (cdr arg)) | |
172 | (cond ((eq keyword :topic) | |
173 | (setq topic value)) | |
174 | ((eq keyword :mode) | |
175 | (setq mode value)) | |
176 | ((eq keyword :regexp) | |
177 | (setq regexp value)) | |
178 | ((eq keyword :ignore-case) | |
179 | (setq ignore-case value)) | |
180 | ((eq keyword :doc-spec) | |
181 | (setq doc-spec value)) | |
182 | ((eq keyword :parse-rule) | |
183 | (setq parse-rule value)) | |
184 | ((eq keyword :other-modes) | |
185 | (setq other-modes value)) | |
186 | (t | |
187 | (error "Unknown keyword \"%S\"" keyword)))) | |
188 | (or (and maybe (info-lookup->mode-value topic mode)) | |
189 | (let* ((data (list regexp ignore-case doc-spec parse-rule other-modes)) | |
190 | (topic-cell (or (assoc topic info-lookup-alist) | |
191 | (car (setq info-lookup-alist | |
192 | (cons (cons topic nil) | |
193 | info-lookup-alist))))) | |
194 | (mode-cell (assoc mode topic-cell))) | |
195 | (if (null mode-cell) | |
196 | (setcdr topic-cell (cons (cons mode data) (cdr topic-cell))) | |
197 | (setcdr mode-cell data)))) | |
198 | nil)) | |
199 | ||
5a79736d RS |
200 | (defvar info-lookup-cache nil |
201 | "Cache storing data maintained automatically by the program. | |
202 | Value is an alist with cons cell of the form | |
203 | ||
204 | (HELP-TOPIC . ((HELP-MODE INITIALIZED COMPLETIONS REFER-MODES) ...)) | |
205 | ||
206 | HELP-TOPIC is the symbol of a help topic. | |
207 | HELP-MODE is a mode's symbol. | |
208 | INITIALIZED is nil if HELP-MODE is uninitialized, t if | |
209 | HELP-MODE is initialized, and `0' means HELP-MODE is | |
210 | initialized but void. | |
211 | COMPLETIONS is an alist of documented help items. | |
212 | REFER-MODES is a list of other help modes to use.") | |
213 | ||
214 | (defsubst info-lookup->cache (topic) | |
215 | (or (assoc topic info-lookup-cache) | |
216 | (car (setq info-lookup-cache | |
217 | (cons (cons topic nil) | |
218 | info-lookup-cache))))) | |
219 | ||
0c10ee28 | 220 | (defun info-lookup->topic-cache (topic) |
5a79736d RS |
221 | (cdr (info-lookup->cache topic))) |
222 | ||
0c10ee28 | 223 | (defun info-lookup->mode-cache (topic mode) |
5a79736d RS |
224 | (assoc mode (info-lookup->topic-cache topic))) |
225 | ||
0c10ee28 | 226 | (defun info-lookup->initialized (topic mode) |
5a79736d RS |
227 | (nth 1 (info-lookup->mode-cache topic mode))) |
228 | ||
0c10ee28 | 229 | (defun info-lookup->completions (topic mode) |
5a79736d RS |
230 | (or (info-lookup->initialized topic mode) |
231 | (info-lookup-setup-mode topic mode)) | |
232 | (nth 2 (info-lookup->mode-cache topic mode))) | |
233 | ||
0c10ee28 | 234 | (defun info-lookup->refer-modes (topic mode) |
5a79736d RS |
235 | (or (info-lookup->initialized topic mode) |
236 | (info-lookup-setup-mode topic mode)) | |
237 | (nth 3 (info-lookup->mode-cache topic mode))) | |
238 | ||
0c10ee28 | 239 | (defun info-lookup->all-modes (topic mode) |
5a79736d RS |
240 | (cons mode (info-lookup->refer-modes topic mode))) |
241 | ||
0c10ee28 RS |
242 | (defun info-lookup-quick-all-modes (topic mode) |
243 | (cons mode (info-lookup->other-modes topic mode))) | |
244 | ||
5a79736d RS |
245 | ;;;###autoload |
246 | (defun info-lookup-reset () | |
247 | "Throw away all cached data. | |
248 | This command is useful if the user wants to start at the beginning without | |
249 | quitting Emacs, for example, after some Info documents were updated on the | |
250 | system." | |
251 | (interactive) | |
252 | (setq info-lookup-cache nil)) | |
253 | ||
99400b3e | 254 | ;;;###autoload (put 'info-lookup-symbol 'info-file "emacs") |
5a79736d RS |
255 | ;;;###autoload |
256 | (defun info-lookup-symbol (symbol &optional mode) | |
3481a5c0 | 257 | "Display the definition of SYMBOL, as found in the relevant manual. |
ec4ef174 EZ |
258 | When this command is called interactively, it reads SYMBOL from the |
259 | minibuffer. In the minibuffer, use M-n to yank the default argument | |
260 | value into the minibuffer so you can edit it. The default symbol is the | |
261 | one found at point. | |
b108eac2 KH |
262 | |
263 | With prefix arg a query for the symbol help mode is offered." | |
5a79736d | 264 | (interactive |
b108eac2 | 265 | (info-lookup-interactive-arguments 'symbol current-prefix-arg)) |
5a79736d RS |
266 | (info-lookup 'symbol symbol mode)) |
267 | ||
99400b3e | 268 | ;;;###autoload (put 'info-lookup-file 'info-file "emacs") |
5a79736d RS |
269 | ;;;###autoload |
270 | (defun info-lookup-file (file &optional mode) | |
271 | "Display the documentation of a file. | |
3481a5c0 KH |
272 | When this command is called interactively, it reads FILE from the minibuffer. |
273 | In the minibuffer, use M-n to yank the default file name | |
274 | into the minibuffer so you can edit it. | |
b108eac2 KH |
275 | The default file name is the one found at point. |
276 | ||
277 | With prefix arg a query for the file help mode is offered." | |
5a79736d | 278 | (interactive |
b108eac2 | 279 | (info-lookup-interactive-arguments 'file current-prefix-arg)) |
5a79736d RS |
280 | (info-lookup 'file file mode)) |
281 | ||
b108eac2 KH |
282 | (defun info-lookup-interactive-arguments (topic &optional query) |
283 | "Read and return argument value (and help mode) for help topic TOPIC. | |
284 | If optional argument QUERY is non-nil, query for the help mode." | |
285 | (let* ((mode (cond (query | |
286 | (info-lookup-change-mode topic)) | |
287 | ((info-lookup->mode-value topic (info-lookup-select-mode)) | |
288 | info-lookup-mode) | |
289 | ((info-lookup-change-mode topic)))) | |
5a79736d RS |
290 | (completions (info-lookup->completions topic mode)) |
291 | (default (info-lookup-guess-default topic mode)) | |
5a79736d RS |
292 | (completion-ignore-case (info-lookup->ignore-case topic mode)) |
293 | (enable-recursive-minibuffers t) | |
294 | (value (completing-read | |
3481a5c0 | 295 | (if default |
5a79736d RS |
296 | (format "Describe %s (default %s): " topic default) |
297 | (format "Describe %s: " topic)) | |
3481a5c0 | 298 | completions nil nil nil 'info-lookup-history default))) |
5a79736d RS |
299 | (list (if (equal value "") default value) mode))) |
300 | ||
9d37318d KH |
301 | (defun info-lookup-select-mode () |
302 | (when (and (not info-lookup-mode) (buffer-file-name)) | |
303 | (let ((file-name (file-name-nondirectory (buffer-file-name))) | |
304 | (file-name-alist info-lookup-file-name-alist)) | |
305 | (while (and (not info-lookup-mode) file-name-alist) | |
306 | (when (string-match (caar file-name-alist) file-name) | |
307 | (setq info-lookup-mode (cdar file-name-alist))) | |
308 | (setq file-name-alist (cdr file-name-alist))))) | |
a9bc03e2 KR |
309 | |
310 | ;; If major-mode has no setups in info-lookup-alist, under any topic, then | |
311 | ;; search up through derived-mode-parent to find a parent mode which does | |
312 | ;; have some setups. This means that a `define-derived-mode' with no | |
313 | ;; setups of its own will select its parent mode for lookups, if one of | |
314 | ;; its parents has some setups. Good for example on `makefile-gmake-mode' | |
315 | ;; and similar derivatives of `makefile-mode'. | |
316 | ;; | |
317 | (let ((mode major-mode)) ;; Look for `mode' with some setups. | |
318 | (while (and mode (not info-lookup-mode)) | |
319 | (dolist (topic-cell info-lookup-alist) ;; Usually only two topics here. | |
320 | (if (info-lookup->mode-value (car topic-cell) mode) | |
321 | (setq info-lookup-mode mode))) | |
322 | (setq mode (get mode 'derived-mode-parent)))) | |
323 | ||
9d37318d KH |
324 | (or info-lookup-mode (setq info-lookup-mode major-mode))) |
325 | ||
5a79736d RS |
326 | (defun info-lookup-change-mode (topic) |
327 | (let* ((completions (mapcar (lambda (arg) | |
328 | (cons (symbol-name (car arg)) (car arg))) | |
329 | (info-lookup->topic-value topic))) | |
330 | (mode (completing-read | |
331 | (format "Use %s help mode: " topic) | |
332 | completions nil t nil 'info-lookup-history))) | |
333 | (or (setq mode (cdr (assoc mode completions))) | |
334 | (error "No %s help available" topic)) | |
335 | (or (info-lookup->mode-value topic mode) | |
336 | (error "No %s help available for `%s'" topic mode)) | |
337 | (setq info-lookup-mode mode))) | |
338 | ||
339 | (defun info-lookup (topic item mode) | |
340 | "Display the documentation of a help item." | |
9d37318d | 341 | (or mode (setq mode (info-lookup-select-mode))) |
5a79736d RS |
342 | (or (info-lookup->mode-value topic mode) |
343 | (error "No %s help available for `%s'" topic mode)) | |
7c3da01b RS |
344 | (let* ((completions (info-lookup->completions topic mode)) |
345 | (ignore-case (info-lookup->ignore-case topic mode)) | |
346 | (entry (or (assoc (if ignore-case (downcase item) item) completions) | |
0445150c | 347 | (assoc-string item completions t) |
7c3da01b RS |
348 | (error "Not documented as a %s: %s" topic (or item "")))) |
349 | (modes (info-lookup->all-modes topic mode)) | |
350 | (window (selected-window)) | |
27b1b62b MR |
351 | (new-Info-history |
352 | ;; Avoid clobbering Info-history with nodes searched during | |
353 | ;; lookup. If lookup succeeds set `Info-history' to | |
354 | ;; `new-Info-history'. | |
355 | (when (get-buffer "*info*") | |
356 | (with-current-buffer "*info*" | |
357 | (cons (list Info-current-file Info-current-node (point)) | |
358 | Info-history)))) | |
7c3da01b | 359 | found doc-spec node prefix suffix doc-found) |
2faede35 MR |
360 | (unless (eq major-mode 'Info-mode) |
361 | (if (not info-lookup-other-window-flag) | |
362 | (info) | |
363 | (save-window-excursion (info)) | |
364 | (let* ((info-window (get-buffer-window "*info*" t)) | |
365 | (info-frame (and info-window (window-frame info-window)))) | |
366 | (if (and info-frame | |
367 | (not (eq info-frame (selected-frame))) | |
368 | (display-multi-frame-p) | |
369 | (memq info-frame (frames-on-display-list))) | |
370 | ;; *info* is visible in another frame on same display. | |
371 | ;; Raise that frame and select the window. | |
372 | (progn | |
373 | (select-window info-window) | |
374 | (raise-frame info-frame)) | |
375 | ;; In any other case, switch to *info* in another window. | |
376 | (switch-to-buffer-other-window "*info*"))))) | |
5a79736d RS |
377 | (while (and (not found) modes) |
378 | (setq doc-spec (info-lookup->doc-spec topic (car modes))) | |
379 | (while (and (not found) doc-spec) | |
380 | (setq node (nth 0 (car doc-spec)) | |
381 | prefix (nth 2 (car doc-spec)) | |
382 | suffix (nth 3 (car doc-spec))) | |
423428a8 | 383 | (when (condition-case nil |
e35ccb9e | 384 | (progn |
e8d2103a EZ |
385 | ;; Don't need Index menu fontifications here, and |
386 | ;; they slow down the lookup. | |
27b1b62b MR |
387 | (let (Info-fontify-maximum-menu-size |
388 | Info-history-list) | |
e8d2103a EZ |
389 | (Info-goto-node node) |
390 | (setq doc-found t))) | |
e35ccb9e | 391 | (error |
1d010333 RS |
392 | (message "Cannot access Info node %s" node) |
393 | (sit-for 1) | |
394 | nil)) | |
395 | (condition-case nil | |
396 | (progn | |
7c3da01b RS |
397 | ;; Don't use Info-menu, it forces case-fold-search to t |
398 | (let ((case-fold-search nil)) | |
399 | (re-search-forward | |
400 | (concat "^\\* " (regexp-quote (or (cdr entry) (car entry))) | |
401 | ":"))) | |
402 | (Info-follow-nearest-node) | |
1d010333 RS |
403 | (setq found t) |
404 | (if (or prefix suffix) | |
405 | (let ((case-fold-search | |
406 | (info-lookup->ignore-case topic (car modes))) | |
407 | (buffer-read-only nil)) | |
408 | (goto-char (point-min)) | |
409 | (re-search-forward | |
7c3da01b | 410 | (concat prefix (regexp-quote (car entry)) suffix)) |
1d010333 | 411 | (goto-char (match-beginning 0)) |
141d2f67 | 412 | (and (display-color-p) info-lookup-highlight-face |
1d010333 | 413 | ;; Search again for ITEM so that the first |
a5a08b1f | 414 | ;; occurrence of ITEM will be highlighted. |
7c3da01b | 415 | (re-search-forward (regexp-quote (car entry))) |
1d010333 RS |
416 | (let ((start (match-beginning 0)) |
417 | (end (match-end 0))) | |
418 | (if (overlayp info-lookup-highlight-overlay) | |
419 | (move-overlay info-lookup-highlight-overlay | |
420 | start end (current-buffer)) | |
421 | (setq info-lookup-highlight-overlay | |
422 | (make-overlay start end)))) | |
423 | (overlay-put info-lookup-highlight-overlay | |
424 | 'face info-lookup-highlight-face))))) | |
425 | (error nil))) | |
5a79736d RS |
426 | (setq doc-spec (cdr doc-spec))) |
427 | (setq modes (cdr modes))) | |
7c3da01b RS |
428 | ;; Alert the user if case was munged, and do this after bringing up the |
429 | ;; info buffer since that can print messages | |
430 | (unless (or ignore-case | |
431 | (string-equal item (car entry))) | |
021c54a3 | 432 | (message "Found in different case: %s" (car entry))) |
27b1b62b MR |
433 | (when found |
434 | (setq Info-history new-Info-history)) | |
1d010333 RS |
435 | (or doc-found |
436 | (error "Info documentation for lookup was not found")) | |
5a79736d RS |
437 | ;; Don't leave the Info buffer if the help item couldn't be looked up. |
438 | (if (and info-lookup-other-window-flag found) | |
439 | (select-window window)))) | |
440 | ||
441 | (defun info-lookup-setup-mode (topic mode) | |
442 | "Initialize the internal data structure." | |
443 | (or (info-lookup->initialized topic mode) | |
27b1b62b MR |
444 | (let ((initialized 0) |
445 | cell data completions refer-modes Info-history-list) | |
5a79736d RS |
446 | (if (not (info-lookup->mode-value topic mode)) |
447 | (message "No %s help available for `%s'" topic mode) | |
448 | ;; Recursively setup cross references. | |
449 | ;; But refer only to non-void modes. | |
538996c7 SM |
450 | (dolist (arg (info-lookup->other-modes topic mode)) |
451 | (or (info-lookup->initialized topic arg) | |
452 | (info-lookup-setup-mode topic arg)) | |
453 | (and (eq (info-lookup->initialized topic arg) t) | |
454 | (setq refer-modes (cons arg refer-modes)))) | |
5a79736d RS |
455 | (setq refer-modes (nreverse refer-modes)) |
456 | ;; Build the full completion alist. | |
457 | (setq completions | |
e12fcc41 KH |
458 | (nconc (condition-case nil |
459 | (info-lookup-make-completions topic mode) | |
460 | (error nil)) | |
5a79736d RS |
461 | (apply 'append |
462 | (mapcar (lambda (arg) | |
463 | (info-lookup->completions topic arg)) | |
464 | refer-modes)))) | |
465 | (setq initialized t)) | |
466 | ;; Update `info-lookup-cache'. | |
467 | (setq cell (info-lookup->mode-cache topic mode) | |
468 | data (list initialized completions refer-modes)) | |
469 | (if (not cell) | |
470 | (setcdr (info-lookup->cache topic) | |
471 | (cons (cons mode data) (info-lookup->topic-cache topic))) | |
472 | (setcdr cell data)) | |
473 | initialized))) | |
474 | ||
475 | (defun info-lookup-make-completions (topic mode) | |
476 | "Create a unique alist from all index entries." | |
1eff0ba1 RS |
477 | (let ((doc-spec (info-lookup->doc-spec topic mode)) |
478 | (regexp (concat "^\\(" (info-lookup->regexp topic mode) | |
479 | "\\)\\([ \t].*\\)?$")) | |
27b1b62b | 480 | Info-history-list Info-fontify-maximum-menu-size |
1d010333 | 481 | node trans entry item prefix result doc-found |
1eff0ba1 RS |
482 | (buffer (get-buffer-create " temp-info-look"))) |
483 | (with-current-buffer buffer | |
484 | (Info-mode)) | |
485 | (while doc-spec | |
486 | (setq node (nth 0 (car doc-spec)) | |
487 | trans (cond ((eq (nth 1 (car doc-spec)) nil) | |
488 | (lambda (arg) | |
489 | (if (string-match regexp arg) | |
490 | (match-string 1 arg)))) | |
491 | ((stringp (nth 1 (car doc-spec))) | |
492 | (setq prefix (nth 1 (car doc-spec))) | |
493 | (lambda (arg) | |
494 | (if (string-match "^\\([^: \t\n]+\\)" arg) | |
495 | (concat prefix (match-string 1 arg))))) | |
496 | (t (nth 1 (car doc-spec))))) | |
1d010333 RS |
497 | (with-current-buffer buffer |
498 | (message "Processing Info node `%s'..." node) | |
423428a8 | 499 | (when (condition-case nil |
e35ccb9e | 500 | (progn |
1d010333 RS |
501 | (Info-goto-node node) |
502 | (setq doc-found t)) | |
e35ccb9e | 503 | (error |
1d010333 RS |
504 | (message "Cannot access Info node `%s'" node) |
505 | (sit-for 1) | |
506 | nil)) | |
507 | (condition-case nil | |
508 | (progn | |
509 | (goto-char (point-min)) | |
510 | (and (search-forward "\n* Menu:" nil t) | |
bdb0f2d5 | 511 | (while (re-search-forward "\n\\* \\(.*\\): " nil t) |
1d010333 RS |
512 | (setq entry (match-string 1) |
513 | item (funcall trans entry)) | |
6480a693 DL |
514 | ;; `trans' can return nil if the regexp doesn't match. |
515 | (when (and item | |
516 | ;; Sometimes there's more than one Menu: | |
e35ccb9e | 517 | (not (string= entry "Menu"))) |
6480a693 DL |
518 | (and (info-lookup->ignore-case topic mode) |
519 | (setq item (downcase item))) | |
520 | (and (string-equal entry item) | |
521 | (setq entry nil)) | |
522 | (and (or (assoc item result) | |
523 | (setq result (cons (cons item entry) | |
524 | result)))))))) | |
1d010333 | 525 | (error nil)))) |
1eff0ba1 RS |
526 | (message "Processing Info node `%s'...done" node) |
527 | (setq doc-spec (cdr doc-spec))) | |
1d010333 RS |
528 | (or doc-found |
529 | (error "Info documentation for lookup was not found")) | |
1eff0ba1 | 530 | result)) |
5a79736d RS |
531 | |
532 | (defun info-lookup-guess-default (topic mode) | |
ce288cb6 KH |
533 | "Return a guess for a symbol to look up, based on text around point. |
534 | Try all related modes applicable to TOPIC and MODE. | |
535 | Return nil if there is nothing appropriate in the buffer near point." | |
5a79736d | 536 | (let ((modes (info-lookup->all-modes topic mode)) |
ce288cb6 | 537 | guess) |
5a79736d RS |
538 | (while (and (not guess) modes) |
539 | (setq guess (info-lookup-guess-default* topic (car modes)) | |
ce288cb6 | 540 | modes (cdr modes))) |
5a79736d | 541 | ;; Collapse whitespace characters. |
ce288cb6 KH |
542 | (when guess |
543 | (let ((pos 0)) | |
544 | (while (string-match "[ \t\n]+" guess pos) | |
545 | (setq pos (1+ (match-beginning 0))) | |
546 | (setq guess (replace-match " " t t guess))))) | |
547 | guess)) | |
5a79736d RS |
548 | |
549 | (defun info-lookup-guess-default* (topic mode) | |
550 | (let ((case-fold-search (info-lookup->ignore-case topic mode)) | |
551 | (rule (or (info-lookup->parse-rule topic mode) | |
552 | (info-lookup->regexp topic mode))) | |
553 | (start (point)) end regexp subexp result) | |
ce288cb6 KH |
554 | (save-excursion |
555 | (if (symbolp rule) | |
556 | (setq result (funcall rule)) | |
557 | (if (consp rule) | |
558 | (setq regexp (car rule) | |
559 | subexp (cdr rule)) | |
560 | (setq regexp rule | |
561 | subexp 0)) | |
e35ccb9e DL |
562 | ;; If at start of symbol, don't go back to end of previous one. |
563 | (if (save-match-data | |
564 | (looking-at "[ \t\n]")) | |
565 | (skip-chars-backward " \t\n")) | |
566 | (setq end (point)) | |
ce288cb6 KH |
567 | (while (and (re-search-backward regexp nil t) |
568 | (looking-at regexp) | |
569 | (>= (match-end 0) end)) | |
570 | (setq result (match-string subexp))) | |
571 | (if (not result) | |
572 | (progn | |
573 | (goto-char start) | |
574 | (skip-chars-forward " \t\n") | |
575 | (and (looking-at regexp) | |
576 | (setq result (match-string subexp))))))) | |
5a79736d RS |
577 | result)) |
578 | ||
579 | (defun info-lookup-guess-c-symbol () | |
580 | "Get the C symbol at point." | |
581 | (condition-case nil | |
582 | (progn | |
ce288cb6 | 583 | (skip-syntax-backward "w_") |
5a79736d RS |
584 | (let ((start (point)) prefix name) |
585 | ;; Test for a leading `struct', `union', or `enum' keyword | |
586 | ;; but ignore names like `foo_struct'. | |
587 | (setq prefix (and (< (skip-chars-backward " \t\n") 0) | |
588 | (< (skip-chars-backward "_a-zA-Z0-9") 0) | |
589 | (looking-at "\\(struct\\|union\\|enum\\)\\s ") | |
590 | (concat (match-string 1) " "))) | |
591 | (goto-char start) | |
592 | (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*") | |
593 | (setq name (match-string 0))) | |
594 | ;; Caveat! Look forward if point is at `struct' etc. | |
595 | (and (not prefix) | |
596 | (or (string-equal name "struct") | |
597 | (string-equal name "union") | |
598 | (string-equal name "enum")) | |
599 | (looking-at "[a-z]+\\s +\\([_a-zA-Z][_a-zA-Z0-9]*\\)") | |
600 | (setq prefix (concat name " ") | |
601 | name (match-string 1))) | |
602 | (and (or prefix name) | |
603 | (concat prefix name)))) | |
604 | (error nil))) | |
605 | ||
ec4ef174 EZ |
606 | (defun info-lookup-guess-custom-symbol () |
607 | "Get symbol at point in custom buffers." | |
608 | (condition-case nil | |
609 | (save-excursion | |
610 | (let ((case-fold-search t) | |
611 | (ignored-chars "][()`',:.\" \t\n") | |
612 | (significant-chars "^][()`',:.\" \t\n") | |
613 | beg end) | |
614 | (cond | |
615 | ((and (memq (get-char-property (point) 'face) | |
616 | '(custom-variable-tag custom-variable-tag-face)) | |
617 | (setq beg (previous-single-char-property-change | |
618 | (point) 'face nil (line-beginning-position))) | |
619 | (setq end (next-single-char-property-change | |
620 | (point) 'face nil (line-end-position))) | |
621 | (> end beg)) | |
622 | (subst-char-in-string | |
4789a3cb | 623 | ?\s ?\- (buffer-substring-no-properties beg end))) |
ec4ef174 EZ |
624 | ((or (and (looking-at (concat "[" significant-chars "]")) |
625 | (save-excursion | |
626 | (skip-chars-backward significant-chars) | |
627 | (setq beg (point))) | |
628 | (skip-chars-forward significant-chars) | |
629 | (setq end (point)) | |
630 | (> end beg)) | |
631 | (and (looking-at "[ \t\n]") | |
632 | (looking-back (concat "[" significant-chars "]")) | |
633 | (setq end (point)) | |
634 | (skip-chars-backward significant-chars) | |
635 | (setq beg (point)) | |
636 | (> end beg)) | |
637 | (and (skip-chars-forward ignored-chars) | |
638 | (setq beg (point)) | |
639 | (skip-chars-forward significant-chars) | |
640 | (setq end (point)) | |
641 | (> end beg))) | |
642 | (buffer-substring-no-properties beg end))))) | |
643 | (error nil))) | |
644 | ||
5a79736d RS |
645 | ;;;###autoload |
646 | (defun info-complete-symbol (&optional mode) | |
647 | "Perform completion on symbol preceding point." | |
82fb111c RS |
648 | (interactive) |
649 | (info-complete 'symbol | |
650 | (or mode | |
651 | (if (info-lookup->mode-value | |
9d37318d KH |
652 | 'symbol (info-lookup-select-mode)) |
653 | info-lookup-mode | |
82fb111c | 654 | (info-lookup-change-mode 'symbol))))) |
5a79736d RS |
655 | |
656 | ;;;###autoload | |
657 | (defun info-complete-file (&optional mode) | |
658 | "Perform completion on file preceding point." | |
a1fee1bc KH |
659 | (interactive) |
660 | (info-complete 'file | |
661 | (or mode | |
662 | (if (info-lookup->mode-value | |
9d37318d KH |
663 | 'file (info-lookup-select-mode)) |
664 | info-lookup-mode | |
a1fee1bc | 665 | (info-lookup-change-mode 'file))))) |
5a79736d | 666 | |
423428a8 SM |
667 | (defun info-lookup-completions-at-point (topic mode) |
668 | "Try to complete a help item." | |
669 | (or mode (setq mode (info-lookup-select-mode))) | |
670 | (when (info-lookup->mode-value topic mode) | |
671 | (let ((modes (info-lookup-quick-all-modes topic mode)) | |
672 | (start (point)) | |
673 | try) | |
674 | (while (and (not try) modes) | |
675 | (setq mode (car modes) | |
676 | modes (cdr modes) | |
677 | try (info-lookup-guess-default* topic mode)) | |
678 | (goto-char start)) | |
679 | (when try | |
680 | (let ((completions (info-lookup->completions topic mode))) | |
681 | (when completions | |
682 | (when (info-lookup->ignore-case topic mode) | |
683 | (setq completions | |
684 | (lambda (string pred action) | |
685 | (let ((completion-ignore-case t)) | |
686 | (complete-with-action | |
687 | action completions string pred))))) | |
688 | (save-excursion | |
689 | ;; Find the original symbol and zap it. | |
690 | (end-of-line) | |
691 | (while (and (search-backward try nil t) | |
692 | (< start (point)))) | |
0ff8e1ba SM |
693 | (list (match-beginning 0) (match-end 0) completions |
694 | :exclusive 'no)))))))) | |
423428a8 | 695 | |
5a79736d RS |
696 | (defun info-complete (topic mode) |
697 | "Try to complete a help item." | |
698 | (barf-if-buffer-read-only) | |
423428a8 SM |
699 | (let ((data (info-lookup-completions-at-point topic mode))) |
700 | (if (null data) | |
701 | (error "No %s completion available for `%s' at point" topic mode) | |
0ff8e1ba | 702 | (completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))) |
d2c2b883 RS |
703 | |
704 | \f | |
d2c2b883 RS |
705 | ;;; Initialize some common modes. |
706 | ||
707 | (info-lookup-maybe-add-help | |
708 | :mode 'c-mode :topic 'symbol | |
709 | :regexp "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*" | |
710 | :doc-spec '(("(libc)Function Index" nil | |
947faf4f | 711 | "^[ \t]+-+ \\(Function\\|Macro\\): .*\\<" "\\>") |
3b90e932 EZ |
712 | ;; prefix/suffix has to match things like |
713 | ;; " -- Macro: int F_DUPFD" | |
714 | ;; " -- Variable: char * tzname [2]" | |
715 | ;; "`DBL_MAX'" (texinfo @table) | |
716 | ;; suffix "\\>" is not used because that sends DBL_MAX to | |
717 | ;; DBL_MAX_EXP ("_" is a non-word char) | |
d2c2b883 | 718 | ("(libc)Variable Index" nil |
3b90e932 EZ |
719 | "^\\([ \t]+-+ \\(Variable\\|Macro\\): .*\\<\\|`\\)" |
720 | "\\( \\|'?$\\)") | |
d2c2b883 | 721 | ("(libc)Type Index" nil |
947faf4f | 722 | "^[ \t]+-+ Data Type: \\<" "\\>") |
d2c2b883 RS |
723 | ("(termcap)Var Index" nil |
724 | "^[ \t]*`" "'")) | |
725 | :parse-rule 'info-lookup-guess-c-symbol) | |
726 | ||
727 | (info-lookup-maybe-add-help | |
728 | :mode 'c-mode :topic 'file | |
729 | :regexp "[_a-zA-Z0-9./+-]+" | |
730 | :doc-spec '(("(libc)File Index"))) | |
731 | ||
732 | (info-lookup-maybe-add-help | |
733 | :mode 'bison-mode | |
734 | :regexp "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+" | |
735 | :doc-spec '(("(bison)Index" nil | |
736 | "`" "'")) | |
737 | :parse-rule "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)" | |
738 | :other-modes '(c-mode)) | |
739 | ||
740 | (info-lookup-maybe-add-help | |
741 | :mode 'makefile-mode | |
742 | :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*" | |
743 | :doc-spec '(("(make)Name Index" nil | |
744 | "^[ \t]*`" "'")) | |
3bfacb2f KR |
745 | :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+") |
746 | ||
747 | (info-lookup-maybe-add-help | |
748 | :topic 'symbol | |
749 | :mode 'makefile-automake-mode | |
750 | ;; similar regexp/parse-rule as makefile-mode, but also the following | |
751 | ;; (which have index entries), | |
752 | ;; "##" special automake comment | |
753 | ;; "+=" append operator, separate from the GNU make one | |
754 | :regexp "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*\\|##\\|\\+=" | |
755 | :parse-rule "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+\\|##\\|\\+=" | |
756 | :doc-spec '( | |
757 | ;; "(automake)Macro Index" is autoconf macros used in | |
c4444d16 | 758 | ;; configure.ac, not Makefile.am, so don't have that here. |
3bfacb2f KR |
759 | ("(automake)Variable Index" nil "^[ \t]*`" "'") |
760 | ;; In automake 1.4 macros and variables were a combined node. | |
761 | ("(automake)Macro and Variable Index" nil "^[ \t]*`" "'") | |
762 | ;; Directives like "if" are in the "General Index". | |
763 | ;; Prefix "`" since the text for say `+=' isn't always an | |
764 | ;; @item etc and so not always at the start of a line. | |
765 | ("(automake)General Index" nil "`" "'") | |
766 | ;; In automake 1.3 there was just a single "Index" node. | |
767 | ("(automake)Index" nil "`" "'")) | |
768 | :other-modes '(makefile-mode)) | |
d2c2b883 RS |
769 | |
770 | (info-lookup-maybe-add-help | |
771 | :mode 'texinfo-mode | |
772 | :regexp "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)" | |
773 | :doc-spec '(("(texinfo)Command and Variable Index" | |
774 | ;; Ignore Emacs commands and prepend a `@'. | |
775 | (lambda (item) | |
776 | (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item) | |
777 | (concat "@" (match-string 1 item)))) | |
947faf4f | 778 | "`" "[' ]"))) |
d2c2b883 RS |
779 | |
780 | (info-lookup-maybe-add-help | |
781 | :mode 'm4-mode | |
782 | :regexp "[_a-zA-Z][_a-zA-Z0-9]*" | |
783 | :doc-spec '(("(m4)Macro index")) | |
784 | :parse-rule "[_a-zA-Z0-9]+") | |
785 | ||
786 | (info-lookup-maybe-add-help | |
787 | :mode 'autoconf-mode | |
788 | :regexp "A[CM]_[_A-Z0-9]+" | |
01e1a819 JB |
789 | :doc-spec '(;; Autoconf Macro Index entries are without an "AC_" prefix, |
790 | ;; but with "AH_" or "AU_" for those. So add "AC_" if there | |
791 | ;; isn't already an "A._". | |
792 | ("(autoconf)Autoconf Macro Index" | |
793 | (lambda (item) | |
794 | (if (string-match "^A._" item) item (concat "AC_" item))) | |
947faf4f | 795 | "^[ \t]+-+ \\(Macro\\|Variable\\): .*\\<" "\\>") |
01e1a819 JB |
796 | ;; M4 Macro Index entries are without "AS_" prefixes, and |
797 | ;; mostly without "m4_" prefixes. "dnl" is an exception, not | |
798 | ;; wanting any prefix. So AS_ is added back to upper-case | |
00fade45 | 799 | ;; names (if needed), m4_ to others which don't already an m4_. |
01e1a819 JB |
800 | ("(autoconf)M4 Macro Index" |
801 | (lambda (item) | |
802 | (let ((case-fold-search nil)) | |
803 | (cond ((or (string-equal item "dnl") | |
00fade45 TTN |
804 | (string-match "^m4_" item) |
805 | ;; Autoconf 2.62 index includes some macros | |
806 | ;; (e.g., AS_HELP_STRING), so avoid prefixing. | |
807 | (string-match "^AS_" item)) | |
01e1a819 JB |
808 | item) |
809 | ((string-match "^[A-Z0-9_]+$" item) | |
810 | (concat "AS_" item)) | |
811 | (t | |
812 | (concat "m4_" item))))) | |
947faf4f | 813 | "^[ \t]+-+ Macro: .*\\<" "\\>") |
01e1a819 JB |
814 | ;; Autotest Macro Index entries are without "AT_". |
815 | ("(autoconf)Autotest Macro Index" "AT_" | |
947faf4f | 816 | "^[ \t]+-+ Macro: .*\\<" "\\>") |
01e1a819 | 817 | ;; This is for older versions (probably pre autoconf 2.5x): |
28a2ca5d | 818 | ("(autoconf)Macro Index" "AC_" |
947faf4f | 819 | "^[ \t]+-+ \\(Macro\\|Variable\\): .*\\<" "\\>") |
01e1a819 JB |
820 | ;; Automake has index entries for its notes on various autoconf |
821 | ;; macros (eg. AC_PROG_CC). Ensure this is after the autoconf | |
822 | ;; index, so as to prefer the autoconf docs. | |
fdba4ab4 | 823 | ("(automake)Macro and Variable Index" nil |
d2c2b883 RS |
824 | "^[ \t]*`" "'")) |
825 | ;; Autoconf symbols are M4 macros. Thus use M4's parser. | |
826 | :parse-rule 'ignore | |
827 | :other-modes '(m4-mode)) | |
828 | ||
829 | (info-lookup-maybe-add-help | |
830 | :mode 'awk-mode | |
831 | :regexp "[_a-zA-Z]+" | |
832 | :doc-spec '(("(gawk)Index" | |
833 | (lambda (item) | |
834 | (let ((case-fold-search nil)) | |
835 | (cond | |
836 | ;; `BEGIN' and `END'. | |
837 | ((string-match "^\\([A-Z]+\\) special pattern\\b" item) | |
838 | (match-string 1 item)) | |
839 | ;; `if', `while', `do', ... | |
840 | ((string-match "^\\([a-z]+\\) statement\\b" item) | |
841 | (if (not (string-equal (match-string 1 item) "control")) | |
842 | (match-string 1 item))) | |
843 | ;; `NR', `NF', ... | |
844 | ((string-match "^[A-Z]+$" item) | |
845 | item) | |
846 | ;; Built-in functions (matches to many entries). | |
847 | ((string-match "^[a-z]+$" item) | |
848 | item)))) | |
849 | "`" "\\([ \t]*([^)]*)\\)?'"))) | |
850 | ||
851 | (info-lookup-maybe-add-help | |
852 | :mode 'perl-mode | |
853 | :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*" | |
854 | :doc-spec '(("(perl5)Function Index" | |
855 | (lambda (item) | |
856 | (if (string-match "^\\([a-zA-Z0-9]+\\)" item) | |
857 | (match-string 1 item))) | |
858 | "^" "\\b") | |
859 | ("(perl5)Variable Index" | |
860 | (lambda (item) | |
861 | ;; Work around bad formatted array variables. | |
862 | (let ((sym (cond ((or (string-match "^\\$\\(.\\|@@\\)$" item) | |
863 | (string-match "^\\$\\^[A-Z]$" item)) | |
864 | item) | |
865 | ((string-match | |
866 | "^\\([$%@]\\|@@\\)?[_a-zA-Z0-9]+" item) | |
867 | (match-string 0 item)) | |
868 | (t "")))) | |
869 | (if (string-match "@@" sym) | |
870 | (setq sym (concat (substring sym 0 (match-beginning 0)) | |
871 | (substring sym (1- (match-end 0)))))) | |
872 | (if (string-equal sym "") nil sym))) | |
873 | "^" "\\b")) | |
874 | :parse-rule "[$@%]?\\([_a-zA-Z0-9]+\\|[^a-zA-Z]\\)") | |
875 | ||
41b1cae7 SM |
876 | (info-lookup-maybe-add-help |
877 | :mode 'cperl-mode | |
878 | :regexp "[$@%][^a-zA-Z]\\|\\$\\^[A-Z]\\|[$@%]?[a-zA-Z][_a-zA-Z0-9]*" | |
879 | :other-modes '(perl-mode)) | |
880 | ||
d2c2b883 RS |
881 | (info-lookup-maybe-add-help |
882 | :mode 'latex-mode | |
883 | :regexp "\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)" | |
72d548a9 LL |
884 | :doc-spec `((,(if (Info-find-file "latex2e" t) |
885 | ;; From http://home.gna.org/latexrefman | |
886 | "(latex2e)Command Index" | |
887 | "(latex)Command Index") | |
888 | nil "`" "\\({[^}]*}\\)?'"))) | |
d2c2b883 RS |
889 | |
890 | (info-lookup-maybe-add-help | |
891 | :mode 'emacs-lisp-mode | |
ec4ef174 | 892 | :regexp "[^][()`',\" \t\n]+" |
16524b9b JB |
893 | :doc-spec '(;; Commands with key sequences appear in nodes as `foo' and |
894 | ;; those without as `M-x foo'. | |
895 | ("(emacs)Command Index" nil "`\\(M-x[ \t\n]+\\)?" "'") | |
896 | ;; Variables normally appear in nodes as just `foo'. | |
897 | ("(emacs)Variable Index" nil "`" "'") | |
898 | ;; Almost all functions, variables, etc appear in nodes as | |
947faf4f | 899 | ;; " -- Function: foo" etc. A small number of aliases and |
16524b9b JB |
900 | ;; symbols appear only as `foo', and will miss out on exact |
901 | ;; positions. Allowing `foo' would hit too many false matches | |
902 | ;; for things that should go to Function: etc, and those latter | |
903 | ;; are much more important. Perhaps this could change if some | |
904 | ;; sort of fallback match scheme existed. | |
947faf4f | 905 | ("(elisp)Index" nil "^ -+ .*: " "\\( \\|$\\)"))) |
d2c2b883 | 906 | |
8b5a10db KR |
907 | ;; docstrings talk about elisp, so have apropos-mode follow emacs-lisp-mode |
908 | (info-lookup-maybe-add-help | |
909 | :mode 'apropos-mode | |
910 | :regexp "[^][()`',\" \t\n]+" ;; same as emacs-lisp-mode above | |
911 | :other-modes '(emacs-lisp-mode)) | |
912 | ||
d2c2b883 RS |
913 | (info-lookup-maybe-add-help |
914 | :mode 'lisp-interaction-mode | |
ec4ef174 | 915 | :regexp "[^][()`',\" \t\n]+" |
d2c2b883 RS |
916 | :parse-rule 'ignore |
917 | :other-modes '(emacs-lisp-mode)) | |
918 | ||
0c10ee28 RS |
919 | (info-lookup-maybe-add-help |
920 | :mode 'lisp-mode | |
ec4ef174 | 921 | :regexp "[^()`',\" \t\n]+" |
0c10ee28 RS |
922 | :parse-rule 'ignore |
923 | :other-modes '(emacs-lisp-mode)) | |
924 | ||
9d37318d KH |
925 | (info-lookup-maybe-add-help |
926 | :mode 'scheme-mode | |
08d87b2d | 927 | :regexp "[^()`',\" \t\n]+" |
9d37318d | 928 | :ignore-case t |
6480a693 | 929 | ;; Aubrey Jaffer's rendition from <URL:ftp://ftp-swiss.ai.mit.edu/pub/scm> |
9d37318d | 930 | :doc-spec '(("(r5rs)Index" nil |
947faf4f | 931 | "^[ \t]+-+ [^:]+:[ \t]*" "\\b"))) |
9d37318d | 932 | |
054e5c20 SE |
933 | (info-lookup-maybe-add-help |
934 | :mode 'octave-mode | |
5d8137ab | 935 | :regexp "[_a-zA-Z0-9]+\\|\\s.+\\|[-!=^|*/.\\,><~&+]\\{1,3\\}\\|[][();,\"']" |
c6bb2688 | 936 | :doc-spec '(("(octave)Function Index" nil |
947faf4f JL |
937 | "^ -+ [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil) |
938 | ("(octave)Variable Index" nil "^ -+ [^:]+:[ ]+" nil) | |
5d8137ab | 939 | ("(octave)Operator Index" nil nil nil) |
054e5c20 | 940 | ;; Catch lines of the form "xyz statement" |
e35ccb9e | 941 | ("(octave)Concept Index" |
054e5c20 SE |
942 | (lambda (item) |
943 | (cond | |
944 | ((string-match "^\\([A-Z]+\\) statement\\b" item) | |
945 | (match-string 1 item)) | |
946 | (t nil))) | |
947faf4f | 947 | nil; "^ -+ [^:]+:[ ]+" don't think this prefix is useful here. |
054e5c20 | 948 | nil))) |
c0e7fbb8 | 949 | |
b3a3e4e1 SE |
950 | (info-lookup-maybe-add-help |
951 | :mode 'maxima-mode | |
952 | :ignore-case t | |
c99240cc | 953 | :regexp "[a-zA-Z0-9_%]+" |
947faf4f JL |
954 | :doc-spec '( ("(maxima)Function and Variable Index" nil |
955 | "^ -+ [^:]+:[ ]+\\(\\[[^=]*=[ ]+\\)?" nil))) | |
b3a3e4e1 SE |
956 | |
957 | (info-lookup-maybe-add-help | |
958 | :mode 'inferior-maxima-mode | |
c99240cc | 959 | :regexp "[a-zA-Z0-9_%]+" |
b3a3e4e1 SE |
960 | :other-modes '(maxima-mode)) |
961 | ||
c0e7fbb8 | 962 | ;; coreutils and bash builtins overlap in places, eg. printf, so there's a |
c6bb2688 | 963 | ;; question which should come first. Some of the coreutils descriptions are |
c0e7fbb8 JB |
964 | ;; more detailed, but if bash is usually /bin/sh on a GNU system then the |
965 | ;; builtins will be what's normally run. | |
966 | ;; | |
967 | ;; Maybe special variables like $? should be matched as $?, not just ?. | |
968 | ;; This would avoid a clash between variable $! and negation !, or variable | |
969 | ;; $# and comment # (though comment # is not currently indexed in bash). | |
970 | ;; Unfortunately if $? etc is the symbol, then we wouldn't be taken to the | |
971 | ;; exact spot in the relevant node, since the bash manual has just `?' etc | |
972 | ;; there. Maybe an extension to the prefix/suffix scheme could help this. | |
973 | ||
974 | (info-lookup-maybe-add-help | |
975 | :mode 'sh-mode :topic 'symbol | |
976 | ;; bash has "." and ":" in its index, but those chars will probably never | |
977 | ;; work in info, so don't bother matching them in the regexp. | |
978 | :regexp "\\([a-zA-Z0-9_-]+\\|[!{}@*#?$]\\|\\[\\[?\\|]]?\\)" | |
979 | :doc-spec '(("(bash)Builtin Index" nil "^`" "[ .']") | |
980 | ("(bash)Reserved Word Index" nil "^`" "[ .']") | |
981 | ("(bash)Variable Index" nil "^`" "[ .']") | |
39764e76 | 982 | |
c0e7fbb8 JB |
983 | ;; coreutils (version 4.5.10) doesn't have a separate program |
984 | ;; index, so exclude extraneous stuff (most of it) by demanding | |
985 | ;; "[a-z]+" in the trans-func. | |
39764e76 KR |
986 | ;; coreutils version 8.1 has node "Concept Index" and past |
987 | ;; versions have node "Index", look for both, whichever is | |
988 | ;; absent is quietly ignored | |
c0e7fbb8 JB |
989 | ("(coreutils)Index" |
990 | (lambda (item) (if (string-match "\\`[a-z]+\\'" item) item))) | |
39764e76 KR |
991 | ("(coreutils)Concept Index" |
992 | (lambda (item) (if (string-match "\\`[a-z]+\\'" item) item))) | |
993 | ||
c0e7fbb8 JB |
994 | ;; diff (version 2.8.1) has only a few programs, index entries |
995 | ;; are things like "foo invocation". | |
996 | ("(diff)Index" | |
997 | (lambda (item) | |
998 | (if (string-match "\\`\\([a-z]+\\) invocation\\'" item) | |
999 | (match-string 1 item)))) | |
1000 | ;; there's no plain "sed" index entry as such, mung another | |
1001 | ;; hopefully unique one to get to the invocation section | |
1002 | ("(sed)Concept Index" | |
1003 | (lambda (item) | |
1004 | (if (string-equal item "Standard input, processing as input") | |
1005 | "sed"))) | |
1006 | ;; there's no plain "awk" or "gawk" index entries, mung other | |
1007 | ;; hopefully unique ones to get to the command line options | |
1008 | ("(gawk)Index" | |
1009 | (lambda (item) | |
1010 | (cond ((string-equal item "gawk, extensions, disabling") | |
1011 | "awk") | |
1012 | ((string-equal item "gawk, versions of, information about, printing") | |
1013 | "gawk")))))) | |
538996c7 | 1014 | |
7830c895 SM |
1015 | ;; This misses some things which occur as node names but not in the |
1016 | ;; index. Unfortunately it also picks up the wrong one of multiple | |
1017 | ;; entries for the same term in some cases. --fx | |
538996c7 SM |
1018 | (info-lookup-maybe-add-help |
1019 | :mode 'cfengine-mode | |
1bc897ca | 1020 | :regexp "[[:alnum:]_]+\\(?:()\\)?" |
7830c895 SM |
1021 | :doc-spec '(("(cfengine-Reference)Variable Index" |
1022 | (lambda (item) | |
1023 | ;; Index entries may be like `IsPlain()' | |
1024 | (if (string-match "\\([[:alnum:]_]+\\)()" item) | |
1025 | (match-string 1 item) | |
1026 | item)) | |
1027 | ;; This gets functions in evaluated classes. Other | |
1028 | ;; possible patterns don't seem to work too well. | |
1029 | "`" "("))) | |
ec4ef174 EZ |
1030 | |
1031 | (info-lookup-maybe-add-help | |
e8b36335 | 1032 | :mode 'Custom-mode |
ec4ef174 EZ |
1033 | :ignore-case t |
1034 | :regexp "[^][()`',:\" \t\n]+" | |
1035 | :parse-rule 'info-lookup-guess-custom-symbol | |
1036 | :other-modes '(emacs-lisp-mode)) | |
1037 | ||
1038 | (info-lookup-maybe-add-help | |
1039 | :mode 'help-mode | |
1040 | :regexp "[^][()`',:\" \t\n]+" | |
1041 | :other-modes '(emacs-lisp-mode)) | |
d2c2b883 | 1042 | \f |
5a79736d RS |
1043 | (provide 'info-look) |
1044 | ||
1045 | ;;; info-look.el ends here |