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
.
The new command variant is defined to call the function parent, then override certain aspects of that parent mode:
variant-map
.
define-derived-mode
initializes this map to inherit from
parent-map
, if it is not already set.
variant-syntax-table
.
define-derived-mode
initializes this variable by copying
parent-syntax-table
, if it is not already set.
variant-abbrev-table
.
define-derived-mode
initializes this variable by copying
parent-abbrev-table
, if it is not already set.
variant-hook
,
which it runs in standard fashion as the very last thing that it does.
(The new mode also runs the mode hook of parent as part
of calling parent.)
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 variant-hook
.
The argument docstring specifies the documentation string for the
new mode. If you omit docstring, define-derived-mode
generates a documentation string.
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)
Go to the first, previous, next, last section, table of contents.