Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 11: Editing Utilities |
|||||||||||||||||
|
Sometimes you type a word over and over again in a document. In the previous section, you saw how to define an abbreviation which might expand to difficult-to-type text. There are, however, situations where you do not want to define an abbreviation for a word, due to the fact that it'll take you some time to define it, and you might not know how many times you have to type this word. You might even be in a situation where you know that you have typed the word before, but you are not sure that you will type it again.
In these situation, you want Emacs to complete the word from a word earlier in the document. For this purpose dynamic abbreviations exist. Simply type part of the word and press M-/ (dabbrev-expand). Emacs then searches all your buffers for a word to complete to.
A much more powerful function called hippie-expand exists. This function expands almost anything. This includes Lisp function names, filenames from the hard disk, and text from the buffer. To use it, bind it to a key. To bind hippie-expand to meta-space, insert the following into your .emacs file :
(global-set-key "\M- " 'hippie-expand)
Now type part of a word, a filename, or a Lisp function-name, and press meta-space. If you are not happy about what it finds for you, ask it to continue its search for a completion by pressing meta-space one more time.
hippie-expand tries several different possibilities to find a piece of text that matches your need. Which expansions these are and the order in which they are tried can be seen in Table 11.1.
The expansions are implemented as Lisp functions so that a user can add an extra one in case he or she needs another expansion. This is the reason for the description of this as try-functions.
The order in which expansions are tried can be customized by setting the variable hippie-expand-try-functions-list. Simply insert the following into your .emacs file. Order the functions the way you like, with new ones added or some removed:
(setq hippie-expand-try-functions-list '(try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-lisp-symbol-partially try-complete-lisp-symbol))
Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 11: Editing Utilities |
|||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.