[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
It's often useful to define a new major mode in terms of an existing one.
An easy way to do this is to use define-derived-mode
.
This construct defines variant as a major mode command, using name as the string form of the mode name. variant and parent should be unquoted symbols.
The new command variant is defined to call the function parent, then override certain aspects of that parent mode:
variant-map
.
define-derived-mode
makes the parent mode's keymap the parent of the
new map, unless variant-map
is already set and already has a
parent.
variant-syntax-table
, unless you override this using the
:syntax-table
keyword (see below). define-derived-mode
makes
the parent mode's syntax-table the parent of
variant-syntax-table
, unless the latter is already set and
already has a parent different from the standard syntax table.
variant-abbrev-table
, unless you override this using the
:abbrev-table
keyword (see below).
variant-hook
. It runs this
hook, after running the hooks of its ancestor modes, with
run-mode-hooks
, as the last thing it does. Voir la section Mode Hooks.
In addition, you can specify how to override other aspects of parent with body. The command variant evaluates the forms in body after setting up all its usual overrides, just before running the mode hooks.
You can also specify nil
for parent. This gives the new mode
no parent. Then define-derived-mode
behaves as described above, but,
of course, omits all actions connected with parent.
The argument docstring specifies the documentation string for the new
mode. define-derived-mode
adds some general information about the
mode's hook, followed by the mode's keymap, at the end of this docstring.
If you omit docstring, define-derived-mode
generates a
documentation string.
The keyword-args are pairs of keywords and values. The values are evaluated. The following keywords are currently supported:
:syntax-table
You can use this to explicitly specify a syntax table for the new mode. If
you specify a nil
value, the new mode uses the same syntax table as
parent, or the standard syntax table if parent is nil
.
(Note that this does not follow the convention used for non-keyword
arguments that a nil
value is equivalent with not specifying the
argument.)
:abbrev-table
You can use this to explicitly specify an abbrev table for the new mode. If
you specify a nil
value, the new mode uses the same abbrev table as
parent, or fundamental-mode-abbrev-table
if parent is
nil
. (Again, a nil
value is not equivalent to not
specifying this keyword.)
:group
If this is specified, the value should be the customization group for this
mode. (Not all major modes have one.) Only the (still experimental and
unadvertised) command customize-mode
currently uses this.
define-derived-mode
does not automatically define the
specified customization group.
Here is a hypothetical example:
(define-derived-mode hypertext-mode text-mode "Hypertext" "Major mode for hypertext. \\{hypertext-mode-map}" (setq case-fold-search nil)) (define-key hypertext-mode-map [down-mouse-3] 'do-hyper-link) |
Do not write an interactive
spec in the definition;
define-derived-mode
does that automatically.
[ < ] | [ > ] | [ << ] | [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.