Mercurial > emacs
comparison doc/lispref/abbrevs.texi @ 103216:75e91d51c5f2
* abbrevs.texi (Abbrevs): Add xref to Creating Symbols when
obarrays are first mentioned. Define "system abbrev" more
prominently, and add it to the index.
(Abbrev Mode, Abbrev Tables, Defining Abbrevs, Abbrev Properties):
Copyedits.
(Abbrev Expansion): Document abbrev-insert.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Wed, 13 May 2009 01:26:47 +0000 |
parents | 133f2b03479e |
children | b269cabac20c |
comparison
equal
deleted
inserted
replaced
103215:bbd292613696 | 103216:75e91d51c5f2 |
---|---|
17 The set of abbrevs currently in effect is recorded in an @dfn{abbrev | 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 | 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 | 19 in the same major mode share one abbrev table. There is also a global |
20 abbrev table. Normally both are used. | 20 abbrev table. Normally both are used. |
21 | 21 |
22 An abbrev table is represented as an obarray containing a symbol for | 22 An abbrev table is represented as an obarray. @xref{Creating |
23 each abbreviation. The symbol's name is the abbreviation; its value | 23 Symbols}, for information about obarrays. Each abbreviation is |
24 is the expansion; its function definition is the hook function to do | 24 represented by a symbol in the obarray. The symbol's name is the |
25 the expansion (@pxref{Defining Abbrevs}); its property list cell | 25 abbreviation; its value is the expansion; its function definition is |
26 typically contains various additional properties such as the use | 26 the hook function for performing the expansion (@pxref{Defining |
27 count, the number of times the abbreviation has been expanded, or | 27 Abbrevs}); and its property list cell contains various additional |
28 whether the abbrev is a so-called ``system'' abbrev defined by a major | 28 properties, including the use count and the number of times the |
29 mode rather than by the user (@pxref{Abbrev Properties}). | 29 abbreviation has been expanded (@pxref{Abbrev Properties}). |
30 | 30 |
31 Because the symbols used for abbrevs are not interned in the usual | 31 @cindex system abbrev |
32 Certain abbrevs, called @dfn{system abbrevs}, are defined by a major | |
33 mode instead of the user. A system abbrev is identified by its | |
34 non-@code{nil} @code{:system} property (@pxref{Abbrev Properties}). | |
35 When abbrevs are saved to an abbrev file, system abbrevs are omitted. | |
36 @xref{Abbrev Files}. | |
37 | |
38 Because the symbols used for abbrevs are not interned in the usual | |
32 obarray, they will never appear as the result of reading a Lisp | 39 obarray, they will never appear as the result of reading a Lisp |
33 expression; in fact, normally they are never used except by the code | 40 expression; in fact, normally they are never used except by the code |
34 that handles abbrevs. Therefore, it is safe to use them in an | 41 that handles abbrevs. Therefore, it is safe to use them in an |
35 extremely nonstandard way. @xref{Creating Symbols}. | 42 extremely nonstandard way. |
36 | 43 |
37 For the user-level commands for abbrevs, see @ref{Abbrevs,, Abbrev | 44 For the user-level commands for abbrevs, see @ref{Abbrevs,, Abbrev |
38 Mode, emacs, The GNU Emacs Manual}. | 45 Mode, emacs, The GNU Emacs Manual}. |
39 | 46 |
40 @menu | 47 @menu |
52 | 59 |
53 @node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs | 60 @node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs |
54 @comment node-name, next, previous, up | 61 @comment node-name, next, previous, up |
55 @section Setting Up Abbrev Mode | 62 @section Setting Up Abbrev Mode |
56 | 63 |
57 Abbrev mode is a minor mode controlled by the value of the variable | 64 Abbrev mode is a minor mode controlled by the variable |
58 @code{abbrev-mode}. | 65 @code{abbrev-mode}. |
59 | 66 |
60 @defvar abbrev-mode | 67 @defvar abbrev-mode |
61 A non-@code{nil} value of this variable turns on the automatic expansion | 68 If this variable is non-@code{nil}, abbrevs are automatically expanded |
62 of abbrevs when their abbreviations are inserted into a buffer. | 69 in the buffer. If the value is @code{nil}, abbrevs may be defined, |
63 If the value is @code{nil}, abbrevs may be defined, but they are not | 70 but they are not expanded automatically. |
64 expanded automatically. | |
65 | 71 |
66 This variable automatically becomes buffer-local when set in any fashion. | 72 This variable automatically becomes buffer-local when set in any fashion. |
67 @end defvar | 73 @end defvar |
68 | 74 |
69 @defvar default-abbrev-mode | 75 @defvar default-abbrev-mode |
70 This is the value of @code{abbrev-mode} for buffers that do not override it. | 76 This is the value of @code{abbrev-mode} for buffers that do not |
71 This is the same as @code{(default-value 'abbrev-mode)}. | 77 override it. It is the same as @code{(default-value 'abbrev-mode)}. |
72 @end defvar | 78 @end defvar |
73 | 79 |
74 @node Abbrev Tables, Defining Abbrevs, Abbrev Mode, Abbrevs | 80 @node Abbrev Tables, Defining Abbrevs, Abbrev Mode, Abbrevs |
75 @section Abbrev Tables | 81 @section Abbrev Tables |
76 | 82 |
77 This section describes how to create and manipulate abbrev tables. | 83 This section describes how to create and manipulate abbrev tables. |
78 | 84 |
79 @defun make-abbrev-table &rest props | 85 @defun make-abbrev-table &rest props |
80 This function creates and returns a new, empty abbrev table---an obarray | 86 This function creates and returns a new, empty abbrev table---an |
81 containing no symbols. It is a vector filled with zeros. @var{props} | 87 obarray containing no symbols. It is a vector filled with zeros. |
82 is a property list that is applied to the new table | 88 @var{props} is a property list that is applied to the new table |
83 (@pxref{Abbrev Table Properties}). | 89 (@pxref{Abbrev Table Properties}). |
84 @end defun | 90 @end defun |
85 | 91 |
86 @defun abbrev-table-p table | 92 @defun abbrev-table-p object |
87 Return non-@code{nil} is @var{table} is an abbrev table. | 93 This function returns a non-@code{nil} value if @var{object} is an |
88 @end defun | 94 abbrev table. |
89 | 95 @end defun |
90 @defun clear-abbrev-table table | 96 |
91 This function undefines all the abbrevs in abbrev table @var{table}, | 97 @defun clear-abbrev-table abbrev-table |
92 leaving it empty. It always returns @code{nil}. | 98 This function undefines all the abbrevs in @var{abbrev-table}, leaving |
93 @end defun | 99 it empty. It always returns @code{nil}. |
94 | 100 @end defun |
95 @defun copy-abbrev-table table | 101 |
96 This function returns a copy of abbrev table @var{table}---a new | 102 @defun copy-abbrev-table abbrev-table |
97 abbrev table that contains the same abbrev definitions. The only | 103 This function returns a copy of @var{abbrev-table}---a new abbrev |
98 difference between @var{table} and the returned copy is that this | 104 table containing the same abbrev definitions. There is one difference |
99 function sets the property lists of all copied abbrevs to 0. | 105 between the contents of @var{abbrev-table} and the returned copy: all |
106 abbrevs in the latter have their property lists set to @code{nil}. | |
100 @end defun | 107 @end defun |
101 | 108 |
102 @defun define-abbrev-table tabname definitions &optional docstring &rest props | 109 @defun define-abbrev-table tabname definitions &optional docstring &rest props |
103 This function defines @var{tabname} (a symbol) as an abbrev table | 110 This function defines @var{tabname} (a symbol) as an abbrev table |
104 name, i.e., as a variable whose value is an abbrev table. It defines | 111 name, i.e., as a variable whose value is an abbrev table. It defines |
138 @end defun | 145 @end defun |
139 | 146 |
140 @node Defining Abbrevs, Abbrev Files, Abbrev Tables, Abbrevs | 147 @node Defining Abbrevs, Abbrev Files, Abbrev Tables, Abbrevs |
141 @comment node-name, next, previous, up | 148 @comment node-name, next, previous, up |
142 @section Defining Abbrevs | 149 @section Defining Abbrevs |
150 | |
143 @code{define-abbrev} is the low-level basic function for defining an | 151 @code{define-abbrev} is the low-level basic function for defining an |
144 abbrev in a specified abbrev table. When major modes predefine standard | 152 abbrev in an abbrev table. |
145 abbrevs, they should call @code{define-abbrev} and specify a @code{t} for | 153 |
146 the @code{:system} property. | 154 When a major mode defines a system abbrev, it should call |
147 Be aware that any saved non-``system'' abbrevs are | 155 @code{define-abbrev} and specify a @code{t} for the @code{:system} |
148 restored at startup, i.e. before some major modes are loaded. Major modes | 156 property. Be aware that any saved non-``system'' abbrevs are restored |
149 should therefore not assume that when they are first loaded their abbrev | 157 at startup, i.e. before some major modes are loaded. Therefore, major |
150 tables are empty. | 158 modes should not assume that their abbrev tables are empty when they |
151 | 159 are first loaded. |
152 @defun define-abbrev table name expansion &optional hook &rest props | 160 |
153 This function defines an abbrev named @var{name}, in @var{table}, to | 161 @defun define-abbrev abbrev-table name expansion &optional hook &rest props |
154 expand to @var{expansion} and call @var{hook}, with properties | 162 This function defines an abbrev named @var{name}, in |
155 @var{props} (@pxref{Abbrev Properties}). The return value is @var{name}. | 163 @var{abbrev-table}, to expand to @var{expansion} and call @var{hook}, |
156 The @code{:system} property in @var{props} is treated specially here: | 164 with properties @var{props} (@pxref{Abbrev Properties}). The return |
157 if it has the value @code{force}, then it will overwrite an existing | 165 value is @var{name}. The @code{:system} property in @var{props} is |
158 definition even for a non-``system'' abbrev of the same name. | 166 treated specially here: if it has the value @code{force}, then it will |
159 | 167 overwrite an existing definition even for a non-``system'' abbrev of |
160 The argument @var{name} should be a string. The argument | 168 the same name. |
161 @var{expansion} is normally the desired expansion (a string), or | 169 |
162 @code{nil} to undefine the abbrev. If it is anything but a string or | 170 @var{name} should be a string. The argument @var{expansion} is |
163 @code{nil}, then the abbreviation ``expands'' solely by running | 171 normally the desired expansion (a string), or @code{nil} to undefine |
164 @var{hook}. | 172 the abbrev. If it is anything but a string or @code{nil}, then the |
173 abbreviation ``expands'' solely by running @var{hook}. | |
165 | 174 |
166 The argument @var{hook} is a function or @code{nil}. If @var{hook} is | 175 The argument @var{hook} is a function or @code{nil}. If @var{hook} is |
167 non-@code{nil}, then it is called with no arguments after the abbrev is | 176 non-@code{nil}, then it is called with no arguments after the abbrev is |
168 replaced with @var{expansion}; point is located at the end of | 177 replaced with @var{expansion}; point is located at the end of |
169 @var{expansion} when @var{hook} is called. | 178 @var{expansion} when @var{hook} is called. |
175 expansion. If @var{hook} returns non-@code{nil} in this case, that | 184 expansion. If @var{hook} returns non-@code{nil} in this case, that |
176 inhibits insertion of the character. By contrast, if @var{hook} | 185 inhibits insertion of the character. By contrast, if @var{hook} |
177 returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as | 186 returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as |
178 if expansion had not really occurred. | 187 if expansion had not really occurred. |
179 | 188 |
180 Normally the function @code{define-abbrev} sets the variable | 189 Normally, @code{define-abbrev} sets the variable |
181 @code{abbrevs-changed} to @code{t}, if it actually changes the abbrev. | 190 @code{abbrevs-changed} to @code{t}, if it actually changes the abbrev. |
182 (This is so that some commands will offer to save the abbrevs.) It | 191 (This is so that some commands will offer to save the abbrevs.) It |
183 does not do this for a ``system'' abbrev, since those won't be saved | 192 does not do this for a system abbrev, since those aren't saved anyway. |
184 anyway. | |
185 @end defun | 193 @end defun |
186 | 194 |
187 @defopt only-global-abbrevs | 195 @defopt only-global-abbrevs |
188 If this variable is non-@code{nil}, it means that the user plans to use | 196 If this variable is non-@code{nil}, it means that the user plans to use |
189 global abbrevs only. This tells the commands that define mode-specific | 197 global abbrevs only. This tells the commands that define mode-specific |
227 @code{abbrev-file-name} specifies the file to save the abbrevs in. | 235 @code{abbrev-file-name} specifies the file to save the abbrevs in. |
228 @end defopt | 236 @end defopt |
229 | 237 |
230 @defvar abbrevs-changed | 238 @defvar abbrevs-changed |
231 This variable is set non-@code{nil} by defining or altering any | 239 This variable is set non-@code{nil} by defining or altering any |
232 abbrevs (except ``system'' abbrevs). This serves as a flag for | 240 abbrevs (except system abbrevs). This serves as a flag for various |
233 various Emacs commands to offer to save your abbrevs. | 241 Emacs commands to offer to save your abbrevs. |
234 @end defvar | 242 @end defvar |
235 | 243 |
236 @deffn Command write-abbrev-file &optional filename | 244 @deffn Command write-abbrev-file &optional filename |
237 Save all abbrev definitions (except ``system'' abbrevs), for all abbrev | 245 Save all abbrev definitions (except system abbrevs), for all abbrev |
238 tables listed in @code{abbrev-table-name-list}, in the file | 246 tables listed in @code{abbrev-table-name-list}, in the file |
239 @var{filename}, in the form of a Lisp program that when loaded will | 247 @var{filename}, in the form of a Lisp program that when loaded will |
240 define the same abbrevs. If @var{filename} is @code{nil} or omitted, | 248 define the same abbrevs. If @var{filename} is @code{nil} or omitted, |
241 @code{abbrev-file-name} is used. This function returns @code{nil}. | 249 @code{abbrev-file-name} is used. This function returns @code{nil}. |
242 @end deffn | 250 @end deffn |
252 | 260 |
253 @defun abbrev-symbol abbrev &optional table | 261 @defun abbrev-symbol abbrev &optional table |
254 This function returns the symbol representing the abbrev named | 262 This function returns the symbol representing the abbrev named |
255 @var{abbrev}. The value returned is @code{nil} if that abbrev is not | 263 @var{abbrev}. The value returned is @code{nil} if that abbrev is not |
256 defined. The optional second argument @var{table} is the abbrev table | 264 defined. The optional second argument @var{table} is the abbrev table |
257 to look it up in. If @var{table} is @code{nil}, this function tries | 265 in which to look it up. If @var{table} is @code{nil}, this function |
258 first the current buffer's local abbrev table, and second the global | 266 tries first the current buffer's local abbrev table, and second the |
259 abbrev table. | 267 global abbrev table. |
260 @end defun | 268 @end defun |
261 | 269 |
262 @defun abbrev-expansion abbrev &optional table | 270 @defun abbrev-expansion abbrev &optional table |
263 This function returns the string that @var{abbrev} would expand into (as | 271 This function returns the string that @var{abbrev} would expand into (as |
264 defined by the abbrev tables used for the current buffer). If | 272 defined by the abbrev tables used for the current buffer). If |
274 | 282 |
275 If the abbrev symbol has a hook function which is a symbol whose | 283 If the abbrev symbol has a hook function which is a symbol whose |
276 @code{no-self-insert} property is non-@code{nil}, and if the hook | 284 @code{no-self-insert} property is non-@code{nil}, and if the hook |
277 function returns @code{nil} as its value, then @code{expand-abbrev} | 285 function returns @code{nil} as its value, then @code{expand-abbrev} |
278 returns @code{nil} even though expansion did occur. | 286 returns @code{nil} even though expansion did occur. |
287 @end deffn | |
288 | |
289 @deffn abbrev-insert abbrev &optional name start end | |
290 This function inserts the abbrev expansion of @code{abbrev}, replacing | |
291 the text between @code{start} and @code{end}. If @code{start} is | |
292 omitted, it defaults to point. @code{name}, if non-@code{nil}, should | |
293 be the name by which this abbrev was found (a string); it is used to | |
294 figure out whether to adjust the capitalization of the expansion. The | |
295 function returns @code{abbrev} if the abbrev was successfully | |
296 inserted. | |
279 @end deffn | 297 @end deffn |
280 | 298 |
281 @deffn Command abbrev-prefix-mark &optional arg | 299 @deffn Command abbrev-prefix-mark &optional arg |
282 This command marks the current location of point as the beginning of | 300 This command marks the current location of point as the beginning of |
283 an abbrev. The next call to @code{expand-abbrev} will use the text | 301 an abbrev. The next call to @code{expand-abbrev} will use the text |
333 @code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command. | 351 @code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command. |
334 @end defvar | 352 @end defvar |
335 | 353 |
336 @defvar abbrev-expand-functions | 354 @defvar abbrev-expand-functions |
337 This is a special hook run @emph{around} the @code{expand-abbrev} | 355 This is a special hook run @emph{around} the @code{expand-abbrev} |
338 function. Functions on this hook are called with a single argument | 356 function. Each function on this hook is called with a single |
339 which is a function that performs the normal abbrev expansion. | 357 argument: a function that performs the normal abbrev expansion. The |
340 The hook function can hence do anything it wants before and after | 358 hook function can hence do anything it wants before and after |
341 performing the expansion. It can also choose not to call its argument | 359 performing the expansion. It can also choose not to call its |
342 and thus override the default behavior, or it may even call it | 360 argument, thus overriding the default behavior; or it may even call it |
343 several times. The function should return the abbrev symbol if | 361 several times. The function should return the abbrev symbol if |
344 expansion took place. | 362 expansion took place. |
345 @end defvar | 363 @end defvar |
346 | 364 |
347 The following sample code shows a simple use of | 365 The following sample code shows a simple use of |
413 @node Abbrev Properties, Abbrev Table Properties, Standard Abbrev Tables, Abbrevs | 431 @node Abbrev Properties, Abbrev Table Properties, Standard Abbrev Tables, Abbrevs |
414 @section Abbrev Properties | 432 @section Abbrev Properties |
415 | 433 |
416 Abbrevs have properties, some of which influence the way they work. | 434 Abbrevs have properties, some of which influence the way they work. |
417 You can provide them as arguments to @code{define-abbrev} and you can | 435 You can provide them as arguments to @code{define-abbrev} and you can |
418 manipulate them with the functions: | 436 manipulate them with the following functions: |
419 | 437 |
420 @defun abbrev-put abbrev prop val | 438 @defun abbrev-put abbrev prop val |
421 Set the property @var{prop} of abbrev @var{abbrev} to value @var{val}. | 439 Set the property @var{prop} of @var{abbrev} to value @var{val}. |
422 @end defun | 440 @end defun |
423 | 441 |
424 @defun abbrev-get abbrev prop | 442 @defun abbrev-get abbrev prop |
425 Return the property @var{prop} of abbrev @var{abbrev}, or @code{nil} | 443 Return the property @var{prop} of @var{abbrev}, or @code{nil} if the |
426 if the abbrev has no such property. | 444 abbrev has no such property. |
427 @end defun | 445 @end defun |
428 | 446 |
429 The following properties have special meaning: | 447 The following properties have special meanings: |
430 | 448 |
431 @table @code | 449 @table @code |
432 @item :count | 450 @item :count |
433 This property counts the number of times the abbrev has | 451 This property counts the number of times the abbrev has |
434 been expanded. If not explicitly set, it is initialized to 0 by | 452 been expanded. If not explicitly set, it is initialized to 0 by |
435 @code{define-abbrev}. | 453 @code{define-abbrev}. |
436 | 454 |
437 @item :system | 455 @item :system |
438 If non-@code{nil}, this property marks the abbrev as a ``system'' | 456 If non-@code{nil}, this property marks the abbrev as a system abbrev. |
439 abbrev. Such abbrevs will not be saved to @var{abbrev-file-name}. | 457 Such abbrevs are not saved (@pxref{Abbrev Files}). |
440 | 458 |
441 @item :enable-function | 459 @item :enable-function |
442 If non-@code{nil}, this property should be a function of no | 460 If non-@code{nil}, this property should be a function of no |
443 arguments which returns @code{nil} if the abbrev should not be used | 461 arguments which returns @code{nil} if the abbrev should not be used |
444 and @code{t} otherwise. | 462 and @code{t} otherwise. |