Книга: Learning GNU Emacs, 3rd Edition

1.3 A Word About Modes

1.3 A Word About Modes

Emacs achieves some of its famed versatility by having various editing modes in which it behaves slightly differently. The word mode may sound technical, but what it really means is that Emacs becomes sensitive to the task at hand. When you're writing, you often want features like word wrap so that you don't have to press Enter at the end of every line. When you're programming, the code must be formatted correctly depending on the language. For writing, there's text mode; for programming, there are modes for different languages, including C, Java, and Perl. Modes, then, allow Emacs to be the kind of editor you want for different tasks.

Text mode and Java mode are major modes. A buffer can be in only one major mode at a time; to exit a major mode, you have to enter another one. Table 1-1 lists some of the major modes, what they do, and where they're covered in this book.

Table 1-1. Major modes

Mode Function
Fundamental mode The default mode (Chapter 6)
Text mode For writing text (Chapter 2)
View mode For viewing files but not editing (Chapter 4)
Shell mode For running a shell within Emacs (Chapter 5)
Outline mode For writing outlines (Chapter 7)
Indented text mode For indenting text automatically (Chapter 7)
Paragraph indent text mode For indenting the first line of each paragraph (Chapter 7)
Picture mode For creating ASCII drawings using the keyboard (Chapter 7)
HTML mode For writing HTML (Chapter 8)
SGML mode For writing SGML and XML (Chapter 8)
LaTeX mode For formatting files for TEX and LATEX (Chapter 8)
Compilation mode For compiling programs (Chapter 9)
cc mode For writing C, C++, and Java programs (Chapter 9)
Java mode For writing Java programs (Chapter 9)
Perl mode and Cperl mode For writing Perl programs (Chapter 9)
SQL mode For interacting with databases using SQL (Chapter 9)
Emacs Lisp mode For writing Emacs Lisp functions (Chapter 9 and Chapter 11)
Lisp mode For writing Lisp programs (Chapter 9 and Chapter 11)
Lisp interaction mode For writing and evaluating Lisp expressions (Chapter 9 and Chapter 11)

Whenever you edit a file, Emacs attempts to put you into the correct major mode for what you're going to edit. If you edit a file that ends in .c, it puts you into cc mode. If you edit a file that ends in .el, it puts you in Lisp mode. Sometimes it looks at the contents of the file rather than just its name. If you edit a file formatted for TEX, Emacs puts you in LaTeX mode. If it cannot tell what mode you should be in, it puts you in fundamental mode, the most general of all. Because Emacs is extensible, add-in modes are also available; we talk about some in this book, though we do not list them in Table 1-1.

In addition to major modes there are also minor modes. These define a particular aspect of Emacs's behavior and can be turned on and off within a major mode. For example, auto-fill mode means that Emacs should do word wrap; when you type a long line, it should automatically make an appropriate line break. Table 1-2 lists some minor modes, what they do, and where they're covered in this book.

Table 1-2. Minor modes

Mode Function
Auto-fill mode Enables word wrap (Chapter 2).
Overwrite mode Replaces characters as you type instead of inserting them (Chapter 2).
Auto-save mode Saves your file automatically every so often in a special auto-save file (Chapter 2).
Isearch mode For searching (Chapter 3).
Flyspell mode For flyspell spell-checker (Chapter 3).
Flyspell prog mode For spell-checking programs with flyspell (Chapter 3).
Abbrev mode Allows you to use word abbreviations (Chapter 3).
Paragraph indent text mode For indenting the first line of each paragraph (Chapter 7).
Refill mode A mode in which Emacs attempts to fill paragraphs as you edit them (a bit experimental; mentioned in Chapter 2).
Artist mode For creating ASCII drawings using the mouse (Chapter 7).
Outline mode For writing outlines (Chapter 7).
SGML name entity mode For inserting special characters in HTML, SGML, and XML documents (Chapter 8).
ISO accents mode For inserting accented characters in text files.
Font lock mode For highlighting text in colors and fonts to improve readability (separating, for example, comments from code visually) (Chapter 9).
Compilation mode For compiling programs (Chapter 9).
Enriched mode For saving text attributes (Chapter 10).
VC mode For using various version control systems under Emacs (Chapter 12).
Info mode A mode for reading Emacs's own documentation (Chapter 14).

You may have noticed that several modes, including paragraph indent text mode, outline mode, and compilation mode, are both major and minor modes. Each can be used alone—as a major mode—or with another major mode as a minor mode.

There are many other modes that we won't discuss, including modes for some obscure but interesting programming languages (like Modula-2). There are also some other modes that Emacs uses itself, like Dired mode for the directory editing feature (described in Chapter 5).

In addition, if you're good at Lisp programming, you can add your own modes. Emacs is almost infinitely extensible.

Оглавление книги

Генерация: 0.721. Запросов К БД/Cache: 3 / 0
Вверх Вниз