1 |
@c -*-texinfo-*- |
@c -*-texinfo-*- |
2 |
@c This is part of the GNU Emacs Lisp Reference Manual. |
@c This is part of the GNU Emacs Lisp Reference Manual. |
3 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
4 |
@c Free Software Foundation, Inc. |
@c Free Software Foundation, Inc. |
5 |
@c See the file elisp.texi for copying conditions. |
@c See the file elisp.texi for copying conditions. |
6 |
@setfilename ../info/modes |
@setfilename ../info/modes |
7 |
@node Modes, Documentation, Keymaps, Top |
@node Modes, Documentation, Keymaps, Top |
69 |
parent argument, since it automatically enforces the most important |
parent argument, since it automatically enforces the most important |
70 |
coding conventions for you. |
coding conventions for you. |
71 |
|
|
72 |
|
@findex define-generic-mode |
73 |
|
For a very simple programming language major mode that handles |
74 |
|
comments and fontification, you can use @code{define-generic-mode} |
75 |
|
in @file{generic.el}. |
76 |
|
|
77 |
Rmail Edit mode offers an example of changing the major mode |
Rmail Edit mode offers an example of changing the major mode |
78 |
temporarily for a buffer, so it can be edited in a different way (with |
temporarily for a buffer, so it can be edited in a different way (with |
79 |
ordinary Emacs commands rather than Rmail commands). In such cases, the |
ordinary Emacs commands rather than Rmail commands). In such cases, the |
99 |
* Example Major Modes:: Text mode and Lisp modes. |
* Example Major Modes:: Text mode and Lisp modes. |
100 |
* Auto Major Mode:: How Emacs chooses the major mode automatically. |
* Auto Major Mode:: How Emacs chooses the major mode automatically. |
101 |
* Mode Help:: Finding out how to use a mode. |
* Mode Help:: Finding out how to use a mode. |
102 |
* Derived Modes:: Defining a new major mode based on another major |
* Derived Modes:: Defining a new major mode based on another major |
103 |
mode. |
mode. |
104 |
@end menu |
@end menu |
105 |
|
|
253 |
would affect buffers that do not use this mode. It is undesirable for a |
would affect buffers that do not use this mode. It is undesirable for a |
254 |
mode to have such global effects. @xref{Buffer-Local Variables}. |
mode to have such global effects. @xref{Buffer-Local Variables}. |
255 |
|
|
256 |
With rare exceptions, the only reasonable way to use |
With rare exceptions, the only reasonable way to use |
257 |
@code{make-variable-buffer-local} in a Lisp package is for a variable |
@code{make-variable-buffer-local} in a Lisp package is for a variable |
258 |
which is used only within that package. Using it on a variable used by |
which is used only within that package. Using it on a variable used by |
259 |
other packages would interfere with them. |
other packages would interfere with them. |
324 |
@smallexample |
@smallexample |
325 |
@group |
@group |
326 |
;; @r{Create mode-specific tables.} |
;; @r{Create mode-specific tables.} |
327 |
(defvar text-mode-syntax-table nil |
(defvar text-mode-syntax-table nil |
328 |
"Syntax table used while in text mode.") |
"Syntax table used while in text mode.") |
329 |
@end group |
@end group |
330 |
|
|
403 |
@smallexample |
@smallexample |
404 |
@group |
@group |
405 |
;; @r{Create mode-specific table variables.} |
;; @r{Create mode-specific table variables.} |
406 |
(defvar lisp-mode-syntax-table nil "") |
(defvar lisp-mode-syntax-table nil "") |
407 |
(defvar emacs-lisp-mode-syntax-table nil "") |
(defvar emacs-lisp-mode-syntax-table nil "") |
408 |
(defvar lisp-mode-abbrev-table nil "") |
(defvar lisp-mode-abbrev-table nil "") |
409 |
@end group |
@end group |
419 |
;; @r{Set syntax of chars up to 0 to class of chars that are} |
;; @r{Set syntax of chars up to 0 to class of chars that are} |
420 |
;; @r{part of symbol names but not words.} |
;; @r{part of symbol names but not words.} |
421 |
;; @r{(The number 0 is @code{48} in the @sc{ascii} character set.)} |
;; @r{(The number 0 is @code{48} in the @sc{ascii} character set.)} |
422 |
(while (< i ?0) |
(while (< i ?0) |
423 |
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) |
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) |
424 |
(setq i (1+ i))) |
(setq i (1+ i))) |
425 |
@dots{} |
@dots{} |
513 |
@end smallexample |
@end smallexample |
514 |
|
|
515 |
Finally, here is the complete major mode function definition for |
Finally, here is the complete major mode function definition for |
516 |
Lisp mode. |
Lisp mode. |
517 |
|
|
518 |
@smallexample |
@smallexample |
519 |
@group |
@group |
601 |
How Major Modes are Chosen, emacs, The GNU Emacs Manual}. |
How Major Modes are Chosen, emacs, The GNU Emacs Manual}. |
602 |
@end defun |
@end defun |
603 |
|
|
604 |
@defopt default-major-mode |
@defopt default-major-mode |
605 |
This variable holds the default major mode for new buffers. The |
This variable holds the default major mode for new buffers. The |
606 |
standard value is @code{fundamental-mode}. |
standard value is @code{fundamental-mode}. |
607 |
|
|
649 |
@end group |
@end group |
650 |
@group |
@group |
651 |
("\\.el\\'" . emacs-lisp-mode) |
("\\.el\\'" . emacs-lisp-mode) |
652 |
("\\.c\\'" . c-mode) |
("\\.c\\'" . c-mode) |
653 |
("\\.h\\'" . c-mode) |
("\\.h\\'" . c-mode) |
654 |
@dots{}) |
@dots{}) |
655 |
@end group |
@end group |
675 |
@smallexample |
@smallexample |
676 |
@group |
@group |
677 |
(setq auto-mode-alist |
(setq auto-mode-alist |
678 |
(append |
(append |
679 |
;; @r{File name (within directory) starts with a dot.} |
;; @r{File name (within directory) starts with a dot.} |
680 |
'(("/\\.[^/]*\\'" . fundamental-mode) |
'(("/\\.[^/]*\\'" . fundamental-mode) |
681 |
;; @r{File name has no dot.} |
;; @r{File name has no dot.} |
682 |
("[^\\./]*\\'" . fundamental-mode) |
("[^\\./]*\\'" . fundamental-mode) |
683 |
;; @r{File name ends in @samp{.C}.} |
;; @r{File name ends in @samp{.C}.} |
684 |
("\\.C\\'" . c++-mode)) |
("\\.C\\'" . c++-mode)) |
685 |
auto-mode-alist)) |
auto-mode-alist)) |
742 |
The new command @var{variant} is defined to call the function |
The new command @var{variant} is defined to call the function |
743 |
@var{parent}, then override certain aspects of that parent mode: |
@var{parent}, then override certain aspects of that parent mode: |
744 |
|
|
745 |
@itemize @bullet |
@itemize @bullet |
746 |
@item |
@item |
747 |
The new mode has its own keymap, named @code{@var{variant}-map}. |
The new mode has its own keymap, named @code{@var{variant}-map}. |
748 |
@code{define-derived-mode} initializes this map to inherit from |
@code{define-derived-mode} initializes this map to inherit from |
751 |
@item |
@item |
752 |
The new mode has its own syntax table, kept in the variable |
The new mode has its own syntax table, kept in the variable |
753 |
@code{@var{variant}-syntax-table}. |
@code{@var{variant}-syntax-table}. |
754 |
@code{define-derived-mode} initializes this variable by copying |
@code{define-derived-mode} initializes this variable by copying |
755 |
@code{@var{parent}-syntax-table}, if it is not already set. |
@code{@var{parent}-syntax-table}, if it is not already set. |
756 |
|
|
757 |
@item |
@item |
758 |
The new mode has its own abbrev table, kept in the variable |
The new mode has its own abbrev table, kept in the variable |
759 |
@code{@var{variant}-abbrev-table}. |
@code{@var{variant}-abbrev-table}. |
760 |
@code{define-derived-mode} initializes this variable by copying |
@code{define-derived-mode} initializes this variable by copying |
761 |
@code{@var{parent}-abbrev-table}, if it is not already set. |
@code{@var{parent}-abbrev-table}, if it is not already set. |
762 |
|
|
763 |
@item |
@item |
764 |
The new mode has its own mode hook, @code{@var{variant}-hook}, |
The new mode has its own mode hook, @code{@var{variant}-hook}, |
765 |
which it runs in standard fashion as the very last thing that it does. |
which it runs in standard fashion as the very last thing that it does. |
766 |
(The new mode also runs the mode hook of @var{parent} as part |
(The new mode also runs the mode hook of @var{parent} as part |
767 |
of calling @var{parent}.) |
of calling @var{parent}.) |
768 |
@end itemize |
@end itemize |
769 |
|
|
770 |
In addition, you can specify how to override other aspects of |
In addition, you can specify how to override other aspects of |
771 |
@var{parent} with @var{body}. The command @var{variant} |
@var{parent} with @var{body}. The command @var{variant} |
772 |
evaluates the forms in @var{body} after setting up all its usual |
evaluates the forms in @var{body} after setting up all its usual |
773 |
overrides, just before running @code{@var{variant}-hook}. |
overrides, just before running @code{@var{variant}-hook}. |
774 |
|
|
775 |
The argument @var{docstring} specifies the documentation string for the |
The argument @var{docstring} specifies the documentation string for the |
1011 |
@smallexample |
@smallexample |
1012 |
(define-minor-mode hungry-mode |
(define-minor-mode hungry-mode |
1013 |
"Toggle Hungry mode. |
"Toggle Hungry mode. |
1014 |
With no argument, this command toggles the mode. |
With no argument, this command toggles the mode. |
1015 |
Non-null prefix argument turns on the mode. |
Non-null prefix argument turns on the mode. |
1016 |
Null prefix argument turns off the mode. |
Null prefix argument turns off the mode. |
1017 |
|
|
1025 |
;; The minor mode bindings. |
;; The minor mode bindings. |
1026 |
'(("\C-\^?" . hungry-electric-delete) |
'(("\C-\^?" . hungry-electric-delete) |
1027 |
("\C-\M-\^?" |
("\C-\M-\^?" |
1028 |
. (lambda () |
. (lambda () |
1029 |
(interactive) |
(interactive) |
1030 |
(hungry-electric-delete t))))) |
(hungry-electric-delete t))))) |
1031 |
@end smallexample |
@end smallexample |
1213 |
'mode-line-mule-info |
'mode-line-mule-info |
1214 |
'mode-line-modified |
'mode-line-modified |
1215 |
'mode-line-frame-identification |
'mode-line-frame-identification |
1216 |
"%b--" |
"%b--" |
1217 |
@end group |
@end group |
1218 |
@group |
@group |
1219 |
;; @r{Note that this is evaluated while making the list.} |
;; @r{Note that this is evaluated while making the list.} |
1220 |
;; @r{It makes a mode line construct which is just a string.} |
;; @r{It makes a mode line construct which is just a string.} |
1221 |
(getenv "HOST") |
(getenv "HOST") |
1222 |
@end group |
@end group |
1223 |
":" |
":" |
1224 |
'default-directory |
'default-directory |
1225 |
" " |
" " |
1226 |
'global-mode-string |
'global-mode-string |
1227 |
" %[(" |
" %[(" |
1228 |
'(:eval (mode-line-mode-name)) |
'(:eval (mode-line-mode-name)) |
1229 |
'mode-line-process |
'mode-line-process |
1230 |
'minor-mode-alist |
'minor-mode-alist |
1231 |
"%n" |
"%n" |
1232 |
")%]--" |
")%]--" |
1233 |
@group |
@group |
1234 |
'(which-func-mode ("" which-func-format "--")) |
'(which-func-mode ("" which-func-format "--")) |
1325 |
@group |
@group |
1326 |
minor-mode-alist |
minor-mode-alist |
1327 |
@result{} ((vc-mode vc-mode) |
@result{} ((vc-mode vc-mode) |
1328 |
(abbrev-mode " Abbrev") |
(abbrev-mode " Abbrev") |
1329 |
(overwrite-mode overwrite-mode) |
(overwrite-mode overwrite-mode) |
1330 |
(auto-fill-function " Fill") |
(auto-fill-function " Fill") |
1331 |
(defining-kbd-macro " Def") |
(defining-kbd-macro " Def") |
1332 |
(isearch-mode isearch-mode)) |
(isearch-mode isearch-mode)) |
1333 |
@end group |
@end group |
1386 |
;; @r{properties to make it mouse-sensitive.} |
;; @r{properties to make it mouse-sensitive.} |
1387 |
(:eval (mode-line-mode-name)) |
(:eval (mode-line-mode-name)) |
1388 |
mode-line-process |
mode-line-process |
1389 |
minor-mode-alist |
minor-mode-alist |
1390 |
"%n" |
"%n" |
1391 |
")%]--" |
")%]--" |
1392 |
@end group |
@end group |
1393 |
@group |
@group |
1671 |
If this variable is non-@code{nil}, its value should be a function that |
If this variable is non-@code{nil}, its value should be a function that |
1672 |
finds the next ``definition'' to put in the buffer index, scanning |
finds the next ``definition'' to put in the buffer index, scanning |
1673 |
backward in the buffer from point. It should return @code{nil} if it |
backward in the buffer from point. It should return @code{nil} if it |
1674 |
doesn't find another ``definition'' before point. Otherwise it shuould |
doesn't find another ``definition'' before point. Otherwise it should |
1675 |
leave point at the place it finds a ``definition,'' and return any |
leave point at the place it finds a ``definition,'' and return any |
1676 |
non-@code{nil} value. |
non-@code{nil} value. |
1677 |
|
|
2146 |
@item font-lock-function-name-face |
@item font-lock-function-name-face |
2147 |
@vindex font-lock-function-name-face |
@vindex font-lock-function-name-face |
2148 |
Used (typically) for the name of a function being defined or declared, |
Used (typically) for the name of a function being defined or declared, |
2149 |
in a function definition or declaration. |
in a function definition or declaration. |
2150 |
|
|
2151 |
@item font-lock-variable-name-face |
@item font-lock-variable-name-face |
2152 |
@vindex font-lock-variable-name-face |
@vindex font-lock-variable-name-face |