Previous Section | Next Section | Table of Contents | Glossary | Index |
A mode is a collection of Hemlock values which may be present in the current environment depending on the editing task at hand. An example of a typical mode is Lisp, for editing Lisp code.
When a mode is added to or removed from a buffer, its mode hook is invoked. The hook functions take two arguments, the buffer involved and t if the mode is being added or nil if it is being removed. Mode hooks are typically used to make a mode do something additional to what it usually does. One might, for example, make a Text mode hook that turned on auto-fill mode when you entered.
There are two kinds of modes, major modes and minor modes. A buffer always has exactly one major mode, but it may have any number of minor modes. Major modes may have mode character attributes while minor modes may not.
A major mode is usually used to change the environment in some major way, such as to install special commands for editing some language. Minor modes generally change some small attribute of the environment, such as whether lines are automatically broken when they get too long. A minor mode should work regardless of what major mode and minor modes are in effect.
defmode name &key :setup-function :cleanup-function :major-p :precedence :transparent-p :documentation
This function defines a new mode named name, and enters it in *mode-names*. If major-p is supplied and is not nil then the mode is a major mode; otherwise it is a minor mode.
Setup-function and cleanup-function are functions which are invoked with the buffer affected, after the mode is turned on, and before it is turned off, respectively. These functions typically are used to make buffer-local key or variable bindings and to remove them when the mode is turned off.
Precedence is only meaningful for a minor mode. The precedence of a minor mode determines the order in which it in a buffer's list of modes. When searching for values in the current environment, minor modes are searched in order, so the precedence of a minor mode determines which value is found when there are several definitions.
Transparent-p determines whether key bindings local to the defined mode are transparent. Transparent key bindings are invoked in addition to the first normal key binding found rather than shadowing less local key bindings.
Documentation is some introductory text about the mode. Commands such as Describe Mode use this.
Previous Section | Next Section | Table of Contents | Glossary | Index |