diff options
| author | Richard M. Stallman | 2003-07-14 15:59:12 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-07-14 15:59:12 +0000 |
| commit | fdba9ef4dad8548c41a1032b206f1d10cf1b0b6c (patch) | |
| tree | 7c7f3bca85e22db1ec839fde00318377318a510d | |
| parent | a1c0746110fd41e3edbe9f743147bc27727f3616 (diff) | |
| download | emacs-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.texi | 137 |
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 |
| 264 | Each major mode should have a @dfn{mode hook} named | 264 | Each 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 |
| 266 | hook, with @code{run-hooks}, as the very last thing it | 266 | hook, with @code{run-mode-hooks}, as the very last thing it |
| 267 | does. @xref{Hooks}. | 267 | does. @xref{Hooks}. |
| 268 | 268 | ||
| 269 | @item | 269 | @item |
| 270 | The major mode command may also run the hooks of some more basic modes. | 270 | The major mode command may start by calling some other major mode |
| 271 | For example, @code{indented-text-mode} runs @code{text-mode-hook} as | 271 | command (called the @dfn{parent mode}) and then alter some of its |
| 272 | well as @code{indented-text-mode-hook}. It may run these other hooks | 272 | settings. A mode that does this is called a @dfn{derived mode}. The |
| 273 | immediately before the mode's own hook (that is, after everything else), | 273 | recommended way to define one is to use @code{define-derived-mode}, |
| 274 | or it may run them earlier. | 274 | but this is not required. Such a mode should use |
| 275 | @code{delay-mode-hooks} around its entire body, including the call to | ||
| 276 | the 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 |
| 277 | If something special should be done if the user switches a buffer from | 280 | If 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. | |||
| 819 | way to insert the necessary hook into the rest of Emacs. Minor mode | 822 | way to insert the necessary hook into the rest of Emacs. Minor mode |
| 820 | keymaps make this easier than it used to be. | 823 | keymaps make this easier than it used to be. |
| 821 | 824 | ||
| 825 | @defvar minor-mode-list | ||
| 826 | The 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.) | |||
| 981 | implementing a mode in one self-contained definition. It supports only | 988 | implementing a mode in one self-contained definition. It supports only |
| 982 | buffer-local minor modes, not global ones. | 989 | buffer-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 |
| 986 | This macro defines a new minor mode whose name is @var{mode} (a symbol). | 993 | This macro defines a new minor mode whose name is @var{mode} (a |
| 987 | It defines a command named @var{mode} to toggle the minor | 994 | symbol). It defines a command named @var{mode} to toggle the minor |
| 988 | mode, with @var{doc} as its documentation string. It also defines a | 995 | mode, with @var{doc} as its documentation string. It also defines a |
| 989 | variable named @var{mode}, which is set to @code{t} or @code{nil} by | 996 | variable named @var{mode}, which is set to @code{t} or @code{nil} by |
| 990 | enabling or disabling the mode. The variable is initialized to | 997 | enabling or disabling the mode. The variable is initialized to |
| 991 | @var{init-value}. | 998 | @var{init-value}. |
| 992 | 999 | ||
| 993 | The command named @var{mode} finishes by executing the @var{body} forms, | 1000 | The string @var{lighter} says what to display in the mode line |
| 994 | if any, after it has performed the standard actions such as setting | ||
| 995 | the variable named @var{mode}. | ||
| 996 | |||
| 997 | The string @var{mode-indicator} says what to display in the mode line | ||
| 998 | when the mode is enabled; if it is @code{nil}, the mode is not displayed | 1001 | when the mode is enabled; if it is @code{nil}, the mode is not displayed |
| 999 | in the mode line. | 1002 | in 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 | |||
| 1012 | The @var{keyword-args} consist of keywords followed by corresponding | ||
| 1013 | values. A few keywords have special meanings: | ||
| 1014 | |||
| 1015 | @table @code | ||
| 1016 | @item :global @var{global} | ||
| 1017 | If non-@code{nil} specifies that the minor mode should be global. | ||
| 1018 | By default, minor modes are buffer-local. | ||
| 1019 | |||
| 1020 | @item :init-value @var{init-value} | ||
| 1021 | This is equivalent to specifying @var{init-value} positionally. | ||
| 1022 | |||
| 1023 | @item :lighter @var{lighter} | ||
| 1024 | This is equivalent to specifying @var{lighter} positionally. | ||
| 1025 | |||
| 1026 | @item :keymap @var{keymap} | ||
| 1027 | This is equivalent to specifying @var{keymap} positionally. | ||
| 1028 | @end table | ||
| 1029 | |||
| 1030 | Any other keyword arguments are passed passed directly to the | ||
| 1031 | @code{defcustom} generated for the variable @var{mode}. | ||
| 1032 | |||
| 1033 | The command named @var{mode} finishes by executing the @var{body} forms, | ||
| 1034 | if any, after it has performed the standard actions such as setting | ||
| 1035 | the 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 | ||
| 1040 | for 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 | |||
| 1037 | which indicates whether the mode is enabled, and a variable named | 1070 | which 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 |
| 1039 | mode is enabled. It initializes the keymap with key bindings for | 1072 | mode 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 |
| 1045 | for this macro. | 1081 | "Toggle Hungry mode. |
| 1082 | With no argument, this command toggles the mode. | ||
| 1083 | Non-null prefix argument turns on the mode. | ||
| 1084 | Null prefix argument turns off the mode. | ||
| 1085 | |||
| 1086 | When Hungry mode is enabled, the control delete key | ||
| 1087 | gobbles all preceding whitespace except the last. | ||
| 1088 | See 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 | ||
| 1944 | The value of @var{facename} is usually a face name (a symbol), but it | ||
| 1945 | can 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 | |||
| 1951 | to specify various text properties to put on the text that matches. | ||
| 1952 | If you do this, be sure to add the other text property names that you | ||
| 1953 | set in this way to the value of @code{font-lock-extra-managed-props} | ||
| 1954 | so that the properties will also be cleared out when they are no longer | ||
| 1955 | appropriate. | ||
| 1956 | |||
| 1888 | @item (@var{matcher} . @var{highlighter}) | 1957 | @item (@var{matcher} . @var{highlighter}) |
| 1889 | In this kind of element, @var{highlighter} is a list | 1958 | In this kind of element, @var{highlighter} is a list |
| 1890 | which specifies how to highlight matches found by @var{matcher}. | 1959 | which 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 | |||
| 2060 | textual modes. | 2129 | textual modes. |
| 2061 | @end defvar | 2130 | @end defvar |
| 2062 | 2131 | ||
| 2132 | @defvar font-lock-extra-managed-props | ||
| 2133 | Additional properties (other than @code{face}) that are being managed | ||
| 2134 | by Font Lock mode. Font Lock mode normally manages only the @code{face} | ||
| 2135 | property; if you want it to manage others as well, you must specify | ||
| 2136 | them in a @var{facename} in @code{font-lock-keywords} as well as adding | ||
| 2137 | them 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 |
| 2164 | Used (typically) for constant names. | 2241 | Used (typically) for constant names. |
| 2165 | 2242 | ||
| 2243 | @item font-locl-preprocessor-face | ||
| 2244 | @vindex font-locl-preprocessor-face | ||
| 2245 | Used (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 |
| 2168 | Used (typically) for constructs that are peculiar, or that greatly | 2249 | Used (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 | ||
| 2397 | Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks} | ||
| 2398 | macro. | ||
| 2399 | @end defun | ||
| 2400 | |||
| 2401 | @defmac delay-mode-hooks body... | ||
| 2402 | This macro executes the @var{body} forms but defers all calls to | ||
| 2403 | @code{run-mode-hooks} within them until the end of @var{body}. | ||
| 2404 | This macro enables a derived mode to arrange not to run | ||
| 2405 | its 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 |
| 2316 | This function is the way to run an abnormal hook which passes arguments | 2409 | This function is the way to run an abnormal hook which passes arguments |
| 2317 | to the hook functions. It calls each of the hook functions, passing | 2410 | to the hook functions. It calls each of the hook functions, passing |