[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [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. (Fundamental mode is an exception to many of these conventions, because its definition is to present the global state of Emacs.)
This list of conventions is only partial, because each major mode should aim for consistency in general with other Emacs major modes. This makes Emacs as a whole more coherent. It is impossible to list here all the possible points where this issue might come up; if the Emacs developers point out an area where your major mode deviates from the usual conventions, please make it compatible.
describe-mode
) in your
mode will display this string.
The documentation string may include the special documentation substrings, ‘\[command]’, ‘\{keymap}’, and ‘\<keymap>’, which enable the documentation to adapt automatically to the user's own key bindings. Voir la section Substituting Key Bindings in Documentation.
kill-all-local-variables
. This runs the normal hook
change-major-mode-hook
, then gets rid of the buffer-local variables
of the major mode previously in effect. Voir la section Creating and Deleting Buffer-Local Bindings.
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 string appears in the mode
line.
indent-line-function
to a suitable
function, and probably customize other variables for indentation.
use-local-map
to install this local map. Voir la section Active Keymaps,
for more information.
This keymap should be stored permanently in a global variable named
modename-mode-map
. Normally the library that defines the mode
sets this variable.
Voir la section Tips for Defining Variables Robustly, for advice about how to write the code to set up the mode's keymap variable.
A major mode can also rebind the keys M-n, M-p and M-s. The bindings for M-n and M-p should normally be some kind of “moving forward and backward,” but this does not necessarily mean cursor motion.
It is legitimate for a major mode to rebind a standard key sequence if it provides a command that does “the same job” in a way better suited to the text this mode is used for. For example, a major mode for editing a programming language might redefine C-M-a to “move to the beginning of a function” in a way that works better for that language.
It is also legitimate for a major mode to rebind a standard key sequence whose standard meaning is rarely useful in that mode. For instance, minibuffer modes rebind M-r, whose standard meaning is rarely of any use in the minibuffer. Major modes such as Dired or Rmail that do not allow self-insertion of text can reasonably redefine letters and other printing characters as special commands.
modename-mode-syntax-table
. @xref{Syntax Tables}.
modename-mode-abbrev-table
. If the major mode command
defines any abbrevs itself, it should pass t
for the
system-flag argument to define-abbrev
. @xref{Defining
Abbrevs}.
font-lock-defaults
(voir la section Font Lock Mode).
imenu-generic-expression
, for the two variables
imenu-prev-index-position-function
and
imenu-extract-index-name-function
, or for the variable
imenu-create-index-function
(voir la section Imenu).
eldoc-documentation-function
to tell ElDoc mode how to handle this mode.
defvar
or defcustom
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. Voir la section Buffer-Local Variables.
With rare exceptions, the only reasonable way to use
make-variable-buffer-local
in a Lisp package is for a variable which
is used only within that package. Using it on a variable used by other
packages would interfere with them.
modename-mode-hook
. The very last thing the major mode command
should do is to call run-mode-hooks
. This runs the mode hook, and
then runs the normal hook after-change-major-mode-hook
. Voir la section Mode Hooks.
define-derived-mode
, but this is not required.
Such a mode should call the parent mode command inside a
delay-mode-hooks
form. (Using define-derived-mode
does this
automatically.) Voir la section Defining Derived Modes, and Mode Hooks.
change-major-mode-hook
(voir la section Creating and Deleting Buffer-Local Bindings).
mode-class
with
value special
, put on as follows:
(put 'funny-mode 'mode-class 'special) |
This tells Emacs that new buffers created while the current buffer is in
Funny mode should not inherit Funny mode, in case default-major-mode
is nil
. Modes such as Dired, Rmail, and Buffer List use this
feature.
auto-mode-alist
to select the
mode for those file names (voir la section How Emacs Chooses a Major Mode). If you define the mode
command to autoload, you should add this element in the same file that calls
autoload
. If you use an autoload cookie for the mode command, you
can also use an autoload cookie for the form that adds the element
(voir autoload cookie). If you do not autoload the mode command, it is
sufficient to add the element in the file that contains the mode definition.
autoload
form and an example of how to add to auto-mode-alist
,
that users can include in their init files (voir la section The Init File, ‘.emacs’).
[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.