home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 32.10 Inserting Binary Characters into Files Chapter 32
GNU Emacs
Next: 32.12 Getting Around Emacs Flow Control Problems
 

32.11 Using Word Abbreviation Mode

Like vi , Emacs provides an "abbreviation" facility. Its traditional usage lets you define abbreviations for long words or phrases so you don't have to type them in their entirety. For example, let's say you are writing a contract which repeatedly references the National Institute of Standards and Technology. Rather than typing the full name, you can define the abbreviation nist . Emacs inserts the full name whenever you type nist , followed by a space or punctuation mark. Emacs watches for you to type an abbreviation, then expands it automatically as soon as you press the space bar or type a punctuation mark (such as . , ! ? ; : ).

One use for word abbreviation mode is to correct misspellings as you type. Almost everyone has a dozen or so words that they habitually type incorrectly, due to some worn neural pathways. You can simply tell Emacs that these misspellings are "abbreviations" for the correct versions, and Emacs fixes the misspellings every time you type them. If you take time to define your common typos as abbreviations, you'll never have to be bothered with teh , adn , and recieve when you run the spellchecker. Emacs sweeps up behind your typos and corrects them. For example, let's say that you define teh as an abbreviation for the . When you press the space bar after you type teh , Emacs fixes it immediately while you continue happily typing. You may not even notice that you typed the word wrong before Emacs fixes it.

32.11.1 Trying Word Abbreviations for One Session

Usually, if you go to the trouble of defining a word abbreviation, you will use it in more than one Emacs session. But if you'd like to try out abbreviation mode to see if you want to make it part of your startup, you can use the following procedure.

To define word abbreviations for this session:

  1. Enter word abbreviation mode by typing ESC x abbrev-mode . abbrev appears on the mode line.

  2. Type the abbreviation you want to use and press CTRL-x a . Emacs then asks you for the expansion.

  3. Type the definition for the abbreviation and press RETURN. Emacs then expands the abbreviation and will do so each time you type it followed by a space or punctuation mark. The abbreviations you've defined will work only during this Emacs session.

If you find that you like using word abbreviation mode, you may want to make it part of your startup, as described in the following section.

32.11.2 Making Word Abbreviations Part of Your Startup

Once you become hooked on abbreviation mode, make it part of your .emacs file so that you enter abbreviation mode and load the file of your word abbreviations and their definitions automatically. To define word abbreviations and make them part of your startup:

  1. Add these lines to your .emacs file:

    (setq-default abbrev-mode t)
    (read-abbrev-file "~/.abbrev_defs")
    (setq save-abbrevs t)

  2. Save the .emacs file and reenter Emacs. Abbrev appears on the mode line. (You'll get an error at this point; ignore it - it won't happen again.)

  3. Type an abbreviation you want to use and then type CTRL-x a following the abbreviation. Emacs asks you for the expansion.

  4. Type the definition for the abbreviation and press RETURN. Emacs expands the abbreviation and will do so each time you type it followed by a space or punctuation mark. You can define as many abbreviations as you want to by repeating steps 3 and 4.

  5. Type ESC x write-abbrev-file to save your abbreviations file. Emacs asks for the filename.

  6. Type ~/.abbrev_defs . Emacs then writes the file. You need only take this step the first time you define abbreviations using this procedure. After this file exists, the lines in your .emacs file load the abbreviations file automatically.

After you've followed this procedure the first time, you only need to use steps 3 and 4 to define more abbreviations. When you add word abbreviations in subsequent sessions, Emacs asks whether you want to save the abbreviations file. Respond with a y to save the new abbreviations you've defined and have them take effect automatically.

If you define an abbreviation and later regret it, use edit-word-abbrevs to delete it.

- DC


Previous: 32.10 Inserting Binary Characters into Files UNIX Power Tools Next: 32.12 Getting Around Emacs Flow Control Problems
32.10 Inserting Binary Characters into Files Book Index 32.12 Getting Around Emacs Flow Control Problems

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System