Mercurial > emacs
comparison man/abbrevs.texi @ 68696:b10a879044b0
Minor clarifications.
(Dabbrev Customization): Talk about "dynamic abbrev expansion",
not "dynamic abbrevs" as if they were a kind of abbrev.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 08 Feb 2006 00:07:17 +0000 |
parents | dc2d5a6655a3 |
children | 91970b147f39 c5406394f567 |
comparison
equal
deleted
inserted
replaced
68695:700063953be7 | 68696:b10a879044b0 |
---|---|
8 @cindex expansion (of abbrevs) | 8 @cindex expansion (of abbrevs) |
9 | 9 |
10 A defined @dfn{abbrev} is a word which @dfn{expands}, if you insert | 10 A defined @dfn{abbrev} is a word which @dfn{expands}, if you insert |
11 it, into some different text. Abbrevs are defined by the user to expand | 11 it, into some different text. Abbrevs are defined by the user to expand |
12 in specific ways. For example, you might define @samp{foo} as an abbrev | 12 in specific ways. For example, you might define @samp{foo} as an abbrev |
13 expanding to @samp{find outer otter}. Then you would be able to insert | 13 expanding to @samp{find outer otter}. Then you could insert |
14 @samp{find outer otter } into the buffer by typing @kbd{f o o | 14 @samp{find outer otter } into the buffer by typing @kbd{f o o |
15 @key{SPC}}. | 15 @key{SPC}}. |
16 | 16 |
17 A second kind of abbreviation facility is called @dfn{dynamic abbrev | 17 A second kind of abbreviation facility is called @dfn{dynamic abbrev |
18 expansion}. You use dynamic abbrev expansion with an explicit command | 18 expansion}. You use dynamic abbrev expansion with an explicit command |
19 to expand the letters in the buffer before point by looking for other | 19 to expand the letters in the buffer before point by looking for other |
20 words in the buffer that start with those letters. @xref{Dynamic | 20 words in the buffer that start with those letters. @xref{Dynamic |
21 Abbrevs}. | 21 Abbrevs}. |
22 | 22 |
23 ``Hippie'' expansion generalizes abbreviation expansion. @xref{Hippie | 23 ``Hippie'' expansion generalizes abbreviation expansion. |
24 Expand, , Hippie Expansion, autotype, Features for Automatic | 24 @xref{Hippie Expand, , Hippie Expansion, autotype, Features for |
25 Typing}. | 25 Automatic Typing}. |
26 | 26 |
27 @menu | 27 @menu |
28 * Abbrev Concepts:: Fundamentals of defined abbrevs. | 28 * Abbrev Concepts:: Fundamentals of defined abbrevs. |
29 * Defining Abbrevs:: Defining an abbrev, so it will expand when typed. | 29 * Defining Abbrevs:: Defining an abbrev, so it will expand when typed. |
30 * Expanding Abbrevs:: Controlling expansion: prefixes, canceling expansion. | 30 * Expanding Abbrevs:: Controlling expansion: prefixes, canceling expansion. |
55 turns Abbrev mode on if the argument is positive, off otherwise. | 55 turns Abbrev mode on if the argument is positive, off otherwise. |
56 @xref{Minor Modes}. @code{abbrev-mode} is also a variable; Abbrev mode is | 56 @xref{Minor Modes}. @code{abbrev-mode} is also a variable; Abbrev mode is |
57 on when the variable is non-@code{nil}. The variable @code{abbrev-mode} | 57 on when the variable is non-@code{nil}. The variable @code{abbrev-mode} |
58 automatically becomes local to the current buffer when it is set. | 58 automatically becomes local to the current buffer when it is set. |
59 | 59 |
60 Abbrev definitions can be @dfn{mode-specific}---active only in one major | 60 Abbrevs can have @dfn{mode-specific} definitions, active only in one major |
61 mode. Abbrevs can also have @dfn{global} definitions that are active in | 61 mode. Abbrevs can also have @dfn{global} definitions that are active in |
62 all major modes. The same abbrev can have a global definition and various | 62 all major modes. The same abbrev can have a global definition and various |
63 mode-specific definitions for different major modes. A mode-specific | 63 mode-specific definitions for different major modes. A mode-specific |
64 definition for the current major mode overrides a global definition. | 64 definition for the current major mode overrides a global definition. |
65 | 65 |
66 Abbrevs can be defined interactively during the editing session. Lists | 66 Yu can define abbrevs interactively during the editing session. You |
67 of abbrev definitions can also be saved in files and reloaded in later | 67 can also save lists of abbrev definitions in files for use in later |
68 sessions. Some users keep extensive lists of abbrevs that they load in | 68 sessions. Some users keep extensive lists of abbrevs that they load |
69 every session. | 69 in every session. |
70 | 70 |
71 @node Defining Abbrevs | 71 @node Defining Abbrevs |
72 @section Defining Abbrevs | 72 @section Defining Abbrevs |
73 | 73 |
74 @table @kbd | 74 @table @kbd |
86 @item M-x define-global-abbrev @key{RET} @var{abbrev} @key{RET} @var{exp} @key{RET} | 86 @item M-x define-global-abbrev @key{RET} @var{abbrev} @key{RET} @var{exp} @key{RET} |
87 Define @var{abbrev} as an abbrev expanding into @var{exp}. | 87 Define @var{abbrev} as an abbrev expanding into @var{exp}. |
88 @item M-x define-mode-abbrev @key{RET} @var{abbrev} @key{RET} @var{exp} @key{RET} | 88 @item M-x define-mode-abbrev @key{RET} @var{abbrev} @key{RET} @var{exp} @key{RET} |
89 Define @var{abbrev} as a mode-specific abbrev expanding into @var{exp}. | 89 Define @var{abbrev} as a mode-specific abbrev expanding into @var{exp}. |
90 @item M-x kill-all-abbrevs | 90 @item M-x kill-all-abbrevs |
91 This command discards all abbrev definitions currently in effect, | 91 Discard all abbrev definitions, leaving a blank slate. |
92 leaving a blank slate. | |
93 @end table | 92 @end table |
94 | 93 |
95 @kindex C-x a g | 94 @kindex C-x a g |
96 @findex add-global-abbrev | 95 @findex add-global-abbrev |
97 The usual way to define an abbrev is to enter the text you want the | 96 The usual way to define an abbrev is to enter the text you want the |
116 | 115 |
117 @kindex C-x a i g | 116 @kindex C-x a i g |
118 @findex inverse-add-global-abbrev | 117 @findex inverse-add-global-abbrev |
119 @kindex C-x a i l | 118 @kindex C-x a i l |
120 @findex inverse-add-mode-abbrev | 119 @findex inverse-add-mode-abbrev |
121 If the text already in the buffer is the abbrev, rather than its | 120 If the abbrev text itself is already in the buffer, you can use the |
122 expansion, use command @kbd{C-x a i g} | 121 commands @kbd{C-x a i g} (@code{inverse-add-global-abbrev}) and |
123 (@code{inverse-add-global-abbrev}) instead of @kbd{C-x a g}, or use | 122 @kbd{C-x a i l} (@code{inverse-add-mode-abbrev}) to define it as an |
124 @kbd{C-x a i l} (@code{inverse-add-mode-abbrev}) instead of @kbd{C-x a | 123 abbrev by specify the expansion in the minibuffer. These commands are |
125 l}. These commands are called ``inverse'' because they invert the | 124 called ``inverse'' because they invert the meaning of the two text |
126 meaning of the two text strings they use (one from the buffer and one | 125 strings they use (one from the buffer and one read with the |
127 read with the minibuffer). | 126 minibuffer). |
128 | 127 |
129 @findex define-mode-abbrev | 128 @findex define-mode-abbrev |
130 @findex define-global-abbrev | 129 @findex define-global-abbrev |
131 You can define an abbrev without inserting either the abbrev or its | 130 You can define an abbrev without inserting either the abbrev or its |
132 expansion in the buffer using the command @code{define-global-abbrev}. | 131 expansion in the buffer using the command @code{define-global-abbrev}. |
135 | 134 |
136 To change the definition of an abbrev, just define a new definition. | 135 To change the definition of an abbrev, just define a new definition. |
137 When the abbrev has a prior definition, the abbrev definition commands | 136 When the abbrev has a prior definition, the abbrev definition commands |
138 ask for confirmation before replacing it. | 137 ask for confirmation before replacing it. |
139 | 138 |
140 To remove an abbrev definition, give a negative argument to the abbrev | |
141 definition command: @kbd{C-u - C-x a g} or @kbd{C-u - C-x a l}. The | |
142 former removes a global definition, while the latter removes a | |
143 mode-specific definition. | |
144 | |
145 @findex kill-all-abbrevs | 139 @findex kill-all-abbrevs |
146 @kbd{M-x kill-all-abbrevs} removes all the abbrev definitions there | 140 To remove an abbrev definition, give a negative argument to the |
147 are, both global and local. | 141 abbrev definition command: @kbd{C-u - C-x a g} or @kbd{C-u - C-x a l}. |
142 The former removes a global definition, while the latter removes a | |
143 mode-specific definition. @kbd{M-x kill-all-abbrevs} removes all | |
144 abbrev definitions, both global and local. | |
148 | 145 |
149 @node Expanding Abbrevs | 146 @node Expanding Abbrevs |
150 @section Controlling Abbrev Expansion | 147 @section Controlling Abbrev Expansion |
151 | 148 |
152 An abbrev expands whenever it is present in the buffer just before | 149 An abbrev expands whenever it is present in the buffer just before |
177 Expand some or all abbrevs found in the region. | 174 Expand some or all abbrevs found in the region. |
178 @end table | 175 @end table |
179 | 176 |
180 @kindex M-' | 177 @kindex M-' |
181 @findex abbrev-prefix-mark | 178 @findex abbrev-prefix-mark |
182 You may wish to expand an abbrev with a prefix attached; for example, | 179 You may wish to expand an abbrev and attach a prefix to the expansion; |
183 if @samp{cnst} expands into @samp{construction}, you might want to use | 180 for example, if @samp{cnst} expands into @samp{construction}, you might want |
184 it to enter @samp{reconstruction}. It does not work to type | 181 to use it to enter @samp{reconstruction}. It does not work to type |
185 @kbd{recnst}, because that is not necessarily a defined abbrev. What | 182 @kbd{recnst}, because that is not necessarily a defined abbrev. What |
186 you can do is use the command @kbd{M-'} (@code{abbrev-prefix-mark}) in | 183 you can do is use the command @kbd{M-'} (@code{abbrev-prefix-mark}) in |
187 between the prefix @samp{re} and the abbrev @samp{cnst}. First, insert | 184 between the prefix @samp{re} and the abbrev @samp{cnst}. First, insert |
188 @samp{re}. Then type @kbd{M-'}; this inserts a hyphen in the buffer to | 185 @samp{re}. Then type @kbd{M-'}; this inserts a hyphen in the buffer to |
189 indicate that it has done its work. Then insert the abbrev @samp{cnst}; | 186 indicate that it has done its work. Then insert the abbrev @samp{cnst}; |
193 used. The result is the desired @samp{reconstruction}. | 190 used. The result is the desired @samp{reconstruction}. |
194 | 191 |
195 If you actually want the text of the abbrev in the buffer, rather than | 192 If you actually want the text of the abbrev in the buffer, rather than |
196 its expansion, you can accomplish this by inserting the following | 193 its expansion, you can accomplish this by inserting the following |
197 punctuation with @kbd{C-q}. Thus, @kbd{foo C-q ,} leaves @samp{foo,} in | 194 punctuation with @kbd{C-q}. Thus, @kbd{foo C-q ,} leaves @samp{foo,} in |
198 the buffer. | 195 the buffer, not expanding it. |
199 | 196 |
200 @findex unexpand-abbrev | 197 @findex unexpand-abbrev |
201 If you expand an abbrev by mistake, you can undo the expansion and | 198 If you expand an abbrev by mistake, you can undo the expansion and |
202 bring back the abbrev itself by typing @kbd{C-_} to undo (@pxref{Undo}). | 199 bring back the abbrev itself by typing @kbd{C-_} to undo (@pxref{Undo}). |
203 This also undoes the insertion of the non-word character that expanded | 200 This also undoes the insertion of the non-word character that expanded |
232 | 229 |
233 @findex list-abbrevs | 230 @findex list-abbrevs |
234 The output from @kbd{M-x list-abbrevs} looks like this: | 231 The output from @kbd{M-x list-abbrevs} looks like this: |
235 | 232 |
236 @example | 233 @example |
234 @var{various other tables@dots{}} | |
237 (lisp-mode-abbrev-table) | 235 (lisp-mode-abbrev-table) |
238 "dk" 0 "define-key" | 236 "dk" 0 "define-key" |
239 (global-abbrev-table) | 237 (global-abbrev-table) |
240 "dfn" 0 "definition" | 238 "dfn" 0 "definition" |
241 @end example | 239 @end example |
320 @findex define-abbrevs | 318 @findex define-abbrevs |
321 The commands @kbd{M-x insert-abbrevs} and @kbd{M-x define-abbrevs} are | 319 The commands @kbd{M-x insert-abbrevs} and @kbd{M-x define-abbrevs} are |
322 similar to the previous commands but work on text in an Emacs buffer. | 320 similar to the previous commands but work on text in an Emacs buffer. |
323 @kbd{M-x insert-abbrevs} inserts text into the current buffer after point, | 321 @kbd{M-x insert-abbrevs} inserts text into the current buffer after point, |
324 describing all current abbrev definitions; @kbd{M-x define-abbrevs} parses | 322 describing all current abbrev definitions; @kbd{M-x define-abbrevs} parses |
325 the entire current buffer and defines abbrevs accordingly.@refill | 323 the entire current buffer and defines abbrevs accordingly. |
326 | 324 |
327 @node Dynamic Abbrevs | 325 @node Dynamic Abbrevs |
328 @section Dynamic Abbrev Expansion | 326 @section Dynamic Abbrev Expansion |
329 | 327 |
330 The abbrev facility described above operates automatically as you insert | 328 The abbrev facility described above operates automatically as you |
331 text, but all abbrevs must be defined explicitly. By contrast, | 329 insert text, but all abbrevs must be defined explicitly. By contrast, |
332 @dfn{dynamic abbrevs} allow the meanings of abbrevs to be determined | 330 @dfn{dynamic abbrevs} allow the meanings of abbreviations to be |
333 automatically from the contents of the buffer, but dynamic abbrev expansion | 331 determined automatically from the contents of the buffer, but dynamic |
334 happens only when you request it explicitly. | 332 abbrev expansion happens only when you request it explicitly. |
335 | 333 |
336 @kindex M-/ | 334 @kindex M-/ |
337 @kindex C-M-/ | 335 @kindex C-M-/ |
338 @findex dabbrev-expand | 336 @findex dabbrev-expand |
339 @findex dabbrev-completion | 337 @findex dabbrev-completion |
355 argument to @kbd{M-/} says to take the second, third, etc.@: distinct | 353 argument to @kbd{M-/} says to take the second, third, etc.@: distinct |
356 expansion found looking backward from point. Repeating @kbd{M-/} | 354 expansion found looking backward from point. Repeating @kbd{M-/} |
357 searches for an alternative expansion by looking farther back. After | 355 searches for an alternative expansion by looking farther back. After |
358 scanning all the text before point, it searches the text after point. | 356 scanning all the text before point, it searches the text after point. |
359 The variable @code{dabbrev-limit}, if non-@code{nil}, specifies how far | 357 The variable @code{dabbrev-limit}, if non-@code{nil}, specifies how far |
360 in the buffer to search for an expansion. | 358 away in the buffer to search for an expansion. |
361 | 359 |
362 @vindex dabbrev-check-all-buffers | 360 @vindex dabbrev-check-all-buffers |
363 After scanning the current buffer, @kbd{M-/} normally searches other | 361 After scanning the current buffer, @kbd{M-/} normally searches other |
364 buffers, unless you have set @code{dabbrev-check-all-buffers} to | 362 buffers, unless you have set @code{dabbrev-check-all-buffers} to |
365 @code{nil}. | 363 @code{nil}. |
370 expressions. If a buffer's name matches any of these regular | 368 expressions. If a buffer's name matches any of these regular |
371 expressions, dynamic abbrev expansion skips that buffer. | 369 expressions, dynamic abbrev expansion skips that buffer. |
372 | 370 |
373 A negative argument to @kbd{M-/}, as in @kbd{C-u - M-/}, says to | 371 A negative argument to @kbd{M-/}, as in @kbd{C-u - M-/}, says to |
374 search first for expansions after point, then other buffers, and | 372 search first for expansions after point, then other buffers, and |
375 consider expansions before point only as a last resort. | 373 consider expansions before point only as a last resort. If you repeat |
376 | 374 the @kbd{M-/} to look for another expansion, do not specify an |
377 If you repeat the @kbd{M-/} to look for another expansion, do not | 375 argument. Repeating @kbd{M-/} cycles through all the expansions after |
378 specify an argument. This tries all the expansions after point and | 376 point and then the expansions before point. |
379 then the expansions before point. | |
380 | 377 |
381 After you have expanded a dynamic abbrev, you can copy additional | 378 After you have expanded a dynamic abbrev, you can copy additional |
382 words that follow the expansion in its original context. Simply type | 379 words that follow the expansion in its original context. Simply type |
383 @kbd{@key{SPC} M-/} for each word you want to copy. The spacing and | 380 @kbd{@key{SPC} M-/} for each additional word you want to copy. The |
384 punctuation between words is copied along with the words. | 381 spacing and punctuation between words is copied along with the words. |
385 | 382 |
386 The command @kbd{C-M-/} (@code{dabbrev-completion}) performs | 383 The command @kbd{C-M-/} (@code{dabbrev-completion}) performs |
387 completion of a dynamic abbreviation. Instead of trying the possible | 384 completion of a dynamic abbrev. Instead of trying the possible |
388 expansions one by one, it finds all of them, then inserts the text that | 385 expansions one by one, it finds all of them, then inserts the text |
389 they have in common. If they have nothing in common, @kbd{C-M-/} | 386 that they have in common. If they have nothing in common, @kbd{C-M-/} |
390 displays a list of completions, from which you can select a choice in | 387 displays a list of completions, from which you can select a choice in |
391 the usual manner. @xref{Completion}. | 388 the usual manner. @xref{Completion}. |
392 | 389 |
393 Dynamic abbrev expansion is completely independent of Abbrev mode; the | 390 Dynamic abbrev expansion is completely independent of Abbrev mode; the |
394 expansion of a word with @kbd{M-/} is completely independent of whether | 391 expansion of a word with @kbd{M-/} is completely independent of whether |
409 @code{case-fold-search}, which is true by default, then the variable | 406 @code{case-fold-search}, which is true by default, then the variable |
410 @code{case-fold-search} controls whether to ignore case while searching | 407 @code{case-fold-search} controls whether to ignore case while searching |
411 for expansions. | 408 for expansions. |
412 | 409 |
413 @vindex dabbrev-case-replace | 410 @vindex dabbrev-case-replace |
414 Normally, dynamic abbrev expansion preserves the case pattern @emph{of | 411 Normally, dynamic abbrev expansion preserves the case pattern |
415 the abbrev you have typed}, by converting the expansion to that case | 412 @emph{of the dynamic abbrev you are expanding}, by converting the |
416 pattern. | 413 expansion to that case pattern. |
417 | 414 |
418 @vindex dabbrev-case-fold-search | 415 @vindex dabbrev-case-fold-search |
419 The variable @code{dabbrev-case-replace} controls whether to preserve | 416 The variable @code{dabbrev-case-replace} controls whether to |
420 the case pattern of the abbrev. If it is @code{t}, the abbrev's case | 417 preserve the case pattern of the dynamic abbrev. If it is @code{t}, |
421 pattern is preserved in most cases; if it is @code{nil}, the expansion is | 418 the dynamic abbrev's case pattern is preserved in most cases; if it is |
422 always copied verbatim. If the value of @code{dabbrev-case-replace} is | 419 @code{nil}, the expansion is always copied verbatim. If the value of |
423 @code{case-replace}, which is true by default, then the variable | 420 @code{dabbrev-case-replace} is @code{case-replace}, which is true by |
424 @code{case-replace} controls whether to copy the expansion verbatim. | 421 default, then the variable @code{case-replace} controls whether to |
422 copy the expansion verbatim. | |
425 | 423 |
426 However, if the expansion contains a complex mixed case pattern, and | 424 However, if the expansion contains a complex mixed case pattern, and |
427 the abbrev matches this pattern as far as it goes, then the expansion is | 425 the dynamic abbrev matches this pattern as far as it goes, then the |
428 always copied verbatim, regardless of those variables. Thus, for | 426 expansion is always copied verbatim, regardless of those variables. |
429 example, if the buffer contains @code{variableWithSillyCasePattern}, and | 427 Thus, for example, if the buffer contains |
430 you type @kbd{v a M-/}, it copies the expansion verbatim including its | 428 @code{variableWithSillyCasePattern}, and you type @kbd{v a M-/}, it |
431 case pattern. | 429 copies the expansion verbatim including its case pattern. |
432 | 430 |
433 @vindex dabbrev-abbrev-char-regexp | 431 @vindex dabbrev-abbrev-char-regexp |
434 The variable @code{dabbrev-abbrev-char-regexp}, if non-@code{nil}, | 432 The variable @code{dabbrev-abbrev-char-regexp}, if non-@code{nil}, |
435 controls which characters are considered part of a word, for dynamic expansion | 433 controls which characters are considered part of a word, for dynamic expansion |
436 purposes. The regular expression must match just one character, never | 434 purposes. The regular expression must match just one character, never |
437 two or more. The same regular expression also determines which | 435 two or more. The same regular expression also determines which |
438 characters are part of an expansion. The value @code{nil} has a special | 436 characters are part of an expansion. The value @code{nil} has a special |
439 meaning: abbreviations are made of word characters, but expansions are | 437 meaning: dynamic abbrevs are made of word characters, but expansions are |
440 made of word and symbol characters. | 438 made of word and symbol characters. |
441 | 439 |
442 @vindex dabbrev-abbrev-skip-leading-regexp | 440 @vindex dabbrev-abbrev-skip-leading-regexp |
443 In shell scripts and makefiles, a variable name is sometimes prefixed | 441 In shell scripts and makefiles, a variable name is sometimes prefixed |
444 with @samp{$} and sometimes not. Major modes for this kind of text can | 442 with @samp{$} and sometimes not. Major modes for this kind of text can |
445 customize dynamic abbreviation to handle optional prefixes by setting | 443 customize dynamic abbrev expansion to handle optional prefixes by setting |
446 the variable @code{dabbrev-abbrev-skip-leading-regexp}. Its value | 444 the variable @code{dabbrev-abbrev-skip-leading-regexp}. Its value |
447 should be a regular expression that matches the optional prefix that | 445 should be a regular expression that matches the optional prefix that |
448 dynamic abbreviation should ignore. | 446 dynamic abbrev expression should ignore. |
449 | 447 |
450 @ignore | 448 @ignore |
451 arch-tag: 638e0079-9540-48ec-9166-414083e16445 | 449 arch-tag: 638e0079-9540-48ec-9166-414083e16445 |
452 @end ignore | 450 @end ignore |