Mercurial > emacs
annotate lispref/abbrevs.texi @ 27223:ac1bc60cf0b4
GUD tooltips.
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 05 Jan 2000 23:49:34 +0000 |
parents | d2e5f1b7d8e2 |
children | 199ada58fd5d |
rev | line source |
---|---|
6552 | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | |
27189 | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1999 |
4 @c Free Software Foundation, Inc. | |
6552 | 5 @c See the file elisp.texi for copying conditions. |
6 @setfilename ../info/abbrevs | |
7 @node Abbrevs, Processes, Syntax Tables, Top | |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
8 @chapter Abbrevs and Abbrev Expansion |
6552 | 9 @cindex abbrev |
10 @cindex abbrev table | |
11 | |
12 An abbreviation or @dfn{abbrev} is a string of characters that may be | |
13 expanded to a longer string. The user can insert the abbrev string and | |
14 find it replaced automatically with the expansion of the abbrev. This | |
15 saves typing. | |
16 | |
17 The set of abbrevs currently in effect is recorded in an @dfn{abbrev | |
18 table}. Each buffer has a local abbrev table, but normally all buffers | |
19 in the same major mode share one abbrev table. There is also a global | |
20 abbrev table. Normally both are used. | |
21 | |
22 An abbrev table is represented as an obarray containing a symbol for | |
7688 | 23 each abbreviation. The symbol's name is the abbreviation; its value is |
6552 | 24 the expansion; its function definition is the hook function to do the |
7688 | 25 expansion (@pxref{Defining Abbrevs}); its property list cell contains |
26 the use count, the number of times the abbreviation has been expanded. | |
27 Because these symbols are not interned in the usual obarray, they will | |
28 never appear as the result of reading a Lisp expression; in fact, | |
29 normally they are never used except by the code that handles abbrevs. | |
30 Therefore, it is safe to use them in an extremely nonstandard way. | |
31 @xref{Creating Symbols}. | |
6552 | 32 |
33 For the user-level commands for abbrevs, see @ref{Abbrevs,, Abbrev | |
34 Mode, emacs, The GNU Emacs Manual}. | |
35 | |
36 @menu | |
37 * Abbrev Mode:: Setting up Emacs for abbreviation. | |
38 * Tables: Abbrev Tables. Creating and working with abbrev tables. | |
39 * Defining Abbrevs:: Specifying abbreviations and their expansions. | |
40 * Files: Abbrev Files. Saving abbrevs in files. | |
41 * Expansion: Abbrev Expansion. Controlling expansion; expansion subroutines. | |
42 * Standard Abbrev Tables:: Abbrev tables used by various major modes. | |
43 @end menu | |
44 | |
45 @node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs | |
46 @comment node-name, next, previous, up | |
47 @section Setting Up Abbrev Mode | |
48 | |
49 Abbrev mode is a minor mode controlled by the value of the variable | |
50 @code{abbrev-mode}. | |
51 | |
52 @defvar abbrev-mode | |
53 A non-@code{nil} value of this variable turns on the automatic expansion | |
54 of abbrevs when their abbreviations are inserted into a buffer. | |
55 If the value is @code{nil}, abbrevs may be defined, but they are not | |
56 expanded automatically. | |
57 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
58 This variable automatically becomes buffer-local when set in any fashion. |
6552 | 59 @end defvar |
60 | |
61 @defvar default-abbrev-mode | |
7688 | 62 This is the value of @code{abbrev-mode} for buffers that do not override it. |
6552 | 63 This is the same as @code{(default-value 'abbrev-mode)}. |
64 @end defvar | |
65 | |
66 @node Abbrev Tables, Defining Abbrevs, Abbrev Mode, Abbrevs | |
67 @section Abbrev Tables | |
68 | |
69 This section describes how to create and manipulate abbrev tables. | |
70 | |
71 @defun make-abbrev-table | |
72 This function creates and returns a new, empty abbrev table---an obarray | |
73 containing no symbols. It is a vector filled with zeros. | |
74 @end defun | |
75 | |
76 @defun clear-abbrev-table table | |
77 This function undefines all the abbrevs in abbrev table @var{table}, | |
26192 | 78 leaving it empty. The function returns @code{nil}. |
6552 | 79 @end defun |
80 | |
81 @defun define-abbrev-table tabname definitions | |
82 This function defines @var{tabname} (a symbol) as an abbrev table name, | |
83 i.e., as a variable whose value is an abbrev table. It defines abbrevs | |
84 in the table according to @var{definitions}, a list of elements of the | |
85 form @code{(@var{abbrevname} @var{expansion} @var{hook} | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
86 @var{usecount})}. The return value is always @code{nil}. |
6552 | 87 @end defun |
88 | |
89 @defvar abbrev-table-name-list | |
90 This is a list of symbols whose values are abbrev tables. | |
91 @code{define-abbrev-table} adds the new abbrev table name to this list. | |
92 @end defvar | |
93 | |
94 @defun insert-abbrev-table-description name &optional human | |
95 This function inserts before point a description of the abbrev table | |
96 named @var{name}. The argument @var{name} is a symbol whose value is an | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
97 abbrev table. The return value is always @code{nil}. |
6552 | 98 |
99 If @var{human} is non-@code{nil}, the description is human-oriented. | |
100 Otherwise the description is a Lisp expression---a call to | |
7688 | 101 @code{define-abbrev-table} that would define @var{name} exactly as it |
6552 | 102 is currently defined. |
103 @end defun | |
104 | |
105 @node Defining Abbrevs, Abbrev Files, Abbrev Tables, Abbrevs | |
106 @comment node-name, next, previous, up | |
107 @section Defining Abbrevs | |
108 | |
109 These functions define an abbrev in a specified abbrev table. | |
110 @code{define-abbrev} is the low-level basic function, while | |
111 @code{add-abbrev} is used by commands that ask for information from the | |
112 user. | |
113 | |
114 @defun add-abbrev table type arg | |
7688 | 115 This function adds an abbreviation to abbrev table @var{table} based on |
116 information from the user. The argument @var{type} is a string | |
117 describing in English the kind of abbrev this will be (typically, | |
118 @code{"global"} or @code{"mode-specific"}); this is used in prompting | |
119 the user. The argument @var{arg} is the number of words in the | |
120 expansion. | |
6552 | 121 |
26192 | 122 |
7688 | 123 The return value is the symbol that internally represents the new |
6552 | 124 abbrev, or @code{nil} if the user declines to confirm redefining an |
125 existing abbrev. | |
126 @end defun | |
127 | |
26192 | 128 @defun define-abbrev table name expansion &optional hook count |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
129 This function defines an abbrev named @var{name}, in @var{table}, to |
26192 | 130 expand to @var{expansion} and call @var{hook}. The value of |
131 @var{count}, if specified, initializes the abbrev's usage-count. If | |
132 @var{count} is not specified or @code{nil}, the use count is initialized | |
133 to zero. The return value is a symbol that represents the abbrev inside | |
134 Emacs; its name is @var{name}. | |
6552 | 135 |
136 The argument @var{name} should be a string. The argument | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
137 @var{expansion} is normally the desired expansion (a string), or |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
138 @code{nil} to undefine the abbrev. If it is anything but a string or |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
139 @code{nil}, then the abbreviation ``expands'' solely by running |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
140 @var{hook}. |
6552 | 141 |
26192 | 142 |
6552 | 143 The argument @var{hook} is a function or @code{nil}. If @var{hook} is |
144 non-@code{nil}, then it is called with no arguments after the abbrev is | |
145 replaced with @var{expansion}; point is located at the end of | |
7688 | 146 @var{expansion} when @var{hook} is called. |
6552 | 147 @end defun |
148 | |
149 @defopt only-global-abbrevs | |
150 If this variable is non-@code{nil}, it means that the user plans to use | |
151 global abbrevs only. This tells the commands that define mode-specific | |
152 abbrevs to define global ones instead. This variable does not alter the | |
7688 | 153 behavior of the functions in this section; it is examined by their |
6552 | 154 callers. |
155 @end defopt | |
156 | |
157 @node Abbrev Files, Abbrev Expansion, Defining Abbrevs, Abbrevs | |
158 @section Saving Abbrevs in Files | |
159 | |
160 A file of saved abbrev definitions is actually a file of Lisp code. | |
161 The abbrevs are saved in the form of a Lisp program to define the same | |
162 abbrev tables with the same contents. Therefore, you can load the file | |
163 with @code{load} (@pxref{How Programs Do Loading}). However, the | |
164 function @code{quietly-read-abbrev-file} is provided as a more | |
165 convenient interface. | |
166 | |
167 User-level facilities such as @code{save-some-buffers} can save | |
168 abbrevs in a file automatically, under the control of variables | |
169 described here. | |
170 | |
171 @defopt abbrev-file-name | |
172 This is the default file name for reading and saving abbrevs. | |
173 @end defopt | |
174 | |
26192 | 175 @defun quietly-read-abbrev-file &optional filename |
6552 | 176 This function reads abbrev definitions from a file named @var{filename}, |
177 previously written with @code{write-abbrev-file}. If @var{filename} is | |
26192 | 178 omitted or @code{nil}, the file specified in @code{abbrev-file-name} is |
179 used. @code{save-abbrevs} is set to @code{t} so that changes will be | |
180 saved. | |
6552 | 181 |
182 This function does not display any messages. It returns @code{nil}. | |
183 @end defun | |
184 | |
185 @defopt save-abbrevs | |
186 A non-@code{nil} value for @code{save-abbrev} means that Emacs should | |
187 save abbrevs when files are saved. @code{abbrev-file-name} specifies | |
188 the file to save the abbrevs in. | |
189 @end defopt | |
190 | |
191 @defvar abbrevs-changed | |
192 This variable is set non-@code{nil} by defining or altering any | |
193 abbrevs. This serves as a flag for various Emacs commands to offer to | |
194 save your abbrevs. | |
195 @end defvar | |
196 | |
26192 | 197 @deffn Command write-abbrev-file &optional filename |
6552 | 198 Save all abbrev definitions, in all abbrev tables, in the file |
7688 | 199 @var{filename}, in the form of a Lisp program that when loaded will |
26192 | 200 define the same abbrevs. If @var{filename} is @code{nil} or omitted, |
201 @code{abbrev-file-name} is used. This function returns @code{nil}. | |
6552 | 202 @end deffn |
203 | |
204 @node Abbrev Expansion, Standard Abbrev Tables, Abbrev Files, Abbrevs | |
205 @comment node-name, next, previous, up | |
206 @section Looking Up and Expanding Abbreviations | |
207 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
208 Abbrevs are usually expanded by certain interactive commands, |
6552 | 209 including @code{self-insert-command}. This section describes the |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
210 subroutines used in writing such commands, as well as the variables they |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
211 use for communication. |
6552 | 212 |
213 @defun abbrev-symbol abbrev &optional table | |
214 This function returns the symbol representing the abbrev named | |
215 @var{abbrev}. The value returned is @code{nil} if that abbrev is not | |
216 defined. The optional second argument @var{table} is the abbrev table | |
217 to look it up in. If @var{table} is @code{nil}, this function tries | |
218 first the current buffer's local abbrev table, and second the global | |
219 abbrev table. | |
220 @end defun | |
221 | |
7688 | 222 @defun abbrev-expansion abbrev &optional table |
223 This function returns the string that @var{abbrev} would expand into (as | |
224 defined by the abbrev tables used for the current buffer). The optional | |
225 argument @var{table} specifies the abbrev table to use, as in | |
226 @code{abbrev-symbol}. | |
227 @end defun | |
228 | |
229 @deffn Command expand-abbrev | |
26192 | 230 This command expands the abbrev before point, if any. If point does not |
231 follow an abbrev, this command does nothing. The command returns the | |
232 abbrev symbol if it did expansion, @code{nil} otherwise. | |
7688 | 233 @end deffn |
234 | |
26192 | 235 |
7688 | 236 @deffn Command abbrev-prefix-mark &optional arg |
237 Mark current point as the beginning of an abbrev. The next call to | |
238 @code{expand-abbrev} will use the text from here to point (where it is | |
239 then) as the abbrev to expand, rather than using the previous word as | |
240 usual. | |
241 @end deffn | |
242 | |
6552 | 243 @defopt abbrev-all-caps |
244 When this is set non-@code{nil}, an abbrev entered entirely in upper | |
245 case is expanded using all upper case. Otherwise, an abbrev entered | |
246 entirely in upper case is expanded by capitalizing each word of the | |
247 expansion. | |
248 @end defopt | |
249 | |
250 @defvar abbrev-start-location | |
251 This is the buffer position for @code{expand-abbrev} to use as the start | |
252 of the next abbrev to be expanded. (@code{nil} means use the word | |
253 before point instead.) @code{abbrev-start-location} is set to | |
254 @code{nil} each time @code{expand-abbrev} is called. This variable is | |
255 also set by @code{abbrev-prefix-mark}. | |
256 @end defvar | |
257 | |
258 @defvar abbrev-start-location-buffer | |
259 The value of this variable is the buffer for which | |
260 @code{abbrev-start-location} has been set. Trying to expand an abbrev | |
261 in any other buffer clears @code{abbrev-start-location}. This variable | |
262 is set by @code{abbrev-prefix-mark}. | |
263 @end defvar | |
264 | |
265 @defvar last-abbrev | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
266 This is the @code{abbrev-symbol} of the most recent abbrev expanded. This |
6552 | 267 information is left by @code{expand-abbrev} for the sake of the |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
268 @code{unexpand-abbrev} command (@pxref{Expanding Abbrevs,, Expanding |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
269 Abbrevs, emacs, The GNU Emacs Manual}). |
6552 | 270 @end defvar |
271 | |
272 @defvar last-abbrev-location | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
273 This is the location of the most recent abbrev expanded. This contains |
6552 | 274 information left by @code{expand-abbrev} for the sake of the |
275 @code{unexpand-abbrev} command. | |
276 @end defvar | |
277 | |
278 @defvar last-abbrev-text | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
279 This is the exact expansion text of the most recent abbrev expanded, |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
280 after case conversion (if any). Its value is @code{nil} if the abbrev |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
281 has already been unexpanded. This contains information left by |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7688
diff
changeset
|
282 @code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command. |
6552 | 283 @end defvar |
284 | |
285 @c Emacs 19 feature | |
286 @defvar pre-abbrev-expand-hook | |
287 This is a normal hook whose functions are executed, in sequence, just | |
288 before any expansion of an abbrev. @xref{Hooks}. Since it is a normal | |
289 hook, the hook functions receive no arguments. However, they can find | |
290 the abbrev to be expanded by looking in the buffer before point. | |
26192 | 291 Running the hook is the first thing that @code{expand-abbrev} does, and |
292 so a hook function can be used to change the current abbrev table before | |
293 abbrev lookup happens. | |
6552 | 294 @end defvar |
295 | |
296 The following sample code shows a simple use of | |
297 @code{pre-abbrev-expand-hook}. If the user terminates an abbrev with a | |
298 punctuation character, the hook function asks for confirmation. Thus, | |
299 this hook allows the user to decide whether to expand the abbrev, and | |
300 aborts expansion if it is not confirmed. | |
301 | |
302 @smallexample | |
303 (add-hook 'pre-abbrev-expand-hook 'query-if-not-space) | |
304 | |
305 ;; @r{This is the function invoked by @code{pre-abbrev-expand-hook}.} | |
306 | |
307 ;; @r{If the user terminated the abbrev with a space, the function does} | |
308 ;; @r{nothing (that is, it returns so that the abbrev can expand). If the} | |
309 ;; @r{user entered some other character, this function asks whether} | |
310 ;; @r{expansion should continue.} | |
311 | |
7688 | 312 ;; @r{If the user answers the prompt with @kbd{y}, the function returns} |
6552 | 313 ;; @r{@code{nil} (because of the @code{not} function), but that is} |
314 ;; @r{acceptable; the return value has no effect on expansion.} | |
315 | |
316 (defun query-if-not-space () | |
317 (if (/= ?\ (preceding-char)) | |
318 (if (not (y-or-n-p "Do you want to expand this abbrev? ")) | |
319 (error "Not expanding this abbrev")))) | |
320 @end smallexample | |
321 | |
322 @node Standard Abbrev Tables, , Abbrev Expansion, Abbrevs | |
323 @comment node-name, next, previous, up | |
324 @section Standard Abbrev Tables | |
325 | |
326 Here we list the variables that hold the abbrev tables for the | |
327 preloaded major modes of Emacs. | |
328 | |
329 @defvar global-abbrev-table | |
330 This is the abbrev table for mode-independent abbrevs. The abbrevs | |
331 defined in it apply to all buffers. Each buffer may also have a local | |
332 abbrev table, whose abbrev definitions take precedence over those in the | |
333 global table. | |
334 @end defvar | |
335 | |
336 @defvar local-abbrev-table | |
337 The value of this buffer-local variable is the (mode-specific) | |
338 abbreviation table of the current buffer. | |
339 @end defvar | |
340 | |
341 @defvar fundamental-mode-abbrev-table | |
7688 | 342 This is the local abbrev table used in Fundamental mode; in other words, |
343 it is the local abbrev table in all buffers in Fundamental mode. | |
6552 | 344 @end defvar |
345 | |
346 @defvar text-mode-abbrev-table | |
347 This is the local abbrev table used in Text mode. | |
348 @end defvar | |
349 | |
350 @defvar lisp-mode-abbrev-table | |
351 This is the local abbrev table used in Lisp mode and Emacs Lisp mode. | |
352 @end defvar | |
26192 | 353 |