Modes

Neomacs use modes to provide functionalities to buffers. Neomacs modes are mixins, i.e. CLOS classes that can be dynamically added to buffers. A Neomacs buffer always inherit from zero or more modes and the buffer class.

Class: mode inherits (defaultable-class)
Metaclass for modes.
Slot: commands
Slot: keymap
Slot: lighter
String displayed in header to indicate this mode is enabled.
Slot: hooks
Other modes to enable or disable when enable or disabling this mode.

Mixins mostly supersede buffer-local variables and hooks used in previous editors like Emacs and Hemlock. Modes can have slots, which are introduced to the buffers that enable them. Methods that specialize on a mode customize behavior of generic functions on buffers. Many generic functions (e.g. on-*) in Neomacs has a buffer as the first argument, which is suitable for specializing on modes. Many ordinary functions in Neomacs has a backing generic function which has a buffer as first argument, usually with name *-aux.

Toggling modes

Function: enable (mode-name)
Enable the mode named by MODE-NAME in current buffer.
Function: disable (mode-name)
Disable the mode named by MODE-NAME in current buffer.
This also disables any modes that has MODE-NAME as super-mode.
Function: toggle (mode-name)
Toggle the mode named by MODE-NAME in current buffer.
This disables MODE-NAME either if it is enabled directly or via dependency (in which case all dependents are also disabled), and enables it otherwise.

Mode toggling hooks:

Standard generic function: enable-aux (mode-name)
Run after MODE-NAME is enabled.
This generic function is run with current-buffer bound to the buffer for which MODE-NAME is being enabled.
Standard generic function: disable-aux (mode-name previous-instance)
Run before MODE-NAME is disabled.
This generic function is run with current-buffer bound to the buffer for which MODE-NAME is being disabled.

Mode hooks

Standard generic function, setf-able: hooks (object)

Mode hooks and super-modes both allow enabling some other modes when a mode is enabled, which may be somewhat confusing. Suppose mode A has mode B in its hooks and mode C as its super-mode, note the differences:

Thefore, super-modes are best used for expressing dependencies between modes (e.g. minibuffer-completion-mode has minibuffer-mode as a super-mode), and mode hooks are best used for suggesting using some other modes together with a mode (e.g. prog-mode has undo-mode in its mode hooks by default).

Defining modes

Macro: define-mode (name super-modes slots &rest options)
Define a mode with NAME.
Like define-class besides supporting extra OPTIONS:
(:toggler TOGGLER-P): If TOGGLER-P is t, generate a toggler command with NAME.
(:lighter LIGHTER): Set the mode's lighter to LIGHTER.