aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2003-07-14 15:59:12 +0000
committerRichard M. Stallman2003-07-14 15:59:12 +0000
commitfdba9ef4dad8548c41a1032b206f1d10cf1b0b6c (patch)
tree7c7f3bca85e22db1ec839fde00318377318a510d
parenta1c0746110fd41e3edbe9f743147bc27727f3616 (diff)
downloademacs-fdba9ef4dad8548c41a1032b206f1d10cf1b0b6c.tar.gz
emacs-fdba9ef4dad8548c41a1032b206f1d10cf1b0b6c.zip
(Major Mode Conventions): Explain about run-mode-hooks and about derived modes.
(Minor Modes): Add minor-mode-list. (Defining Minor Modes): Keyword args for define-minor-mode. (Search-based Fontification): Explain managing other properties. (Other Font Lock Variables): Add font-lock-extra-managed-props. (Faces for Font Lock): Add font-locl-preprocessor-face. (Hooks): Add run-mode-hooks and delay-mode-hooks.
-rw-r--r--lispref/modes.texi137
1 files changed, 115 insertions, 22 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi
index 8870c8632bf..c8e2523a5cb 100644
--- a/lispref/modes.texi
+++ b/lispref/modes.texi
@@ -263,15 +263,18 @@ other packages would interfere with them.
263@cindex major mode hook 263@cindex major mode hook
264Each major mode should have a @dfn{mode hook} named 264Each major mode should have a @dfn{mode hook} named
265@code{@var{modename}-mode-hook}. The major mode command should run that 265@code{@var{modename}-mode-hook}. The major mode command should run that
266hook, with @code{run-hooks}, as the very last thing it 266hook, with @code{run-mode-hooks}, as the very last thing it
267does. @xref{Hooks}. 267does. @xref{Hooks}.
268 268
269@item 269@item
270The major mode command may also run the hooks of some more basic modes. 270The major mode command may start by calling some other major mode
271For example, @code{indented-text-mode} runs @code{text-mode-hook} as 271command (called the @dfn{parent mode}) and then alter some of its
272well as @code{indented-text-mode-hook}. It may run these other hooks 272settings. A mode that does this is called a @dfn{derived mode}. The
273immediately before the mode's own hook (that is, after everything else), 273recommended way to define one is to use @code{define-derived-mode},
274or it may run them earlier. 274but this is not required. Such a mode should use
275@code{delay-mode-hooks} around its entire body, including the call to
276the parent mode command and the final call to @code{run-mode-hooks}.
277(Using @code{define-derived-mode} does this automatically.)
275 278
276@item 279@item
277If something special should be done if the user switches a buffer from 280If something special should be done if the user switches a buffer from
@@ -359,7 +362,7 @@ inherit all the commands defined in this map.")
359@end group 362@end group
360@end smallexample 363@end smallexample
361 364
362 Here is the complete major mode function definition for Text mode: 365 This was formerly the complete major mode function definition for Text mode:
363 366
364@smallexample 367@smallexample
365@group 368@group
@@ -388,7 +391,7 @@ Turning on text-mode runs the hook `text-mode-hook'."
388@group 391@group
389 (setq mode-name "Text") 392 (setq mode-name "Text")
390 (setq major-mode 'text-mode) 393 (setq major-mode 'text-mode)
391 (run-hooks 'text-mode-hook)) ; @r{Finally, this permits the user to} 394 (run-mode-hooks 'text-mode-hook)) ; @r{Finally, this permits the user to}
392 ; @r{customize the mode with a hook.} 395 ; @r{customize the mode with a hook.}
393@end group 396@end group
394@end smallexample 397@end smallexample
@@ -543,7 +546,7 @@ if that value is non-nil."
543@group 546@group
544 (setq imenu-case-fold-search t) 547 (setq imenu-case-fold-search t)
545 (set-syntax-table lisp-mode-syntax-table) 548 (set-syntax-table lisp-mode-syntax-table)
546 (run-hooks 'lisp-mode-hook)) ; @r{This permits the user to use a} 549 (run-mode-hooks 'lisp-mode-hook)) ; @r{This permits the user to use a}
547 ; @r{hook to customize the mode.} 550 ; @r{hook to customize the mode.}
548@end group 551@end group
549@end smallexample 552@end smallexample
@@ -819,6 +822,10 @@ minor modes in effect.
819way to insert the necessary hook into the rest of Emacs. Minor mode 822way to insert the necessary hook into the rest of Emacs. Minor mode
820keymaps make this easier than it used to be. 823keymaps make this easier than it used to be.
821 824
825@defvar minor-mode-list
826The value of this variable is a list of all minor mode commands.
827@end defvar
828
822@menu 829@menu
823* Minor Mode Conventions:: Tips for writing a minor mode. 830* Minor Mode Conventions:: Tips for writing a minor mode.
824* Keymaps and Minor Modes:: How a minor mode can have its own keymap. 831* Keymaps and Minor Modes:: How a minor mode can have its own keymap.
@@ -981,20 +988,16 @@ characters are reserved for major modes.)
981implementing a mode in one self-contained definition. It supports only 988implementing a mode in one self-contained definition. It supports only
982buffer-local minor modes, not global ones. 989buffer-local minor modes, not global ones.
983 990
984@defmac define-minor-mode mode doc &optional init-value mode-indicator keymap body... 991@defmac define-minor-mode mode doc [init-value [lighter [keymap keyword-args... body...]]]
985@tindex define-minor-mode 992@tindex define-minor-mode
986This macro defines a new minor mode whose name is @var{mode} (a symbol). 993This macro defines a new minor mode whose name is @var{mode} (a
987It defines a command named @var{mode} to toggle the minor 994symbol). It defines a command named @var{mode} to toggle the minor
988mode, with @var{doc} as its documentation string. It also defines a 995mode, with @var{doc} as its documentation string. It also defines a
989variable named @var{mode}, which is set to @code{t} or @code{nil} by 996variable named @var{mode}, which is set to @code{t} or @code{nil} by
990enabling or disabling the mode. The variable is initialized to 997enabling or disabling the mode. The variable is initialized to
991@var{init-value}. 998@var{init-value}.
992 999
993The command named @var{mode} finishes by executing the @var{body} forms, 1000The string @var{lighter} says what to display in the mode line
994if any, after it has performed the standard actions such as setting
995the variable named @var{mode}.
996
997The string @var{mode-indicator} says what to display in the mode line
998when the mode is enabled; if it is @code{nil}, the mode is not displayed 1001when the mode is enabled; if it is @code{nil}, the mode is not displayed
999in the mode line. 1002in the mode line.
1000 1003
@@ -1005,8 +1008,37 @@ specifying bindings in this form:
1005@example 1008@example
1006(@var{key-sequence} . @var{definition}) 1009(@var{key-sequence} . @var{definition})
1007@end example 1010@end example
1011
1012The @var{keyword-args} consist of keywords followed by corresponding
1013values. A few keywords have special meanings:
1014
1015@table @code
1016@item :global @var{global}
1017If non-@code{nil} specifies that the minor mode should be global.
1018By default, minor modes are buffer-local.
1019
1020@item :init-value @var{init-value}
1021This is equivalent to specifying @var{init-value} positionally.
1022
1023@item :lighter @var{lighter}
1024This is equivalent to specifying @var{lighter} positionally.
1025
1026@item :keymap @var{keymap}
1027This is equivalent to specifying @var{keymap} positionally.
1028@end table
1029
1030Any other keyword arguments are passed passed directly to the
1031@code{defcustom} generated for the variable @var{mode}.
1032
1033The command named @var{mode} finishes by executing the @var{body} forms,
1034if any, after it has performed the standard actions such as setting
1035the variable named @var{mode}.
1008@end defmac 1036@end defmac
1009 1037
1038@findex easy-mmode-define-minor-mode
1039 The name @code{easy-mmode-define-minor-mode} is an alias
1040for this macro.
1041
1010 Here is an example of using @code{define-minor-mode}: 1042 Here is an example of using @code{define-minor-mode}:
1011 1043
1012@smallexample 1044@smallexample
@@ -1028,7 +1060,8 @@ See the command \\[hungry-electric-delete]."
1028 ("\C-\M-\^?" 1060 ("\C-\M-\^?"
1029 . (lambda () 1061 . (lambda ()
1030 (interactive) 1062 (interactive)
1031 (hungry-electric-delete t))))) 1063 (hungry-electric-delete t))))
1064 :group 'hunger)
1032@end smallexample 1065@end smallexample
1033 1066
1034@noindent 1067@noindent
@@ -1037,12 +1070,35 @@ This defines a minor mode named ``Hungry mode'', a command named
1037which indicates whether the mode is enabled, and a variable named 1070which indicates whether the mode is enabled, and a variable named
1038@code{hungry-mode-map} which holds the keymap that is active when the 1071@code{hungry-mode-map} which holds the keymap that is active when the
1039mode is enabled. It initializes the keymap with key bindings for 1072mode is enabled. It initializes the keymap with key bindings for
1040@kbd{C-@key{DEL}} and @kbd{C-M-@key{DEL}}. 1073@kbd{C-@key{DEL}} and @kbd{C-M-@key{DEL}}. It puts the variable
1074@code{hungry-mode} into custom group @code{hunger}. There are no
1075@var{body} forms---many minor modes don't need any.
1041 1076
1077 Here's an equivalent way to write it:
1042 1078
1043@findex easy-mmode-define-minor-mode 1079@smallexample
1044 The name @code{easy-mmode-define-minor-mode} is an alias 1080(define-minor-mode hungry-mode
1045for this macro. 1081 "Toggle Hungry mode.
1082With no argument, this command toggles the mode.
1083Non-null prefix argument turns on the mode.
1084Null prefix argument turns off the mode.
1085
1086When Hungry mode is enabled, the control delete key
1087gobbles all preceding whitespace except the last.
1088See the command \\[hungry-electric-delete]."
1089 ;; The initial value.
1090 :initial-value nil
1091 ;; The indicator for the mode line.
1092 :lighter " Hungry"
1093 ;; The minor mode bindings.
1094 :keymap
1095 '(("\C-\^?" . hungry-electric-delete)
1096 ("\C-\M-\^?"
1097 . (lambda ()
1098 (interactive)
1099 (hungry-electric-delete t))))
1100 :group 'hunger)
1101@end smallexample
1046 1102
1047@node Mode Line Format 1103@node Mode Line Format
1048@section Mode Line Format 1104@section Mode Line Format
@@ -1885,6 +1941,19 @@ specifies the face name to use for highlighting.
1885("fubar" . fubar-face) 1941("fubar" . fubar-face)
1886@end example 1942@end example
1887 1943
1944The value of @var{facename} is usually a face name (a symbol), but it
1945can also be a list of the form
1946
1947@example
1948(face @var{face} @var{prop1} @var{val1} @var{prop2} @var{val2}@dots{})
1949@end example
1950
1951to specify various text properties to put on the text that matches.
1952If you do this, be sure to add the other text property names that you
1953set in this way to the value of @code{font-lock-extra-managed-props}
1954so that the properties will also be cleared out when they are no longer
1955appropriate.
1956
1888@item (@var{matcher} . @var{highlighter}) 1957@item (@var{matcher} . @var{highlighter})
1889In this kind of element, @var{highlighter} is a list 1958In this kind of element, @var{highlighter} is a list
1890which specifies how to highlight matches found by @var{matcher}. 1959which specifies how to highlight matches found by @var{matcher}.
@@ -2060,6 +2129,14 @@ are @code{mark-defun} for programming modes or @code{mark-paragraph} for
2060textual modes. 2129textual modes.
2061@end defvar 2130@end defvar
2062 2131
2132@defvar font-lock-extra-managed-props
2133Additional properties (other than @code{face}) that are being managed
2134by Font Lock mode. Font Lock mode normally manages only the @code{face}
2135property; if you want it to manage others as well, you must specify
2136them in a @var{facename} in @code{font-lock-keywords} as well as adding
2137them to this list.
2138@end defvar
2139
2063@node Levels of Font Lock 2140@node Levels of Font Lock
2064@subsection Levels of Font Lock 2141@subsection Levels of Font Lock
2065 2142
@@ -2163,6 +2240,10 @@ where they are defined and where they are used.
2163@vindex font-lock-constant-face 2240@vindex font-lock-constant-face
2164Used (typically) for constant names. 2241Used (typically) for constant names.
2165 2242
2243@item font-locl-preprocessor-face
2244@vindex font-locl-preprocessor-face
2245Used (typically) for preprocessor commands.
2246
2166@item font-lock-warning-face 2247@item font-lock-warning-face
2167@vindex font-lock-warning-face 2248@vindex font-lock-warning-face
2168Used (typically) for constructs that are peculiar, or that greatly 2249Used (typically) for constructs that are peculiar, or that greatly
@@ -2312,6 +2393,18 @@ For example, here's how @code{emacs-lisp-mode} runs its mode hook:
2312@end example 2393@end example
2313@end defun 2394@end defun
2314 2395
2396@defun run-mode-hooks &rest hookvars
2397Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks}
2398macro.
2399@end defun
2400
2401@defmac delay-mode-hooks body...
2402This macro executes the @var{body} forms but defers all calls to
2403@code{run-mode-hooks} within them until the end of @var{body}.
2404This macro enables a derived mode to arrange not to run
2405its parent modes' mode hooks until the end.
2406@end defmac
2407
2315@defun run-hook-with-args hook &rest args 2408@defun run-hook-with-args hook &rest args
2316This function is the way to run an abnormal hook which passes arguments 2409This function is the way to run an abnormal hook which passes arguments
2317to the hook functions. It calls each of the hook functions, passing 2410to the hook functions. It calls each of the hook functions, passing