Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 3: Getting Started with Emacs

Previous HourNext Hour

Sections in this Hour:

 

Modes


When you edit an HTML file, your way of working will be much different from the way you work when you write a C program. One could, in fact, develop two different editors, one for writing C programs and one for writing HTML documents. These two editors would present much duplicate work, because they'd have many similar functions. An alternative is to write one editor that can be customized in two different ways, one for writing HTML documents and one for writing C programs. This editor would have the advantage that you would be familiar with it; for example, you would have to learn only one way for searching. You might think that there exists only one way to do these things, but you are wrong. Look at some of your favorite applications and think about it.

The Emacs way of doing this is to offer major and minor editing modes for different files and programs. For example, one major mode exists for editing HTML files, and another for editing C programs. There are many different editing modes, such as cc-mode (for C and C++ programs), emacs-lisp-mode (for Emacs Lisp), and latex-mode (for LaTeX documents).

Major Modes

Exactly one major mode is enabled at a time for a given buffer. That is, the major mode is local for each buffer, and every buffer is always in a given major mode. The major mode might contain different configurations. Most of them include the following:

To enable a major mode, simply press M-x and type its name. You can specify which major mode should be loaded when a file is read, depending on the name of the file. This is done by configuring the variable auto-mode-alist (See Hour 22, "Learning Lisp Basics," for a description of this.)

To disable one major mode, you have to enable another one. If no major mode seems appropriate then you can enable the major mode called fundamental-mode, which is a major mode without any specialization.

Minor Modes

Emacs has taken the customization grouping one step farther and developed a concept called minor modes. A minor mode is a set of customization options or functions that makes Emacs behave in a certain way. Any number of minor modes can be enabled at a time (this includes zero). Some minor modes are local to buffers, while others affect all of Emacs. The following list contains a few examples of some of the minor modes in Emacs:

To enable or disable a minor mode, simply press M-x and type its name. Minor modes can also be turned on together with a major mode (that is, whenever the given major mode is loaded, the minor mode is loaded too). To learn how to do that, please refer to Hour 24, "Installing Emacs Add-Ons."

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 3: Getting Started with Emacs

Previous HourNext Hour

Sections in this Hour: