Mercurial > emacs
comparison lispref/modes.texi @ 62539:14e404c9c65f
(Hooks): Delete confusing and unnecessary sentence.
(Major Mode Conventions): Refer to `Auto Major Mode' in more
appropriate place.
(Derived Modes): Small clarifications.
(Minor Mode Conventions, Keymaps and Minor Modes): Replace
references to nodes with references to anchors.
(Mode Line Data): Warn that `(:eval FORM)' should not load any files.
Clarify description of lists whose first element is an integer.
(Mode Line Variables): Add anchor.
(%-Constructs): Clarify description of integer after %.
(Emulating Mode Line): Describe nil value for FACE.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Thu, 19 May 2005 23:35:18 +0000 |
parents | 5d20851e7295 |
children | 47219b2b8b6f f042e7c0fe20 |
comparison
equal
deleted
inserted
replaced
62538:431e1a995da5 | 62539:14e404c9c65f |
---|---|
86 @example | 86 @example |
87 (add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill) | 87 (add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill) |
88 @end example | 88 @end example |
89 | 89 |
90 At the appropriate time, Emacs uses the @code{run-hooks} function to | 90 At the appropriate time, Emacs uses the @code{run-hooks} function to |
91 run particular hooks. This function calls the hook functions that have | 91 run particular hooks. |
92 been added with @code{add-hook}. | |
93 | 92 |
94 @defun run-hooks &rest hookvars | 93 @defun run-hooks &rest hookvars |
95 This function takes one or more normal hook variable names as | 94 This function takes one or more normal hook variable names as |
96 arguments, and runs each hook in turn. Each argument should be a | 95 arguments, and runs each hook in turn. Each argument should be a |
97 symbol that is a normal hook variable. These arguments are processed | 96 symbol that is a normal hook variable. These arguments are processed |
468 and Buffer List use this feature. | 467 and Buffer List use this feature. |
469 | 468 |
470 @item | 469 @item |
471 If you want to make the new mode the default for files with certain | 470 If you want to make the new mode the default for files with certain |
472 recognizable names, add an element to @code{auto-mode-alist} to select | 471 recognizable names, add an element to @code{auto-mode-alist} to select |
473 the mode for those file names. If you define the mode command to | 472 the mode for those file names (@pxref{Auto Major Mode}). If you |
474 autoload, you should add this element in the same file that calls | 473 define the mode command to autoload, you should add this element in |
475 @code{autoload}. If you use an autoload cookie for the mode command, | 474 the same file that calls @code{autoload}. If you use an autoload |
476 you can also use an autoload cookie for the form that adds the element | 475 cookie for the mode command, you can also use an autoload cookie for |
477 (@pxref{autoload cookie}). If you do not autoload the mode command, | 476 the form that adds the element (@pxref{autoload cookie}). If you do |
478 it is sufficient to add the element in the file that contains the mode | 477 not autoload the mode command, it is sufficient to add the element in |
479 definition. @xref{Auto Major Mode}. | 478 the file that contains the mode definition. |
480 | 479 |
481 @item | 480 @item |
482 In the comments that document the file, you should provide a sample | 481 In the comments that document the file, you should provide a sample |
483 @code{autoload} form and an example of how to add to | 482 @code{autoload} form and an example of how to add to |
484 @code{auto-mode-alist}, that users can include in their init files | 483 @code{auto-mode-alist}, that users can include in their init files |
1009 @code{:abbrev-table} keyword (see below). | 1008 @code{:abbrev-table} keyword (see below). |
1010 | 1009 |
1011 @item | 1010 @item |
1012 The new mode has its own mode hook, @code{@var{variant}-hook}. It | 1011 The new mode has its own mode hook, @code{@var{variant}-hook}. It |
1013 runs this hook, after running the hooks of its ancestor modes, with | 1012 runs this hook, after running the hooks of its ancestor modes, with |
1014 @code{run-mode-hooks} (@pxref{Mode Hooks}). | 1013 @code{run-mode-hooks}, as the last thing it does. @xref{Mode Hooks}. |
1015 @end itemize | 1014 @end itemize |
1016 | 1015 |
1017 In addition, you can specify how to override other aspects of | 1016 In addition, you can specify how to override other aspects of |
1018 @var{parent} with @var{body}. The command @var{variant} | 1017 @var{parent} with @var{body}. The command @var{variant} |
1019 evaluates the forms in @var{body} after setting up all its usual | 1018 evaluates the forms in @var{body} after setting up all its usual |
1020 overrides, just before running @code{@var{variant}-hook}. | 1019 overrides, just before running the mode hooks. |
1021 | 1020 |
1022 You can also specify @code{nil} for @var{parent}. This gives the new | 1021 You can also specify @code{nil} for @var{parent}. This gives the new |
1023 mode no parent. Then @code{define-derived-mode} behaves as described | 1022 mode no parent. Then @code{define-derived-mode} behaves as described |
1024 above, but, of course, omits all actions connected with @var{parent}. | 1023 above, but, of course, omits all actions connected with @var{parent}. |
1025 | 1024 |
1260 @end group | 1259 @end group |
1261 @end smallexample | 1260 @end smallexample |
1262 | 1261 |
1263 @item | 1262 @item |
1264 Add an element to @code{minor-mode-alist} for each minor mode | 1263 Add an element to @code{minor-mode-alist} for each minor mode |
1265 (@pxref{Mode Line Variables}), if you want to indicate the minor mode in | 1264 (@pxref{Definition of minor-mode-alist}), if you want to indicate the |
1266 the mode line. This element should be a list of the following form: | 1265 minor mode in the mode line. This element should be a list of the |
1266 following form: | |
1267 | 1267 |
1268 @smallexample | 1268 @smallexample |
1269 (@var{mode-variable} @var{string}) | 1269 (@var{mode-variable} @var{string}) |
1270 @end smallexample | 1270 @end smallexample |
1271 | 1271 |
1303 If just setting the variable is not sufficient to enable the mode, you | 1303 If just setting the variable is not sufficient to enable the mode, you |
1304 should also specify a @code{:set} method which enables the mode by | 1304 should also specify a @code{:set} method which enables the mode by |
1305 invoking the mode command. Note in the variable's documentation string that | 1305 invoking the mode command. Note in the variable's documentation string that |
1306 setting the variable other than via Custom may not take effect. | 1306 setting the variable other than via Custom may not take effect. |
1307 | 1307 |
1308 Also mark the definition with an autoload cookie (@pxref{Autoload}), | 1308 Also mark the definition with an autoload cookie (@pxref{autoload cookie}), |
1309 and specify a @code{:require} so that customizing the variable will load | 1309 and specify a @code{:require} so that customizing the variable will load |
1310 the library that defines the mode. This will copy suitable definitions | 1310 the library that defines the mode. This will copy suitable definitions |
1311 into @file{loaddefs.el} so that users can use @code{customize-option} to | 1311 into @file{loaddefs.el} so that users can use @code{customize-option} to |
1312 enable the mode. For example: | 1312 enable the mode. For example: |
1313 | 1313 |
1332 @node Keymaps and Minor Modes | 1332 @node Keymaps and Minor Modes |
1333 @subsection Keymaps and Minor Modes | 1333 @subsection Keymaps and Minor Modes |
1334 | 1334 |
1335 Each minor mode can have its own keymap, which is active when the mode | 1335 Each minor mode can have its own keymap, which is active when the mode |
1336 is enabled. To set up a keymap for a minor mode, add an element to the | 1336 is enabled. To set up a keymap for a minor mode, add an element to the |
1337 alist @code{minor-mode-map-alist}. @xref{Active Keymaps}. | 1337 alist @code{minor-mode-map-alist}. @xref{Definition of minor-mode-map-alist}. |
1338 | 1338 |
1339 @cindex @code{self-insert-command}, minor modes | 1339 @cindex @code{self-insert-command}, minor modes |
1340 One use of minor mode keymaps is to modify the behavior of certain | 1340 One use of minor mode keymaps is to modify the behavior of certain |
1341 self-inserting characters so that they do something else as well as | 1341 self-inserting characters so that they do something else as well as |
1342 self-insert. In general, this is the only way to do that, since the | 1342 self-insert. In general, this is the only way to do that, since the |
1626 elements recursively and concatenate the results. This is the most | 1626 elements recursively and concatenate the results. This is the most |
1627 common form of mode-line construct. | 1627 common form of mode-line construct. |
1628 | 1628 |
1629 @item (:eval @var{form}) | 1629 @item (:eval @var{form}) |
1630 A list whose first element is the symbol @code{:eval} says to evaluate | 1630 A list whose first element is the symbol @code{:eval} says to evaluate |
1631 @var{form}, and use the result as a string to display. | 1631 @var{form}, and use the result as a string to display. Make sure this |
1632 evaluation cannot load any files, as doing so could cause infinite | |
1633 recursion. | |
1632 | 1634 |
1633 @item (:propertize @var{elt} @var{props}@dots{}) | 1635 @item (:propertize @var{elt} @var{props}@dots{}) |
1634 A list whose first element is the symbol @code{:propertize} says to | 1636 A list whose first element is the symbol @code{:propertize} says to |
1635 process the mode-line construct @var{elt} recursively and add the text | 1637 process the mode-line construct @var{elt} recursively and add the text |
1636 properties specified by @var{props} to the result. The argument | 1638 properties specified by @var{props} to the result. The argument |
1648 | 1650 |
1649 @item (@var{width} @var{rest}@dots{}) | 1651 @item (@var{width} @var{rest}@dots{}) |
1650 A list whose first element is an integer specifies truncation or | 1652 A list whose first element is an integer specifies truncation or |
1651 padding of the results of @var{rest}. The remaining elements | 1653 padding of the results of @var{rest}. The remaining elements |
1652 @var{rest} are processed recursively as mode-line constructs and | 1654 @var{rest} are processed recursively as mode-line constructs and |
1653 concatenated together. Then the result is space filled (if | 1655 concatenated together. When @var{width} is positive, the result is |
1654 @var{width} is positive) or truncated (to @minus{}@var{width} columns, | 1656 space filled on the right if its width is less than @var{width}. When |
1655 if @var{width} is negative) on the right. | 1657 @var{width} is negative, the result is truncated on the right to |
1658 @minus{}@var{width} columns if its width exceeds @minus{}@var{width}. | |
1656 | 1659 |
1657 For example, the usual way to show what percentage of a buffer is above | 1660 For example, the usual way to show what percentage of a buffer is above |
1658 the top of the window is to use a list like this: @code{(-3 "%p")}. | 1661 the top of the window is to use a list like this: @code{(-3 "%p")}. |
1659 @end table | 1662 @end table |
1660 | 1663 |
1816 with the major mode as: @samp{(Shell:run)}. Normally this variable | 1819 with the major mode as: @samp{(Shell:run)}. Normally this variable |
1817 is @code{nil}. | 1820 is @code{nil}. |
1818 @end defvar | 1821 @end defvar |
1819 | 1822 |
1820 @defvar minor-mode-alist | 1823 @defvar minor-mode-alist |
1824 @anchor{Definition of minor-mode-alist} | |
1821 This variable holds an association list whose elements specify how the | 1825 This variable holds an association list whose elements specify how the |
1822 mode line should indicate that a minor mode is active. Each element of | 1826 mode line should indicate that a minor mode is active. Each element of |
1823 the @code{minor-mode-alist} should be a two-element list: | 1827 the @code{minor-mode-alist} should be a two-element list: |
1824 | 1828 |
1825 @example | 1829 @example |
1887 @node %-Constructs | 1891 @node %-Constructs |
1888 @subsection @code{%}-Constructs in the Mode Line | 1892 @subsection @code{%}-Constructs in the Mode Line |
1889 | 1893 |
1890 The following table lists the recognized @code{%}-constructs and what | 1894 The following table lists the recognized @code{%}-constructs and what |
1891 they mean. In any construct except @samp{%%}, you can add a decimal | 1895 they mean. In any construct except @samp{%%}, you can add a decimal |
1892 integer after the @samp{%} to specify how many characters to display. | 1896 integer after the @samp{%} to specify a minimum field width. If the |
1897 width is less, the field is padded with spaces to the right. | |
1893 | 1898 |
1894 @table @code | 1899 @table @code |
1895 @item %b | 1900 @item %b |
1896 The current buffer name, obtained with the @code{buffer-name} function. | 1901 The current buffer name, obtained with the @code{buffer-name} function. |
1897 @xref{Buffer Names}. | 1902 @xref{Buffer Names}. |
1992 @subsection Properties in the Mode Line | 1997 @subsection Properties in the Mode Line |
1993 @cindex text properties in the mode line | 1998 @cindex text properties in the mode line |
1994 | 1999 |
1995 Certain text properties are meaningful in the | 2000 Certain text properties are meaningful in the |
1996 mode line. The @code{face} property affects the appearance of text; the | 2001 mode line. The @code{face} property affects the appearance of text; the |
1997 @code{help-echo} property associate help strings with the text, and | 2002 @code{help-echo} property associates help strings with the text, and |
1998 @code{local-map} can make the text mouse-sensitive. | 2003 @code{local-map} can make the text mouse-sensitive. |
1999 | 2004 |
2000 There are four ways to specify text properties for text in the mode | 2005 There are four ways to specify text properties for text in the mode |
2001 line: | 2006 line: |
2002 | 2007 |
2060 @node Emulating Mode Line | 2065 @node Emulating Mode Line |
2061 @subsection Emulating Mode-Line Formatting | 2066 @subsection Emulating Mode-Line Formatting |
2062 | 2067 |
2063 You can use the function @code{format-mode-line} to compute | 2068 You can use the function @code{format-mode-line} to compute |
2064 the text that would appear in a mode line or header line | 2069 the text that would appear in a mode line or header line |
2065 based on certain mode-line specification. | 2070 based on a certain mode-line specification. |
2066 | 2071 |
2067 @defun format-mode-line format &optional face window buffer | 2072 @defun format-mode-line format &optional face window buffer |
2068 This function formats a line of text according to @var{format} as if | 2073 This function formats a line of text according to @var{format} as if |
2069 it were generating the mode line for @var{window}, but instead of | 2074 it were generating the mode line for @var{window}, but instead of |
2070 displaying the text in the mode line or the header line, it returns | 2075 displaying the text in the mode line or the header line, it returns |
2076 The value string normally has text properties that correspond to the | 2081 The value string normally has text properties that correspond to the |
2077 faces, keymaps, etc., that the mode line would have. And any character | 2082 faces, keymaps, etc., that the mode line would have. And any character |
2078 for which no @code{face} property is specified gets a default | 2083 for which no @code{face} property is specified gets a default |
2079 value which is usually @var{face}. (If @var{face} is @code{t}, | 2084 value which is usually @var{face}. (If @var{face} is @code{t}, |
2080 that stands for either @code{mode-line} if @var{window} is selected, | 2085 that stands for either @code{mode-line} if @var{window} is selected, |
2081 otherwise @code{mode-line-inactive}.) | 2086 otherwise @code{mode-line-inactive}. If @var{face} is @code{nil} or |
2087 omitted, that stands for no face property.) | |
2082 | 2088 |
2083 However, if @var{face} is an integer, the value has no text properties. | 2089 However, if @var{face} is an integer, the value has no text properties. |
2084 | 2090 |
2085 For example, @code{(format-mode-line header-line-format)} returns the | 2091 For example, @code{(format-mode-line header-line-format)} returns the |
2086 text that would appear in the selected window's header line (@code{""} | 2092 text that would appear in the selected window's header line (@code{""} |