diff options
| author | Richard M. Stallman | 1994-05-01 19:27:09 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-05-01 19:27:09 +0000 |
| commit | de9f0bd94f691d90c98b0d703f58f9036fdcd40e (patch) | |
| tree | a826c385b1c28a826bd804a4927bec96c8bb7bd5 | |
| parent | 87b2d5ff029e93b27ab4887608788fd3d2b8c7e7 (diff) | |
| download | emacs-de9f0bd94f691d90c98b0d703f58f9036fdcd40e.tar.gz emacs-de9f0bd94f691d90c98b0d703f58f9036fdcd40e.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/modes.texi | 175 |
1 files changed, 97 insertions, 78 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi index c15ca5a9cd0..69649c4b665 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -99,7 +99,7 @@ should set up the keymap, syntax table, and local variables in an | |||
| 99 | existing buffer without changing the buffer's text. | 99 | existing buffer without changing the buffer's text. |
| 100 | 100 | ||
| 101 | @item | 101 | @item |
| 102 | Write a documentation string for this command which describes the | 102 | Write a documentation string for this command that describes the |
| 103 | special commands available in this mode. @kbd{C-h m} | 103 | special commands available in this mode. @kbd{C-h m} |
| 104 | (@code{describe-mode}) in your mode will display this string. | 104 | (@code{describe-mode}) in your mode will display this string. |
| 105 | 105 | ||
| @@ -140,16 +140,13 @@ should call @code{use-local-map} to install this local map. | |||
| 140 | 140 | ||
| 141 | This keymap should be kept in a global variable named | 141 | This keymap should be kept in a global variable named |
| 142 | @code{@var{modename}-mode-map}. Normally the library that defines the | 142 | @code{@var{modename}-mode-map}. Normally the library that defines the |
| 143 | mode sets this variable. Use @code{defvar} to set the variable, so that | 143 | mode sets this variable. |
| 144 | it is not reinitialized if it already has a value. (Such | ||
| 145 | reinitialization could discard customizations made by the user.) | ||
| 146 | 144 | ||
| 147 | @item | 145 | @item |
| 148 | @cindex syntax tables in modes | 146 | @cindex syntax tables in modes |
| 149 | The mode may have its own syntax table or may share one with other | 147 | The mode may have its own syntax table or may share one with other |
| 150 | related modes. If it has its own syntax table, it should store this in | 148 | related modes. If it has its own syntax table, it should store this in |
| 151 | a variable named @code{@var{modename}-mode-syntax-table}. The reasons | 149 | a variable named @code{@var{modename}-mode-syntax-table}. @xref{Syntax |
| 152 | for this are the same as for using a keymap variable. @xref{Syntax | ||
| 153 | Tables}. | 150 | Tables}. |
| 154 | 151 | ||
| 155 | @item | 152 | @item |
| @@ -160,6 +157,11 @@ a variable named @code{@var{modename}-mode-abbrev-table}. @xref{Abbrev | |||
| 160 | Tables}. | 157 | Tables}. |
| 161 | 158 | ||
| 162 | @item | 159 | @item |
| 160 | Use @code{defvar} to set mode-related variables, so that they are not | ||
| 161 | reinitialized if they already have a value. (Such reinitialization | ||
| 162 | could discard customizations made by the user.) | ||
| 163 | |||
| 164 | @item | ||
| 163 | @cindex buffer-local variables in modes | 165 | @cindex buffer-local variables in modes |
| 164 | To make a buffer-local binding for an Emacs customization variable, use | 166 | To make a buffer-local binding for an Emacs customization variable, use |
| 165 | @code{make-local-variable} in the major mode command, not | 167 | @code{make-local-variable} in the major mode command, not |
| @@ -223,7 +225,7 @@ include in their @file{.emacs} files. | |||
| 223 | 225 | ||
| 224 | @item | 226 | @item |
| 225 | @cindex mode loading | 227 | @cindex mode loading |
| 226 | The top level forms in the file defining the mode should be written so | 228 | The top-level forms in the file defining the mode should be written so |
| 227 | that they may be evaluated more than once without adverse consequences. | 229 | that they may be evaluated more than once without adverse consequences. |
| 228 | Even if you never load the file more than once, someone else will. | 230 | Even if you never load the file more than once, someone else will. |
| 229 | @end itemize | 231 | @end itemize |
| @@ -234,7 +236,7 @@ does anything else. This gives major modes a way to arrange for | |||
| 234 | something special to be done if the user switches to a different major | 236 | something special to be done if the user switches to a different major |
| 235 | mode. For best results, make this variable buffer-local, so that it | 237 | mode. For best results, make this variable buffer-local, so that it |
| 236 | will disappear after doing its job and will not interfere with the | 238 | will disappear after doing its job and will not interfere with the |
| 237 | subsequent major mode. | 239 | subsequent major mode. @xref{Hooks}. |
| 238 | @end defvar | 240 | @end defvar |
| 239 | 241 | ||
| 240 | @node Example Major Modes | 242 | @node Example Major Modes |
| @@ -424,8 +426,7 @@ variable with @code{defvar} to hold the mode-specific keymap. When this | |||
| 424 | void. Then we set up the keymap if the variable is @code{nil}. | 426 | void. Then we set up the keymap if the variable is @code{nil}. |
| 425 | 427 | ||
| 426 | This code avoids changing the keymap or the variable if it is already | 428 | This code avoids changing the keymap or the variable if it is already |
| 427 | set up. This lets the user customize the keymap if he or she so | 429 | set up. This lets the user customize the keymap. |
| 428 | wishes. | ||
| 429 | 430 | ||
| 430 | @smallexample | 431 | @smallexample |
| 431 | @group | 432 | @group |
| @@ -461,7 +462,7 @@ Entry to this mode runs the hook `emacs-lisp-mode-hook'." | |||
| 461 | (setq major-mode 'emacs-lisp-mode) ; @r{This is how @code{describe-mode}} | 462 | (setq major-mode 'emacs-lisp-mode) ; @r{This is how @code{describe-mode}} |
| 462 | ; @r{finds out what to describe.} | 463 | ; @r{finds out what to describe.} |
| 463 | (setq mode-name "Emacs-Lisp") ; @r{This goes into the mode line.} | 464 | (setq mode-name "Emacs-Lisp") ; @r{This goes into the mode line.} |
| 464 | (lisp-mode-variables nil) ; @r{This define various variables.} | 465 | (lisp-mode-variables nil) ; @r{This defines various variables.} |
| 465 | (run-hooks 'emacs-lisp-mode-hook)) ; @r{This permits the user to use a} | 466 | (run-hooks 'emacs-lisp-mode-hook)) ; @r{This permits the user to use a} |
| 466 | ; @r{hook to customize the mode.} | 467 | ; @r{hook to customize the mode.} |
| 467 | @end group | 468 | @end group |
| @@ -527,7 +528,7 @@ the user what to do for each file. The default value is @code{maybe}. | |||
| 527 | This function selects the major mode that is appropriate for the | 528 | This function selects the major mode that is appropriate for the |
| 528 | current buffer. It may base its decision on the value of the @w{@samp{-*-}} | 529 | current buffer. It may base its decision on the value of the @w{@samp{-*-}} |
| 529 | line, on the visited file name (using @code{auto-mode-alist}), or on the | 530 | line, on the visited file name (using @code{auto-mode-alist}), or on the |
| 530 | value of a local variable). However, this function does not look for | 531 | value of a local variable. However, this function does not look for |
| 531 | the @samp{mode:} local variable near the end of a file; the | 532 | the @samp{mode:} local variable near the end of a file; the |
| 532 | @code{hack-local-variables} function does that. @xref{Choosing Modes, , | 533 | @code{hack-local-variables} function does that. @xref{Choosing Modes, , |
| 533 | How Major Modes are Chosen, emacs, The GNU Emacs Manual}. | 534 | How Major Modes are Chosen, emacs, The GNU Emacs Manual}. |
| @@ -600,10 +601,11 @@ Here is an example of how to prepend several pattern pairs to | |||
| 600 | @group | 601 | @group |
| 601 | (setq auto-mode-alist | 602 | (setq auto-mode-alist |
| 602 | (append | 603 | (append |
| 603 | ;; @r{Filename starts with a dot.} | 604 | ;; @r{File name starts with a dot.} |
| 604 | '(("/\\.[^/]*$" . fundamental-mode) | 605 | '(("/\\.[^/]*$" . fundamental-mode) |
| 605 | ;; @r{Filename has no dot.} | 606 | ;; @r{File name has no dot.} |
| 606 | ("[^\\./]*$" . fundamental-mode) | 607 | ("[^\\./]*$" . fundamental-mode) |
| 608 | ;; @r{File name ends in @samp{.C}.} | ||
| 607 | ("\\.C$" . c++-mode)) | 609 | ("\\.C$" . c++-mode)) |
| 608 | auto-mode-alist)) | 610 | auto-mode-alist)) |
| 609 | @end group | 611 | @end group |
| @@ -618,8 +620,8 @@ example, @code{("perl" . perl-mode)} is one element present by default. | |||
| 618 | The element says to use mode @var{mode} if the file specifies | 620 | The element says to use mode @var{mode} if the file specifies |
| 619 | @var{interpreter}. | 621 | @var{interpreter}. |
| 620 | 622 | ||
| 621 | This variable is applicable only when the file name doesn't indicate | 623 | This variable is applicable only when the @code{auto-mode-alist} does |
| 622 | which major mode to use. | 624 | not indicate which major mode to use. |
| 623 | @end defvar | 625 | @end defvar |
| 624 | 626 | ||
| 625 | @defun hack-local-variables &optional force | 627 | @defun hack-local-variables &optional force |
| @@ -628,7 +630,8 @@ variables for the current buffer. | |||
| 628 | 630 | ||
| 629 | The handling of @code{enable-local-variables} documented for | 631 | The handling of @code{enable-local-variables} documented for |
| 630 | @code{normal-mode} actually takes place here. The argument @var{force} | 632 | @code{normal-mode} actually takes place here. The argument @var{force} |
| 631 | reflects the argument @var{find-file} given to @code{normal-mode}. | 633 | usually comes from the argument @var{find-file} given to |
| 634 | @code{normal-mode}. | ||
| 632 | @end defun | 635 | @end defun |
| 633 | 636 | ||
| 634 | @node Mode Help | 637 | @node Mode Help |
| @@ -654,9 +657,9 @@ displays the documentation string of the major mode function. | |||
| 654 | 657 | ||
| 655 | @defvar major-mode | 658 | @defvar major-mode |
| 656 | This variable holds the symbol for the current buffer's major mode. | 659 | This variable holds the symbol for the current buffer's major mode. |
| 657 | This symbol should have a function definition which is the command to | 660 | This symbol should have a function definition that is the command to |
| 658 | switch to that major mode. The @code{describe-mode} function uses the | 661 | switch to that major mode. The @code{describe-mode} function uses the |
| 659 | documentation string of this symbol as the documentation of the major | 662 | documentation string of the function as the documentation of the major |
| 660 | mode. | 663 | mode. |
| 661 | @end defvar | 664 | @end defvar |
| 662 | 665 | ||
| @@ -666,12 +669,12 @@ mode. | |||
| 666 | It's often useful to define a new major mode in terms of an existing | 669 | It's often useful to define a new major mode in terms of an existing |
| 667 | one. An easy way to do this is to use @code{define-derived-mode}. | 670 | one. An easy way to do this is to use @code{define-derived-mode}. |
| 668 | 671 | ||
| 669 | @defmac define-derived-mode variant parent name doc body@dots{} | 672 | @defmac define-derived-mode variant parent name docstring body@dots{} |
| 670 | This construct defines @var{variant} as a major mode command, using | 673 | This construct defines @var{variant} as a major mode command, using |
| 671 | @var{name} as the string form of the mode which. | 674 | @var{name} as the string form of the mode name. |
| 672 | 675 | ||
| 673 | The definition of the command is to call the function @var{parent}, then | 676 | The new command @var{variant} is defined to call the function |
| 674 | override certain aspects of that parent mode: | 677 | @var{parent}, then override certain aspects of that parent mode: |
| 675 | 678 | ||
| 676 | @itemize @bullet | 679 | @itemize @bullet |
| 677 | @item | 680 | @item |
| @@ -680,13 +683,13 @@ The new mode has its own keymap, named @code{@var{variant}-map}. | |||
| 680 | @code{@var{parent}-map}, if it is not already set. | 683 | @code{@var{parent}-map}, if it is not already set. |
| 681 | 684 | ||
| 682 | @item | 685 | @item |
| 683 | The new mode has its own syntax table, taken from the variable | 686 | The new mode has its own syntax table, kept in the variable |
| 684 | @code{@var{variant}-syntax-table}. | 687 | @code{@var{variant}-syntax-table}. |
| 685 | @code{define-derived-mode} initializes this variable by copying | 688 | @code{define-derived-mode} initializes this variable by copying |
| 686 | @code{@var{parent}-syntax-table}, if it is not already set. | 689 | @code{@var{parent}-syntax-table}, if it is not already set. |
| 687 | 690 | ||
| 688 | @item | 691 | @item |
| 689 | The new mode has its own abbrev table, taken from the variable | 692 | The new mode has its own abbrev table, kept in the variable |
| 690 | @code{@var{variant}-abbrev-table}. | 693 | @code{@var{variant}-abbrev-table}. |
| 691 | @code{define-derived-mode} initializes this variable by copying | 694 | @code{define-derived-mode} initializes this variable by copying |
| 692 | @code{@var{parent}-abbrev-table}, if it is not already set. | 695 | @code{@var{parent}-abbrev-table}, if it is not already set. |
| @@ -699,7 +702,7 @@ of calling @var{parent}.) | |||
| 699 | @end itemize | 702 | @end itemize |
| 700 | 703 | ||
| 701 | In addition, you can specify how to override other aspects of | 704 | In addition, you can specify how to override other aspects of |
| 702 | @var{parent-mode} with @var{body}. The command @var{variant} | 705 | @var{parent} with @var{body}. The command @var{variant} |
| 703 | evaluates the forms in @var{body} after setting up all its usual | 706 | evaluates the forms in @var{body} after setting up all its usual |
| 704 | overrides, just before running @code{@var{variant}-hook}. | 707 | overrides, just before running @code{@var{variant}-hook}. |
| 705 | 708 | ||
| @@ -738,10 +741,9 @@ of the things major modes do. | |||
| 738 | 741 | ||
| 739 | A minor mode is often much more difficult to implement than a major | 742 | A minor mode is often much more difficult to implement than a major |
| 740 | mode. One reason is that you should be able to activate and deactivate | 743 | mode. One reason is that you should be able to activate and deactivate |
| 741 | minor modes in any order. | 744 | minor modes in any order. A minor mode should be able to have its |
| 742 | 745 | desired effect regardless of the major mode and regardless of the other | |
| 743 | and restore the environment of the major mode to the state it was in | 746 | minor modes in effect. |
| 744 | before the minor mode was activated. | ||
| 745 | 747 | ||
| 746 | Often the biggest problem in implementing a minor mode is finding a | 748 | Often the biggest problem in implementing a minor mode is finding a |
| 747 | way to insert the necessary hook into the rest of Emacs. Minor mode | 749 | way to insert the necessary hook into the rest of Emacs. Minor mode |
| @@ -794,8 +796,9 @@ list whose @sc{car} is such an integer or symbol; it should turn the | |||
| 794 | mode off otherwise. | 796 | mode off otherwise. |
| 795 | 797 | ||
| 796 | Here is an example taken from the definition of @code{overwrite-mode}. | 798 | Here is an example taken from the definition of @code{overwrite-mode}. |
| 797 | It shows the use of @code{overwrite-mode} as a variable which enables or | 799 | It shows the use of @code{overwrite-mode} as a variable that enables or |
| 798 | disables the mode's behavior. | 800 | disables the mode's behavior, and also shows the proper way to toggle, |
| 801 | enable or disable the minor mode based on the raw prefix argument value. | ||
| 799 | 802 | ||
| 800 | @smallexample | 803 | @smallexample |
| 801 | @group | 804 | @group |
| @@ -814,7 +817,7 @@ following form: | |||
| 814 | (@var{mode-variable} @var{string}) | 817 | (@var{mode-variable} @var{string}) |
| 815 | @end smallexample | 818 | @end smallexample |
| 816 | 819 | ||
| 817 | Here @var{mode-variable} is the variable that controls enablement of the | 820 | Here @var{mode-variable} is the variable that controls enabling of the |
| 818 | minor mode, and @var{string} is a short string, starting with a space, | 821 | minor mode, and @var{string} is a short string, starting with a space, |
| 819 | to represent the mode in the mode line. These strings must be short so | 822 | to represent the mode in the mode line. These strings must be short so |
| 820 | that there is room for several of them at once. | 823 | that there is room for several of them at once. |
| @@ -834,7 +837,7 @@ check for an existing element, to avoid duplication. For example: | |||
| 834 | @node Keymaps and Minor Modes | 837 | @node Keymaps and Minor Modes |
| 835 | @subsection Keymaps and Minor Modes | 838 | @subsection Keymaps and Minor Modes |
| 836 | 839 | ||
| 837 | As of Emacs version 19, each minor mode can have its own keymap which is | 840 | As of Emacs version 19, each minor mode can have its own keymap, which is |
| 838 | active when the mode is enabled. @xref{Active Keymaps}. To set up a | 841 | active when the mode is enabled. @xref{Active Keymaps}. To set up a |
| 839 | keymap for a minor mode, add an element to the alist | 842 | keymap for a minor mode, add an element to the alist |
| 840 | @code{minor-mode-map-alist}. | 843 | @code{minor-mode-map-alist}. |
| @@ -856,7 +859,7 @@ This variable is an alist of elements that look like this: | |||
| 856 | @end example | 859 | @end example |
| 857 | 860 | ||
| 858 | @noindent | 861 | @noindent |
| 859 | where @var{variable} is the variable which indicates whether the minor | 862 | where @var{variable} is the variable that indicates whether the minor |
| 860 | mode is enabled, and @var{keymap} is the keymap. The keymap | 863 | mode is enabled, and @var{keymap} is the keymap. The keymap |
| 861 | @var{keymap} is active whenever @var{variable} has a non-@code{nil} | 864 | @var{keymap} is active whenever @var{variable} has a non-@code{nil} |
| 862 | value. | 865 | value. |
| @@ -880,11 +883,11 @@ this properly, the order will not matter. | |||
| 880 | @section Mode Line Format | 883 | @section Mode Line Format |
| 881 | @cindex mode line | 884 | @cindex mode line |
| 882 | 885 | ||
| 883 | Each Emacs window (aside from minibuffer windows) includes a mode line | 886 | Each Emacs window (aside from minibuffer windows) includes a mode line, |
| 884 | which displays status information about the buffer displayed in the | 887 | which displays status information about the buffer displayed in the |
| 885 | window. The mode line contains information about the buffer such as its | 888 | window. The mode line contains information about the buffer, such as its |
| 886 | name, associated file, depth of recursive editing, and the major and | 889 | name, associated file, depth of recursive editing, and the major and |
| 887 | minor modes of the buffer. | 890 | minor modes. |
| 888 | 891 | ||
| 889 | This section describes how the contents of the mode line are | 892 | This section describes how the contents of the mode line are |
| 890 | controlled. It is in the chapter on modes because much of the | 893 | controlled. It is in the chapter on modes because much of the |
| @@ -900,8 +903,9 @@ line numbers). | |||
| 900 | The mode line of a window is normally updated whenever a different | 903 | The mode line of a window is normally updated whenever a different |
| 901 | buffer is shown in the window, or when the buffer's modified-status | 904 | buffer is shown in the window, or when the buffer's modified-status |
| 902 | changes from @code{nil} to @code{t} or vice-versa. If you modify any of | 905 | changes from @code{nil} to @code{t} or vice-versa. If you modify any of |
| 903 | the variables referenced by @code{mode-line-format}, you may want to | 906 | the variables referenced by @code{mode-line-format} (@pxref{Mode Line |
| 904 | force an update of the mode line so as to display the new information. | 907 | Variables}), you may want to force an update of the mode line so as to |
| 908 | display the new information. | ||
| 905 | 909 | ||
| 906 | @c Emacs 19 feature | 910 | @c Emacs 19 feature |
| 907 | @defun force-mode-line-update | 911 | @defun force-mode-line-update |
| @@ -922,7 +926,7 @@ Force redisplay of the current buffer's mode line. | |||
| 922 | @cindex mode line construct | 926 | @cindex mode line construct |
| 923 | 927 | ||
| 924 | The mode line contents are controlled by a data structure of lists, | 928 | The mode line contents are controlled by a data structure of lists, |
| 925 | strings, symbols and numbers kept in the buffer-local variable | 929 | strings, symbols, and numbers kept in the buffer-local variable |
| 926 | @code{mode-line-format}. The data structure is called a @dfn{mode line | 930 | @code{mode-line-format}. The data structure is called a @dfn{mode line |
| 927 | construct}, and it is built in recursive fashion out of simpler mode line | 931 | construct}, and it is built in recursive fashion out of simpler mode line |
| 928 | constructs. | 932 | constructs. |
| @@ -945,9 +949,8 @@ Because of this, very few modes need to alter @code{mode-line-format}. | |||
| 945 | For most purposes, it is sufficient to alter the variables referenced by | 949 | For most purposes, it is sufficient to alter the variables referenced by |
| 946 | @code{mode-line-format}. | 950 | @code{mode-line-format}. |
| 947 | 951 | ||
| 948 | A mode line construct may be a list, cons cell, symbol, or string. If | 952 | A mode line construct may be a list, a symbol, or a string. If the |
| 949 | the value is a list, each element may be a list, a cons cell, a symbol, | 953 | value is a list, each element may be a list, a symbol, or a string. |
| 950 | or a string. | ||
| 951 | 954 | ||
| 952 | @table @code | 955 | @table @code |
| 953 | @cindex percent symbol in mode line | 956 | @cindex percent symbol in mode line |
| @@ -959,24 +962,26 @@ is left justified). @xref{%-Constructs}. | |||
| 959 | 962 | ||
| 960 | @item @var{symbol} | 963 | @item @var{symbol} |
| 961 | A symbol as a mode line construct stands for its value. The value of | 964 | A symbol as a mode line construct stands for its value. The value of |
| 962 | @var{symbol} is used in place of @var{symbol} unless @var{symbol} is | 965 | @var{symbol} is used as a mode line construct, in place of @var{symbol}. |
| 963 | @code{t} or @code{nil}, or is void, in which case @var{symbol} is | 966 | However, the symbols @code{t} and @code{nil} are ignored; so is any |
| 964 | ignored. | 967 | symbol whose value is void. |
| 965 | 968 | ||
| 966 | There is one exception: if the value of @var{symbol} is a string, it is | 969 | There is one exception: if the value of @var{symbol} is a string, it is |
| 967 | processed verbatim in that the @code{%}-constructs are not recognized. | 970 | displayed verbatim: the @code{%}-constructs are not recognized. |
| 968 | 971 | ||
| 969 | @item (@var{string} @var{rest}@dots{}) @r{or} (@var{list} @var{rest}@dots{}) | 972 | @item (@var{string} @var{rest}@dots{}) @r{or} (@var{list} @var{rest}@dots{}) |
| 970 | A list whose first element is a string or list, means to concatenate all | 973 | A list whose first element is a string or list means to process all the |
| 971 | the elements. This is the most common form of mode line construct. | 974 | elements recursively and concatenate the results. This is the most |
| 975 | common form of mode line construct. | ||
| 972 | 976 | ||
| 973 | @item (@var{symbol} @var{then} @var{else}) | 977 | @item (@var{symbol} @var{then} @var{else}) |
| 974 | A list whose first element is a symbol is a conditional. Its meaning | 978 | A list whose first element is a symbol is a conditional. Its meaning |
| 975 | depends on the value of @var{symbol}. If the value is non-@code{nil}, | 979 | depends on the value of @var{symbol}. If the value is non-@code{nil}, |
| 976 | the second element of the list (@var{then}) is processed recursively as | 980 | the second element, @var{then}, is processed recursively as a mode line |
| 977 | a mode line element. But if the value of @var{symbol} is @code{nil}, | 981 | element. But if the value of @var{symbol} is @code{nil}, the third |
| 978 | the third element of the list (if there is one) is processed | 982 | element, @var{else}, is processed recursively. You may omit @var{else}; |
| 979 | recursively. | 983 | then the mode line element displays nothing if the value of @var{symbol} |
| 984 | is @code{nil}. | ||
| 980 | 985 | ||
| 981 | @item (@var{width} @var{rest}@dots{}) | 986 | @item (@var{width} @var{rest}@dots{}) |
| 982 | A list whose first element is an integer specifies truncation or | 987 | A list whose first element is an integer specifies truncation or |
| @@ -987,19 +992,19 @@ concatenated together. Then the result is space filled (if | |||
| 987 | if @var{width} is negative) on the right. | 992 | if @var{width} is negative) on the right. |
| 988 | 993 | ||
| 989 | For example, the usual way to show what percentage of a buffer is above | 994 | For example, the usual way to show what percentage of a buffer is above |
| 990 | the top of the window is to use a list like this: @code{(-3 . "%p")}. | 995 | the top of the window is to use a list like this: @code{(-3 "%p")}. |
| 991 | @end table | 996 | @end table |
| 992 | 997 | ||
| 993 | If you do alter @code{mode-line-format} itself, the new value should | 998 | If you do alter @code{mode-line-format} itself, the new value should |
| 994 | use all the same variables that are used by the default value, rather | 999 | use the same variables that appear in the default value (@pxref{Mode |
| 995 | than duplicating their contents or displaying the information in another | 1000 | Line Variables}), rather than duplicating their contents or displaying |
| 996 | fashion. This way, customizations made by the user, by libraries (such | 1001 | the information in another fashion. This way, customizations made by |
| 997 | as @code{display-time}) and by major modes via changes to those | 1002 | the user, by libraries (such as @code{display-time}) and by major modes |
| 998 | variables remain effective. | 1003 | via changes to those variables remain effective. |
| 999 | 1004 | ||
| 1000 | @cindex Shell mode @code{mode-line-format} | 1005 | @cindex Shell mode @code{mode-line-format} |
| 1001 | Here is an example of a @code{mode-line-format} that might be | 1006 | Here is an example of a @code{mode-line-format} that might be |
| 1002 | useful for @code{shell-mode} since it contains the hostname and default | 1007 | useful for @code{shell-mode}, since it contains the hostname and default |
| 1003 | directory. | 1008 | directory. |
| 1004 | 1009 | ||
| 1005 | @example | 1010 | @example |
| @@ -1014,10 +1019,11 @@ directory. | |||
| 1014 | 'default-directory | 1019 | 'default-directory |
| 1015 | " " | 1020 | " " |
| 1016 | 'global-mode-string | 1021 | 'global-mode-string |
| 1017 | " %[(" 'mode-name | 1022 | " %[(" |
| 1023 | 'mode-name | ||
| 1024 | 'mode-line-process | ||
| 1018 | 'minor-mode-alist | 1025 | 'minor-mode-alist |
| 1019 | "%n" | 1026 | "%n" |
| 1020 | 'mode-line-process | ||
| 1021 | ")%]----" | 1027 | ")%]----" |
| 1022 | @group | 1028 | @group |
| 1023 | (line-number-mode "L%l--") | 1029 | (line-number-mode "L%l--") |
| @@ -1036,10 +1042,10 @@ other variables could have the same effects on the mode line if | |||
| 1036 | @code{mode-line-format} were changed to use them. | 1042 | @code{mode-line-format} were changed to use them. |
| 1037 | 1043 | ||
| 1038 | @defvar mode-line-modified | 1044 | @defvar mode-line-modified |
| 1039 | This variable holds the value of the mode-line construct that displays | 1045 | This variable holds the value of the mode-line construct that displays |
| 1040 | whether the current buffer is modified. | 1046 | whether the current buffer is modified. |
| 1041 | 1047 | ||
| 1042 | The default value of @code{mode-line-modified} is | 1048 | The default value of @code{mode-line-modified} is |
| 1043 | @code{("--%1*%1*-")}. This means that the mode line displays | 1049 | @code{("--%1*%1*-")}. This means that the mode line displays |
| 1044 | @samp{--**-} if the buffer is modified, @samp{-----} if the buffer is | 1050 | @samp{--**-} if the buffer is modified, @samp{-----} if the buffer is |
| 1045 | not modified, and @samp{--%%-} if the buffer is read only. | 1051 | not modified, and @samp{--%%-} if the buffer is read only. |
| @@ -1048,10 +1054,11 @@ Changing this variable does not force an update of the mode line. | |||
| 1048 | @end defvar | 1054 | @end defvar |
| 1049 | 1055 | ||
| 1050 | @defvar mode-line-buffer-identification | 1056 | @defvar mode-line-buffer-identification |
| 1051 | This variable identifies the buffer being displayed in the window. | 1057 | This variable identifies the buffer being displayed in the window. Its |
| 1052 | Its default value is @samp{Emacs: %17b}, which means that it displays | 1058 | default value is @samp{Emacs: %17b}, which means that it displays |
| 1053 | @samp{Emacs:} followed by the buffer name. You may want to change this | 1059 | @samp{Emacs:} followed by seventeen characters of the buffer name. You |
| 1054 | in modes such as Rmail that do not behave like a ``normal'' Emacs. | 1060 | may want to change this in modes such as Rmail that do not behave like a |
| 1061 | ``normal'' Emacs. | ||
| 1055 | @end defvar | 1062 | @end defvar |
| 1056 | 1063 | ||
| 1057 | @defvar global-mode-string | 1064 | @defvar global-mode-string |
| @@ -1067,13 +1074,13 @@ included directly in the mode line. | |||
| 1067 | @end defvar | 1074 | @end defvar |
| 1068 | 1075 | ||
| 1069 | @defvar mode-name | 1076 | @defvar mode-name |
| 1070 | This buffer-local variable holds the ``pretty'' name of the current | 1077 | This buffer-local variable holds the ``pretty'' name of the current |
| 1071 | buffer's major mode. Each major mode should set this variable so that the | 1078 | buffer's major mode. Each major mode should set this variable so that the |
| 1072 | mode name will appear in the mode line. | 1079 | mode name will appear in the mode line. |
| 1073 | @end defvar | 1080 | @end defvar |
| 1074 | 1081 | ||
| 1075 | @defvar minor-mode-alist | 1082 | @defvar minor-mode-alist |
| 1076 | This variable holds an association list whose elements specify how the | 1083 | This variable holds an association list whose elements specify how the |
| 1077 | mode line should indicate that a minor mode is active. Each element of | 1084 | mode line should indicate that a minor mode is active. Each element of |
| 1078 | the @code{minor-mode-alist} should be a two-element list: | 1085 | the @code{minor-mode-alist} should be a two-element list: |
| 1079 | 1086 | ||
| @@ -1120,11 +1127,11 @@ is @code{nil}. | |||
| 1120 | @end defvar | 1127 | @end defvar |
| 1121 | 1128 | ||
| 1122 | @defvar default-mode-line-format | 1129 | @defvar default-mode-line-format |
| 1123 | This variable holds the default @code{mode-line-format} for buffers | 1130 | This variable holds the default @code{mode-line-format} for buffers |
| 1124 | that do not override it. This is the same as @code{(default-value | 1131 | that do not override it. This is the same as @code{(default-value |
| 1125 | 'mode-line-format)}. | 1132 | 'mode-line-format)}. |
| 1126 | 1133 | ||
| 1127 | The default value of @code{default-mode-line-format} is: | 1134 | The default value of @code{default-mode-line-format} is: |
| 1128 | 1135 | ||
| 1129 | @example | 1136 | @example |
| 1130 | @group | 1137 | @group |
| @@ -1147,11 +1154,19 @@ that do not override it. This is the same as @code{(default-value | |||
| 1147 | @end example | 1154 | @end example |
| 1148 | @end defvar | 1155 | @end defvar |
| 1149 | 1156 | ||
| 1157 | @defvar vc-mode | ||
| 1158 | The variable @code{vc-mode}, local in each buffer, records whether the | ||
| 1159 | buffer's visited file is maintained with version control, and, if so, | ||
| 1160 | which kind. Its value is @code{nil} for no version control, or a string | ||
| 1161 | that appears in the mode line. | ||
| 1162 | @end defvar | ||
| 1163 | |||
| 1150 | @node %-Constructs | 1164 | @node %-Constructs |
| 1151 | @subsection @code{%}-Constructs in the Mode Line | 1165 | @subsection @code{%}-Constructs in the Mode Line |
| 1152 | 1166 | ||
| 1153 | The following table lists the recognized @code{%}-constructs and what | 1167 | The following table lists the recognized @code{%}-constructs and what |
| 1154 | they mean. | 1168 | they mean. In any construct except @samp{%%}, you can add a decimal |
| 1169 | integer after the @samp{%} to specify how many characters to display. | ||
| 1155 | 1170 | ||
| 1156 | @table @code | 1171 | @table @code |
| 1157 | @item %b | 1172 | @item %b |
| @@ -1168,7 +1183,7 @@ function. @xref{Buffer File Name}. | |||
| 1168 | @samp{-} otherwise. @xref{Buffer Modification}. | 1183 | @samp{-} otherwise. @xref{Buffer Modification}. |
| 1169 | 1184 | ||
| 1170 | @item %+ | 1185 | @item %+ |
| 1171 | @samp{*} if the buffer is modified, and otherwise @samp{-}. | 1186 | @samp{*} if the buffer is modified, and @samp{-} otherwise. |
| 1172 | 1187 | ||
| 1173 | @item %s | 1188 | @item %s |
| 1174 | The status of the subprocess belonging to the current buffer, obtained with | 1189 | The status of the subprocess belonging to the current buffer, obtained with |
| @@ -1241,8 +1256,8 @@ a Function}). Most normal hook variables are initially void; | |||
| 1241 | @code{add-hook} knows how to deal with this. | 1256 | @code{add-hook} knows how to deal with this. |
| 1242 | 1257 | ||
| 1243 | As for abnormal hooks, those whose names end in @samp{-function} have | 1258 | As for abnormal hooks, those whose names end in @samp{-function} have |
| 1244 | a value which is a single function. Those whose names end in | 1259 | a value that is a single function. Those whose names end in |
| 1245 | @samp{-hooks} have a value which is a list of functions. Any hook which | 1260 | @samp{-hooks} have a value that is a list of functions. Any hook that |
| 1246 | is abnormal is abnormal because a normal hook won't do the job; either | 1261 | is abnormal is abnormal because a normal hook won't do the job; either |
| 1247 | the functions are called with arguments, or their values are meaningful. | 1262 | the functions are called with arguments, or their values are meaningful. |
| 1248 | The name shows you that the hook is abnormal and that you should look at | 1263 | The name shows you that the hook is abnormal and that you should look at |
| @@ -1340,7 +1355,8 @@ For example, here's how @code{emacs-lisp-hooks} runs its mode hook: | |||
| 1340 | 1355 | ||
| 1341 | @defun add-hook hook function &optional append | 1356 | @defun add-hook hook function &optional append |
| 1342 | This function is the handy way to add function @var{function} to hook | 1357 | This function is the handy way to add function @var{function} to hook |
| 1343 | variable @var{hook}. For example, | 1358 | variable @var{hook}. The argument @var{function} may be any valid Lisp |
| 1359 | function with the proper number of arguments. For example, | ||
| 1344 | 1360 | ||
| 1345 | @example | 1361 | @example |
| 1346 | (add-hook 'text-mode-hook 'my-text-hook-function) | 1362 | (add-hook 'text-mode-hook 'my-text-hook-function) |
| @@ -1349,6 +1365,9 @@ variable @var{hook}. For example, | |||
| 1349 | @noindent | 1365 | @noindent |
| 1350 | adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}. | 1366 | adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}. |
| 1351 | 1367 | ||
| 1368 | You can use @code{add-hook} for abnormal hooks as well as for normal | ||
| 1369 | hooks. | ||
| 1370 | |||
| 1352 | It is best to design your hook functions so that the order in which they | 1371 | It is best to design your hook functions so that the order in which they |
| 1353 | are executed does not matter. Any dependence on the order is ``asking | 1372 | are executed does not matter. Any dependence on the order is ``asking |
| 1354 | for trouble.'' However, the order is predictable: normally, | 1373 | for trouble.'' However, the order is predictable: normally, |