Emacs modes

From LQWiki
Jump to: navigation, search

Emacs modes are descriptions of how Emacs should behave. They come in two forms: major modes and minor modes. Only one major mode may be active at a time, and typically is used to describe the underlying nature of the current buffer. cperl-mode is an example of a major mode used for editing Perl code. Any number of minor modes may be active at a time, and are used to add extra functionality. font-lock-mode is an example of a minor mode which activates syntax highlighting.

Most modes (both major and minor) can be activated manually by invoking the function that bears their name. For example, auto-fill-mode can be started by typing "M-x auto-fill-mode". In addition, major modes can be set automatically depending on file extension through the auto-mode-alist variable. For example, prepending the dotted list ("\\.py$" . python-mode) to the auto-mode-alist variable will set the python-mode major mode when opening a file with a .py extension.

Major modes can be set on a per-file basis by placing the name of the requested mode between two "-*-" strings in the first line of the file. For example, if the first line of a file is "-*- latex -*-" then Emacs will use the Latex major mode for that file's buffer.