Next: Example Major Modes, Previous: Major Modes, Up: Major Modes [Contents][Index]
The code for existing major modes follows various coding conventions, including conventions for local keymap and syntax table initialization, global names, and hooks. Please follow these conventions when you define a new major mode:
describe-mode
) in your mode will display this string.
The documentation string may include the special documentation substrings, ‘\[command]’, ‘\{keymap}’, and ‘\<keymap>’, that enable the documentation to adapt automatically to the user’s own key bindings. See Keys in Documentation.
kill-all-local-variables
. This is what gets rid of the local
variables of the major mode previously in effect.
major-mode
to the
major mode command symbol. This is how describe-mode
discovers
which documentation to print.
mode-name
to the
“pretty” name of the mode, as a string. This appears in the mode
line.
use-local-map
to install this local map.
See Active Keymaps, for more information.
This keymap should be kept in a global variable named
modename-mode-map
. Normally the library that defines the
mode sets this variable.
modename-mode-syntax-table
. See Syntax Tables.
modename-mode-abbrev-table
. See Abbrev Tables.
defvar
to set mode-related variables, so that they are not
reinitialized if they already have a value. (Such reinitialization
could discard customizations made by the user.)
make-local-variable
in the major mode command, not
make-variable-buffer-local
. The latter function would make the
variable local to every buffer in which it is subsequently set, which
would affect buffers that do not use this mode. It is undesirable for a
mode to have such global effects. See Buffer-Local Variables.
It’s ok to use make-variable-buffer-local
, if you wish, for a
variable used only within a single Lisp package.
modename-mode-hook
. The major mode command should run that
hook, with run-hooks
, as the very last thing it
does. See Hooks.
indented-text-mode
runs text-mode-hook
as
well as indented-text-mode-hook
. It may run these other hooks
immediately before the mode’s own hook (that is, after everything else),
or it may run them earlier.
define-derived-mode
,
but this is not required. Such a mode should use
delay-mode-hooks
around its entire body, including the call to
the parent mode command and the final call to run-mode-hooks
.
(Using define-derived-mode
does this automatically.)
change-major-mode-hook
.
mode-class
with value special
, put on as follows:
(put 'funny-mode 'mode-class 'special)
This tells SXEmacs that new buffers created while the current buffer has Funny mode should not inherit Funny mode. Modes such as Dired, Rmail, and Buffer List use this feature.
auto-mode-alist
to select
the mode for those file names. If you define the mode command to
autoload, you should add this element in the same file that calls
autoload
. Otherwise, it is sufficient to add the element in the
file that contains the mode definition. See Auto Major Mode.
autoload
form
and an example of how to add to auto-mode-alist
, that users can
include in their init.el files.
This normal hook is run by kill-all-local-variables
before it
does anything else. This gives major modes a way to arrange for
something special to be done if the user switches to a different major
mode. For best results, make this variable buffer-local, so that it
will disappear after doing its job and will not interfere with the
subsequent major mode. See Hooks.
Next: Example Major Modes, Previous: Major Modes, Up: Major Modes [Contents][Index]