annotate lisp/info-look.el @ 20690:a51c71dd5cda

(info-lookup): Report if Info-goto-node fails. (info-lookup-make-completions): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Tue, 20 Jan 1998 20:09:39 +0000
parents c7b3ef0ed1ad
children d1f6ac340403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; info-look.el --- major-mode-sensitive Info index lookup facility.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; An older version of this was known as libc.el.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
4 ;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Ralph Schleicher <rs@purple.UL.BaWue.DE>
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: help languages
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Code:
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 (require 'info)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (defvar info-lookup-mode nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 "*Symbol of the current buffer's help mode.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 Provide help according to the buffer's major mode if value is nil.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 Automatically becomes buffer local when set in any fashion.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (make-variable-buffer-local 'info-lookup-mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (defvar info-lookup-other-window-flag t
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 "*Non-nil means pop up the Info buffer in another window.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (defvar info-lookup-highlight-face 'highlight
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 "*Face for highlighting looked up help items.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 Setting this variable to nil disables highlighting.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defvar info-lookup-highlight-overlay nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 "Overlay object used for highlighting.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (defvar info-lookup-history nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 "History of previous input lines.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (defvar info-lookup-alist '((symbol . info-lookup-symbol-alist)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (file . info-lookup-file-alist))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "*Alist of known help topics.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 Cons cells are of the form
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (HELP-TOPIC . VARIABLE)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 HELP-TOPIC is the symbol of a help topic.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 VARIABLE is a variable storing HELP-TOPIC's public data.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 Value is an alist with elements of the form
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (HELP-MODE REGEXP IGNORE-CASE DOC-SPEC PARSE-RULE OTHER-MODES)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 HELP-MODE is a mode's symbol.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 REGEXP is a regular expression matching those help items whose
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 documentation can be looked up via DOC-SPEC.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 IGNORE-CASE is non-nil if help items are case insensitive.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 DOC-SPEC is a list of documentation specifications of the form
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (INFO-NODE TRANS-FUNC PREFIX SUFFIX)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 INFO-NODE is the name (including file name part) of an Info index.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 TRANS-FUNC is a function translating index entries into help items;
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 nil means add only those index entries matching REGEXP, a string
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 means prepend string to the first word of all index entries.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 PREFIX and SUFFIX are parts of a regular expression. If one of
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 them is non-nil then search the help item's Info node for the
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 first occurrence of the regular expression `PREFIX ITEM SUFFIX'.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ITEM will be highlighted with `info-lookup-highlight-face' if this
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 variable is not nil.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 PARSE-RULE is either the symbol name of a function or a regular
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 expression for guessing the default help item at point. Fuzzy
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 regular expressions like \"[_a-zA-Z0-9]+\" do a better job if
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 there are no clear delimiters; do not try to write too complex
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 expressions. PARSE-RULE defaults to REGEXP.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 OTHER-MODES is a list of cross references to other help modes.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (defsubst info-lookup->topic-value (topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (symbol-value (cdr (assoc topic info-lookup-alist))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defsubst info-lookup->mode-value (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (assoc mode (info-lookup->topic-value topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defsubst info-lookup->regexp (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (nth 1 (info-lookup->mode-value topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defsubst info-lookup->ignore-case (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (nth 2 (info-lookup->mode-value topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defsubst info-lookup->doc-spec (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (nth 3 (info-lookup->mode-value topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defsubst info-lookup->parse-rule (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (nth 4 (info-lookup->mode-value topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defsubst info-lookup->other-modes (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (nth 5 (info-lookup->mode-value topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar info-lookup-cache nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 "Cache storing data maintained automatically by the program.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 Value is an alist with cons cell of the form
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (HELP-TOPIC . ((HELP-MODE INITIALIZED COMPLETIONS REFER-MODES) ...))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 HELP-TOPIC is the symbol of a help topic.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 HELP-MODE is a mode's symbol.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 INITIALIZED is nil if HELP-MODE is uninitialized, t if
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 HELP-MODE is initialized, and `0' means HELP-MODE is
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 initialized but void.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 COMPLETIONS is an alist of documented help items.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 REFER-MODES is a list of other help modes to use.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defsubst info-lookup->cache (topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (or (assoc topic info-lookup-cache)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (car (setq info-lookup-cache
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (cons (cons topic nil)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 info-lookup-cache)))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defsubst info-lookup->topic-cache (topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (cdr (info-lookup->cache topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (defsubst info-lookup->mode-cache (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (assoc mode (info-lookup->topic-cache topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defsubst info-lookup->initialized (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (nth 1 (info-lookup->mode-cache topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (defsubst info-lookup->completions (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (or (info-lookup->initialized topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (info-lookup-setup-mode topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (nth 2 (info-lookup->mode-cache topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defsubst info-lookup->refer-modes (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (or (info-lookup->initialized topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (info-lookup-setup-mode topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (nth 3 (info-lookup->mode-cache topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (defsubst info-lookup->all-modes (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (cons mode (info-lookup->refer-modes topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defvar info-lookup-symbol-alist
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 '((autoconf-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 "A[CM]_[_A-Z0-9]+" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (("(autoconf)Macro Index" "AC_"
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 "^[ \t]+- \\(Macro\\|Variable\\): .*\\<" "\\>")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ("(automake)Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "^[ \t]*`" "'"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; Autoconf symbols are M4 macros. Thus use M4's parser.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ignore
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (m4-mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (bison-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 "[:;|]\\|%\\([%{}]\\|[_a-z]+\\)\\|YY[_A-Z]+\\|yy[_a-z]+" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (("(bison)Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "`" "'"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 "[:;|]\\|%\\([%{}]\\|[_a-zA-Z][_a-zA-Z0-9]*\\)"
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (c-mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (c-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 "\\(struct \\|union \\|enum \\)?[_a-zA-Z][_a-zA-Z0-9]*" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (("(libc)Function Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 "^[ \t]+- \\(Function\\|Macro\\): .*\\<" "\\>")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ("(libc)Variable Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 "^[ \t]+- \\(Variable\\|Macro\\): .*\\<" "\\>")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ("(libc)Type Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 "^[ \t]+- Data Type: \\<" "\\>")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ("(termcap)Var Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 "^[ \t]*`" "'"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 info-lookup-guess-c-symbol)
20519
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
176 (emacs-lisp-mode
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
177 "[-_a-zA-Z+=*:&%$#@!^~][-_a-zA-Z0-9+=*:&%$#@!^~]*" nil
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
178 ("(elisp)Index" nil
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
179 "^[ \t]+- \\(Function\\|Macro\\|User Option\\|Variable\\): .*\\<"
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
180 "\\>"))
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (m4-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 "[_a-zA-Z][_a-zA-Z0-9]*" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (("(m4)Macro index"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 "[_a-zA-Z0-9]+")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (makefile-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z][_a-zA-Z0-9-]*" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (("(make)Name Index" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 "^[ \t]*`" "'"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "\\$[^({]\\|\\.[_A-Z]*\\|[_a-zA-Z0-9-]+")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (texinfo-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 "@\\([a-zA-Z]+\\|[^a-zA-Z]\\)" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (("(texinfo)Command and Variable Index"
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; Ignore Emacs commands and prepend a `@'.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (lambda (item)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if (string-match "^\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\( .*\\)?$" item)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (concat "@" (match-string 1 item))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 "`" "'"))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 "*Alist of help specifications for symbol names.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 See the documentation of the variable `info-lookup-alist' for more details.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (defvar info-lookup-file-alist
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 '((c-mode
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 "[_a-zA-Z0-9./+-]+" nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (("(libc)File Index"))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 "*Alist of help specifications for file names.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 See the documentation of the variable `info-lookup-alist' for more details.")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;;;###autoload
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (defun info-lookup-reset ()
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "Throw away all cached data.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 This command is useful if the user wants to start at the beginning without
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 quitting Emacs, for example, after some Info documents were updated on the
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 system."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (interactive)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (setq info-lookup-cache nil))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;;;###autoload
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defun info-lookup-symbol (symbol &optional mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 "Display the documentation of a symbol.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 If called interactively, SYMBOL will be read from the mini-buffer.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 Prefix argument means unconditionally insert the default symbol name
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 into the mini-buffer so that it can be edited.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 The default symbol is the one found at point."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (interactive
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (info-lookup-interactive-arguments 'symbol))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (info-lookup 'symbol symbol mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;;;###autoload
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (defun info-lookup-file (file &optional mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 "Display the documentation of a file.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 If called interactively, FILE will be read from the mini-buffer.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 Prefix argument means unconditionally insert the default file name
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 into the mini-buffer so that it can be edited.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 The default file name is the one found at point."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (interactive
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (info-lookup-interactive-arguments 'file))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (info-lookup 'file file mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun info-lookup-interactive-arguments (topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 "Return default value and help mode for help topic TOPIC."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (let* ((mode (if (info-lookup->mode-value
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 topic (or info-lookup-mode major-mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (or info-lookup-mode major-mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (info-lookup-change-mode topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (completions (info-lookup->completions topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (default (info-lookup-guess-default topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (input (if (or current-prefix-arg (not (assoc default completions)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 default))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (completion-ignore-case (info-lookup->ignore-case topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (enable-recursive-minibuffers t)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (value (completing-read
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (if (and default (not input))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (format "Describe %s (default %s): " topic default)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (format "Describe %s: " topic))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 completions nil nil input 'info-lookup-history)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (list (if (equal value "") default value) mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun info-lookup-change-mode (topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (let* ((completions (mapcar (lambda (arg)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (cons (symbol-name (car arg)) (car arg)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (info-lookup->topic-value topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (mode (completing-read
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (format "Use %s help mode: " topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 completions nil t nil 'info-lookup-history)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (or (setq mode (cdr (assoc mode completions)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (error "No %s help available" topic))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (or (info-lookup->mode-value topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (error "No %s help available for `%s'" topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (setq info-lookup-mode mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun info-lookup (topic item mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 "Display the documentation of a help item."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (if (not mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (setq mode (or info-lookup-mode major-mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (or (info-lookup->mode-value topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (error "No %s help available for `%s'" topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (let ((entry (or (assoc (if (info-lookup->ignore-case topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (downcase item) item)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (info-lookup->completions topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (error "Not documented as a %s: %s" topic (or item ""))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (modes (info-lookup->all-modes topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (window (selected-window))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
283 found doc-spec node prefix suffix doc-found)
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (if (not info-lookup-other-window-flag)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (info)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (save-window-excursion (info))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (switch-to-buffer-other-window "*info*"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (while (and (not found) modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (setq doc-spec (info-lookup->doc-spec topic (car modes)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (while (and (not found) doc-spec)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (setq node (nth 0 (car doc-spec))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 prefix (nth 2 (car doc-spec))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 suffix (nth 3 (car doc-spec)))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
294 (when (condition-case error-data
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
295 (progn
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
296 (Info-goto-node node)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
297 (setq doc-found t))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
298 (error
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
299 (message "Cannot access Info node %s" node)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
300 (sit-for 1)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
301 nil))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
302 (condition-case nil
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
303 (progn
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
304 (Info-menu (or (cdr entry) item))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
305 (setq found t)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
306 (if (or prefix suffix)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
307 (let ((case-fold-search
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
308 (info-lookup->ignore-case topic (car modes)))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
309 (buffer-read-only nil))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
310 (goto-char (point-min))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
311 (re-search-forward
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
312 (concat prefix (regexp-quote item) suffix))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
313 (goto-char (match-beginning 0))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
314 (and window-system info-lookup-highlight-face
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
315 ;; Search again for ITEM so that the first
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
316 ;; occurence of ITEM will be highlighted.
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
317 (re-search-forward (regexp-quote item))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
318 (let ((start (match-beginning 0))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
319 (end (match-end 0)))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
320 (if (overlayp info-lookup-highlight-overlay)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
321 (move-overlay info-lookup-highlight-overlay
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
322 start end (current-buffer))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
323 (setq info-lookup-highlight-overlay
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
324 (make-overlay start end))))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
325 (overlay-put info-lookup-highlight-overlay
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
326 'face info-lookup-highlight-face)))))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
327 (error nil)))
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (setq doc-spec (cdr doc-spec)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (setq modes (cdr modes)))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
330 (or doc-found
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
331 (error "Info documentation for lookup was not found"))
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ;; Don't leave the Info buffer if the help item couldn't be looked up.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (if (and info-lookup-other-window-flag found)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (select-window window))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (defun info-lookup-setup-mode (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 "Initialize the internal data structure."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (or (info-lookup->initialized topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (let (cell data (initialized 0) completions refer-modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (if (not (info-lookup->mode-value topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (message "No %s help available for `%s'" topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 ;; Recursively setup cross references.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 ;; But refer only to non-void modes.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (mapcar (lambda (arg)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (or (info-lookup->initialized topic arg)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (info-lookup-setup-mode topic arg))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (and (eq (info-lookup->initialized topic arg) t)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (setq refer-modes (cons arg refer-modes))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (info-lookup->other-modes topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (setq refer-modes (nreverse refer-modes))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 ;; Build the full completion alist.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (setq completions
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (nconc (info-lookup-make-completions topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (apply 'append
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (mapcar (lambda (arg)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (info-lookup->completions topic arg))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 refer-modes))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq initialized t))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 ;; Update `info-lookup-cache'.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (setq cell (info-lookup->mode-cache topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 data (list initialized completions refer-modes))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (if (not cell)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (setcdr (info-lookup->cache topic)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (cons (cons mode data) (info-lookup->topic-cache topic)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (setcdr cell data))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 initialized)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (defun info-lookup-make-completions (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 "Create a unique alist from all index entries."
20519
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
370 (let ((doc-spec (info-lookup->doc-spec topic mode))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
371 (regexp (concat "^\\(" (info-lookup->regexp topic mode)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
372 "\\)\\([ \t].*\\)?$"))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
373 node trans entry item prefix result doc-found
20519
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
374 (buffer (get-buffer-create " temp-info-look")))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
375 (with-current-buffer buffer
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
376 (Info-mode))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
377 (while doc-spec
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
378 (setq node (nth 0 (car doc-spec))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
379 trans (cond ((eq (nth 1 (car doc-spec)) nil)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
380 (lambda (arg)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
381 (if (string-match regexp arg)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
382 (match-string 1 arg))))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
383 ((stringp (nth 1 (car doc-spec)))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
384 (setq prefix (nth 1 (car doc-spec)))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
385 (lambda (arg)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
386 (if (string-match "^\\([^: \t\n]+\\)" arg)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
387 (concat prefix (match-string 1 arg)))))
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
388 (t (nth 1 (car doc-spec)))))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
389 (with-current-buffer buffer
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
390 (message "Processing Info node `%s'..." node)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
391 (when (condition-case error-data
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
392 (progn
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
393 (Info-goto-node node)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
394 (setq doc-found t))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
395 (error
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
396 (message "Cannot access Info node `%s'" node)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
397 (sit-for 1)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
398 nil))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
399 (condition-case nil
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
400 (progn
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
401 (goto-char (point-min))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
402 (and (search-forward "\n* Menu:" nil t)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
403 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
404 (setq entry (match-string 1)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
405 item (funcall trans entry))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
406 (and (info-lookup->ignore-case topic mode)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
407 (setq item (downcase item)))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
408 (and (string-equal entry item)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
409 (setq entry nil))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
410 (or (assoc item result)
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
411 (setq result (cons (cons item entry) result))))))
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
412 (error nil))))
20519
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
413 (message "Processing Info node `%s'...done" node)
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
414 (setq doc-spec (cdr doc-spec)))
20690
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
415 (or doc-found
a51c71dd5cda (info-lookup): Report if Info-goto-node fails.
Richard M. Stallman <rms@gnu.org>
parents: 20519
diff changeset
416 (error "Info documentation for lookup was not found"))
20519
c7b3ef0ed1ad (info-lookup-symbol-alist): Handle Emacs Lisp mode.
Richard M. Stallman <rms@gnu.org>
parents: 18323
diff changeset
417 result))
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (defun info-lookup-guess-default (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 "Pick up default item at point (with favor to look back).
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 Return nil if there is nothing appropriate."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (let ((modes (info-lookup->all-modes topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (start (point)) guess whitespace)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (while (and (not guess) modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (setq guess (info-lookup-guess-default* topic (car modes))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 modes (cdr modes))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (goto-char start))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 ;; Collapse whitespace characters.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (and guess (concat (delete nil (mapcar (lambda (ch)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (if (or (char-equal ch ? )
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (char-equal ch ?\t)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (char-equal ch ?\n))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (if (not whitespace)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (setq whitespace ? ))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (setq whitespace nil) ch))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 guess))))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (defun info-lookup-guess-default* (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (let ((case-fold-search (info-lookup->ignore-case topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (rule (or (info-lookup->parse-rule topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (info-lookup->regexp topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (start (point)) end regexp subexp result)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (symbolp rule)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq result (funcall rule))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (if (consp rule)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (setq regexp (car rule)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 subexp (cdr rule))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (setq regexp rule
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 subexp 0))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (skip-chars-backward " \t\n") (setq end (point))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (while (and (re-search-backward regexp nil t)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (looking-at regexp)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (>= (match-end 0) end))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (setq result (match-string subexp)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (if (not result)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (progn
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (goto-char start)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (skip-chars-forward " \t\n")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (and (looking-at regexp)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (setq result (match-string subexp))))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 result))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (defun info-lookup-guess-c-symbol ()
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 "Get the C symbol at point."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (condition-case nil
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (progn
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (backward-sexp)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (let ((start (point)) prefix name)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 ;; Test for a leading `struct', `union', or `enum' keyword
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 ;; but ignore names like `foo_struct'.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (setq prefix (and (< (skip-chars-backward " \t\n") 0)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (< (skip-chars-backward "_a-zA-Z0-9") 0)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (looking-at "\\(struct\\|union\\|enum\\)\\s ")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (concat (match-string 1) " ")))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (goto-char start)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (and (looking-at "[_a-zA-Z][_a-zA-Z0-9]*")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (setq name (match-string 0)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 ;; Caveat! Look forward if point is at `struct' etc.
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (and (not prefix)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (or (string-equal name "struct")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (string-equal name "union")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (string-equal name "enum"))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (looking-at "[a-z]+\\s +\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (setq prefix (concat name " ")
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 name (match-string 1)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (and (or prefix name)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (concat prefix name))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (error nil)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 ;;;###autoload
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (defun info-complete-symbol (&optional mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 "Perform completion on symbol preceding point."
18323
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
493 (interactive)
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
494 (info-complete 'symbol
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
495 (or mode
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
496 (if (info-lookup->mode-value
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
497 'symbol (or info-lookup-mode major-mode))
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
498 (or info-lookup-mode major-mode)
64d728fb396a (info-complete-symbol): If MODE is nil, use the default value.
Richard M. Stallman <rms@gnu.org>
parents: 18322
diff changeset
499 (info-lookup-change-mode 'symbol)))))
18322
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 ;;;###autoload
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (defun info-complete-file (&optional mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 "Perform completion on file preceding point."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (interactive
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (list (if (info-lookup->mode-value
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 'file (or info-lookup-mode major-mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (or info-lookup-mode major-mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (info-lookup-change-mode 'file))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (info-complete 'file mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (defun info-complete (topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 "Try to complete a help item."
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (barf-if-buffer-read-only)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (if (not mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (setq mode (or info-lookup-mode major-mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (or (info-lookup->mode-value topic mode)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (error "No %s completion available for `%s'" topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (let ((modes (info-lookup->all-modes topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (start (point)) try completion)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (while (and (not try) modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (setq mode (car modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 modes (cdr modes)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 try (info-lookup-guess-default* topic mode))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (goto-char start))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (and (not try)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (error "Found no %s to complete" topic))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (setq completion (try-completion
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 try (info-lookup->completions topic mode)))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (cond ((not completion)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (ding))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 ((stringp completion)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (delete-region (- start (length try)) start)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (insert completion)))))
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (provide 'info-look)
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536
02f932c91db2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 ;;; info-look.el ends here