Modes

Emacs uses the concept of a mode to encapsulate a set of editing behaviors. In other words, Emacs behaves differently in buffers with different modes. To take a small example, while the TAB key inserts an ASCII tab character in Text mode, in Emacs Lisp mode it inserts or deletes enough whitespace to indent a line of code to the correct column. As another example, when you invoke the command indent-for-comment in an Emacs Lisp mode buffer, you get an empty comment beginning with the Lisp comment character, ;. When you invoke it in a C mode buffer, you get an empty comment using C comment syntax: /* */.

Every buffer in Emacs is always in exactly one major mode. A major mode specializes a buffer for a particular kind of editing such as Text, Lisp, or C. A major mode called Fundamental isn't specialized for anything in particular and can be thought of as sort of a null mode. Usually the major mode for a buffer is chosen automatically by the name of the file you visit, or by some cues in the buffer itself. You can change major modes by invoking a mode's command, such as text-mode, emacs-lisp-mode, or c-mode.[27] When you do so, the buffer is in the new major mode and is no longer in the old major mode.

A minor mode, by contrast, adds to a buffer a package of functionality that doesn't fundamentally change the way editing in the buffer is performed. Minor modes can be turned on and off independently of the major mode and of each other. A buffer can be in zero, one, two, three, or ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.