diff options
| author | Richard M. Stallman | 2006-08-08 17:39:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-08-08 17:39:08 +0000 |
| commit | 02a2b2ad4f23b253380485eca654bf4b338d0855 (patch) | |
| tree | 57a2da0bcc5ecc575a893c0adedbe80e2ea0eccd | |
| parent | 08e5fcf12acce1b89b667e552a2d8f23e34c2423 (diff) | |
| download | emacs-02a2b2ad4f23b253380485eca654bf4b338d0855.tar.gz emacs-02a2b2ad4f23b253380485eca654bf4b338d0855.zip | |
Clean up wording in previous change.
| -rw-r--r-- | lispref/ChangeLog | 4 | ||||
| -rw-r--r-- | lispref/modes.texi | 179 |
2 files changed, 87 insertions, 96 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog index 8c963512d2f..318c00e84b6 100644 --- a/lispref/ChangeLog +++ b/lispref/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2006-08-08 Richard Stallman <rms@gnu.org> | ||
| 2 | |||
| 3 | * modes.texi: Clean up wording in previous change. | ||
| 4 | |||
| 1 | 2006-08-07 Chong Yidong <cyd@stupidchicken.com> | 5 | 2006-08-07 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 6 | ||
| 3 | * modes.texi (Hooks): Clarify. | 7 | * modes.texi (Hooks): Clarify. |
diff --git a/lispref/modes.texi b/lispref/modes.texi index e0953c403b2..f8afcd8a829 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -52,8 +52,8 @@ possible, so that you can use them in a uniform way. | |||
| 52 | the @dfn{mode hook} as the one of the last steps of initialization. | 52 | the @dfn{mode hook} as the one of the last steps of initialization. |
| 53 | This makes it easy for a user to customize the behavior of the mode, | 53 | This makes it easy for a user to customize the behavior of the mode, |
| 54 | by overriding the buffer-local variable assignments already made by | 54 | by overriding the buffer-local variable assignments already made by |
| 55 | the mode. Most minor modes also run a mode hook at their end. But | 55 | the mode. Most minor mode functions also run a mode hook at the end. |
| 56 | hooks are used in other contexts too. For example, the hook | 56 | But hooks are used in other contexts too. For example, the hook |
| 57 | @code{suspend-hook} runs just before Emacs suspends itself | 57 | @code{suspend-hook} runs just before Emacs suspends itself |
| 58 | (@pxref{Suspending Emacs}). | 58 | (@pxref{Suspending Emacs}). |
| 59 | 59 | ||
| @@ -66,17 +66,16 @@ globally or buffer-locally with @code{add-hook}. | |||
| 66 | 66 | ||
| 67 | @cindex abnormal hook | 67 | @cindex abnormal hook |
| 68 | If the hook variable's name does not end with @samp{-hook}, that | 68 | If the hook variable's name does not end with @samp{-hook}, that |
| 69 | indicates it is probably an @dfn{abnormal hook}. Then you should look at its | 69 | indicates it is probably an @dfn{abnormal hook}. That means the hook |
| 70 | documentation to see how to use the hook properly. | 70 | functions are called with arguments, or their return values are used |
| 71 | in some way. The hook's documentation says how the functions are | ||
| 72 | called. You can use @code{add-hook} to add a function to an abnormal | ||
| 73 | hook, but you must write the function to follow the hook's calling | ||
| 74 | convention. | ||
| 71 | 75 | ||
| 72 | @dfn{Abnormal hooks} are hooks in which the functions are called | 76 | By convention, abnormal hook names end in @samp{-functions} or |
| 73 | with arguments, or the return values are used in some way. By | 77 | @samp{-hooks}. If the variable's name ends in @samp{-function}, then |
| 74 | convention, abnormal hook names end in @samp{-functions} or | 78 | its value is just a single function, not a list of functions. |
| 75 | @samp{-hooks}. You can use @code{add-hook} to add a function to the | ||
| 76 | list, but you must take care in writing the function. | ||
| 77 | |||
| 78 | If the variable's name ends in @samp{-function}, then its value | ||
| 79 | is just a single function, not a list of functions. | ||
| 80 | 79 | ||
| 81 | Here's an example that uses a mode hook to turn on Auto Fill mode when | 80 | Here's an example that uses a mode hook to turn on Auto Fill mode when |
| 82 | in Lisp Interaction mode: | 81 | in Lisp Interaction mode: |
| @@ -95,12 +94,12 @@ symbol that is a normal hook variable. These arguments are processed | |||
| 95 | in the order specified. | 94 | in the order specified. |
| 96 | 95 | ||
| 97 | If a hook variable has a non-@code{nil} value, that value should be a | 96 | If a hook variable has a non-@code{nil} value, that value should be a |
| 98 | list of functions. Each function in this list is called, | 97 | list of functions. @code{run-hooks} calls all the functions, one by |
| 99 | consecutively, with no arguments. | 98 | one, with no arguments. |
| 100 | 99 | ||
| 101 | A hook variable can also be a single function (either a lambda | 100 | The hook variable's value can also be a single function---either a |
| 102 | expression or a symbol with a function definition) to be called. This | 101 | lambda expression or a symbol with a function definition---which |
| 103 | use is considered obsolete. | 102 | @code{run-hooks} calls. But this usage is obsolete. |
| 104 | @end defun | 103 | @end defun |
| 105 | 104 | ||
| 106 | @defun run-hook-with-args hook &rest args | 105 | @defun run-hook-with-args hook &rest args |
| @@ -357,9 +356,10 @@ letters and other printing characters as special commands. | |||
| 357 | 356 | ||
| 358 | @item | 357 | @item |
| 359 | Major modes modes for editing text should not define @key{RET} to do | 358 | Major modes modes for editing text should not define @key{RET} to do |
| 360 | anything other than insert a newline. The command to insert a newline | 359 | anything other than insert a newline. However, it is ok for |
| 361 | and then indent is @kbd{C-j}. It is ok for more specialized modes, | 360 | specialized modes for text that users don't directly edit, such as |
| 362 | such as Info mode, to redefine @key{RET} to something else. | 361 | Dired and Info modes, to redefine @key{RET} to do something entirely |
| 362 | different. | ||
| 363 | 363 | ||
| 364 | @item | 364 | @item |
| 365 | Major modes should not alter options that are primarily a matter of user | 365 | Major modes should not alter options that are primarily a matter of user |
| @@ -801,101 +801,92 @@ Do not write an @code{interactive} spec in the definition; | |||
| 801 | @subsection Generic Modes | 801 | @subsection Generic Modes |
| 802 | @cindex generic mode | 802 | @cindex generic mode |
| 803 | 803 | ||
| 804 | @dfn{Generic modes} are simple major modes with basic support for | 804 | @dfn{Generic modes} are simple major modes with basic support for |
| 805 | comment syntax and Font Lock mode. To define a generic mode, use the | 805 | comment syntax and Font Lock mode. To define a generic mode, use the |
| 806 | macro @code{define-generic-mode}. See the file @file{generic-x.el} | 806 | macro @code{define-generic-mode}. See the file @file{generic-x.el} |
| 807 | for some examples of the use of @code{define-generic-mode}. | 807 | for some examples of the use of @code{define-generic-mode}. |
| 808 | 808 | ||
| 809 | @defmac define-generic-mode mode comment-list keyword-list font-lock-list auto-mode-list function-list &optional docstring | 809 | @defmac define-generic-mode mode comment-list keyword-list font-lock-list auto-mode-list function-list &optional docstring |
| 810 | This macro creates a new generic mode. The argument @var{mode} (an | 810 | This macro defines a generic mode command named @var{mode} (a symbol, |
| 811 | unquoted symbol) is the major mode command. The optional argument | 811 | not quoted). The optional argument @var{docstring} is the |
| 812 | @var{docstring} is the documentation for the mode command. If you do | 812 | documentation for the mode command. If you do not supply it, |
| 813 | not supply it, @code{define-generic-mode} uses a default documentation | 813 | @code{define-generic-mode} generates one by default. |
| 814 | string instead. | 814 | |
| 815 | 815 | The argument @var{comment-list} is a list in which each element is | |
| 816 | @var{comment-list} is a list in which each element is either a | 816 | either a character, a string of one or two characters, or a cons cell. |
| 817 | character, a string of one or two characters, or a cons cell. A | 817 | A character or a string is set up in the mode's syntax table as a |
| 818 | character or a string is set up in the mode's syntax table as a | ||
| 819 | ``comment starter.'' If the entry is a cons cell, the @sc{car} is set | 818 | ``comment starter.'' If the entry is a cons cell, the @sc{car} is set |
| 820 | up as a ``comment starter'' and the @sc{cdr} as a ``comment ender.'' | 819 | up as a ``comment starter'' and the @sc{cdr} as a ``comment ender.'' |
| 821 | (Use @code{nil} for the latter if you want comments to end at the end | 820 | (Use @code{nil} for the latter if you want comments to end at the end |
| 822 | of the line.) Note that the syntax table has limitations about what | 821 | of the line.) Note that the syntax table mechanism has limitations |
| 823 | comment starters and enders are actually possible. @xref{Syntax | 822 | about what comment starters and enders are actually possible. |
| 824 | Tables}. | 823 | @xref{Syntax Tables}. |
| 825 | 824 | ||
| 826 | @var{keyword-list} is a list of keywords to highlight with | 825 | The argument @var{keyword-list} is a list of keywords to highlight |
| 827 | @code{font-lock-keyword-face}. Each keyword should be a string. | 826 | with @code{font-lock-keyword-face}. Each keyword should be a string. |
| 828 | @var{font-lock-list} is a list of additional expressions to highlight. | 827 | Meanwhile, @var{font-lock-list} is a list of additional expressions to |
| 829 | Each element of this list should have the same form as an element of | 828 | highlight. Each element of this list should have the same form as an |
| 830 | @code{font-lock-keywords}. @xref{Search-based Fontification}. | 829 | element of @code{font-lock-keywords}. @xref{Search-based |
| 831 | 830 | Fontification}. | |
| 832 | @var{auto-mode-list} is a list of regular expressions to add to the | 831 | |
| 833 | variable @code{auto-mode-alist}. These regular expressions are added | 832 | The argument @var{auto-mode-list} is a list of regular expressions to |
| 834 | when Emacs runs the macro expansion. | 833 | add to the variable @code{auto-mode-alist}. They are added by the execution |
| 835 | 834 | of the @code{define-generic-mode} form, not by expanding the macro call. | |
| 836 | @var{function-list} is a list of functions to call to do some | 835 | |
| 837 | additional setup. The mode command calls these functions just before | 836 | Finally, @var{function-list} is a list of functions for the mode |
| 838 | it runs the mode hook variable @code{@var{mode}-hook}. | 837 | command to call for additional setup. It calls these functions just |
| 838 | before it runs the mode hook variable @code{@var{mode}-hook}. | ||
| 839 | @end defmac | 839 | @end defmac |
| 840 | 840 | ||
| 841 | @node Mode Hooks | 841 | @node Mode Hooks |
| 842 | @subsection Mode Hooks | 842 | @subsection Mode Hooks |
| 843 | 843 | ||
| 844 | The two last things a major mode function should do is run its mode | 844 | Every major mode function should finish by running its mode hook and |
| 845 | hook and finally the mode independent normal hook | 845 | the mode-independent normal hook @code{after-change-major-mode-hook}. |
| 846 | @code{after-change-major-mode-hook}. If the major mode is a derived | 846 | It does this by calling @code{run-mode-hooks}. If the major mode is a |
| 847 | mode, that is if it calls another major mode (the parent mode) in its | 847 | derived mode, that is if it calls another major mode (the parent mode) |
| 848 | body, then the parent's mode hook is run just before the derived | 848 | in its body, it should do this inside @code{delay-mode-hooks} so that |
| 849 | mode's hook. Neither the parent's mode hook nor | 849 | the parent won't run these hooks itself. Instead, the derived mode's |
| 850 | @code{after-change-major-mode-hook} are run at the end of the actual | 850 | call to @code{run-mode-hooks} runs the parent's mode hook too. |
| 851 | call to the parent mode. This applies recursively if the parent mode | 851 | @xref{Major Mode Conventions}. |
| 852 | has itself a parent. That is, the mode hooks of all major modes | 852 | |
| 853 | called directly or indirectly by the major mode function are all run | 853 | Emacs versions before Emacs 22 did not have @code{delay-mode-hooks}. |
| 854 | in sequence at the end, just before | 854 | When user-implemented major modes have not been updated to use it, |
| 855 | @code{after-change-major-mode-hook}. | 855 | they won't entirely follow these conventions: they may run the |
| 856 | 856 | parent's mode hook too early, or fail to run | |
| 857 | These conventions are new in Emacs 22, and some major modes | 857 | @code{after-change-major-mode-hook}. If you encounter such a major |
| 858 | implemented by users do not follow them yet. So if you put a function | 858 | mode, please correct it to follow these conventions. |
| 859 | onto @code{after-change-major-mode-hook}, keep in mind that some modes | ||
| 860 | will fail to run it. If a user complains about that, you can respond, | ||
| 861 | ``That major mode fails to follow Emacs conventions, and that's why it | ||
| 862 | fails to work. Please fix the major mode.'' In most cases, that is | ||
| 863 | good enough, so go ahead and use @code{after-change-major-mode-hook}. | ||
| 864 | However, if a certain feature needs to be completely reliable, | ||
| 865 | it should not use @code{after-change-major-mode-hook} as of yet. | ||
| 866 | 859 | ||
| 867 | When you defined a major mode using @code{define-derived-mode}, it | 860 | When you defined a major mode using @code{define-derived-mode}, it |
| 868 | automatically makes sure these conventions are followed. If you | 861 | automatically makes sure these conventions are followed. If you |
| 869 | define a major mode ``from scratch,'' not using | 862 | define a major mode ``by hand,'' not using @code{define-derived-mode}, |
| 870 | @code{define-derived-mode}, make sure the major mode command follows | 863 | use the following functions to handle these conventions automatically. |
| 871 | these and other conventions. @xref{Major Mode Conventions}. You use | ||
| 872 | these functions to do it properly. | ||
| 873 | 864 | ||
| 874 | @defun run-mode-hooks &rest hookvars | 865 | @defun run-mode-hooks &rest hookvars |
| 875 | Major modes should run their mode hook using this function. It is | 866 | Major modes should run their mode hook using this function. It is |
| 876 | similar to @code{run-hooks} (@pxref{Hooks}), but it also runs | 867 | similar to @code{run-hooks} (@pxref{Hooks}), but it also runs |
| 877 | @code{after-change-major-mode-hook}. | 868 | @code{after-change-major-mode-hook}. |
| 878 | 869 | ||
| 879 | When the call to this function is dynamically inside a | 870 | When this function is called during the execution of a |
| 880 | @code{delay-mode-hooks} form, this function does not run any hooks. | 871 | @code{delay-mode-hooks} form, it does not run the hooks immediately. |
| 881 | Instead, it arranges for the next call to @code{run-mode-hooks} to run | 872 | Instead, it arranges for the next call to @code{run-mode-hooks} to run |
| 882 | @var{hookvars}. | 873 | them. |
| 883 | @end defun | 874 | @end defun |
| 884 | 875 | ||
| 885 | @defmac delay-mode-hooks body@dots{} | 876 | @defmac delay-mode-hooks body@dots{} |
| 886 | This macro executes @var{body} like @code{progn}, but all calls to | 877 | When one major mode command calls another, it should do so inside of |
| 887 | @code{run-mode-hooks} inside @var{body} delay running their hooks. | 878 | @code{delay-mode-hooks}. |
| 888 | They will be run by the first call to @code{run-mode-hooks} after exit | 879 | |
| 889 | from @code{delay-mode-hooks}. This is the proper way for a major mode | 880 | This macro executes @var{body}, but tells all @code{run-mode-hooks} |
| 890 | command to invoke its parent mode. | 881 | calls during the execution of @var{body} to delay running their hooks. |
| 882 | The hooks will actually run during the next call to | ||
| 883 | @code{run-mode-hooks} after the end of the @code{delay-mode-hooks} | ||
| 884 | construct. | ||
| 891 | @end defmac | 885 | @end defmac |
| 892 | 886 | ||
| 893 | @defvar after-change-major-mode-hook | 887 | @defvar after-change-major-mode-hook |
| 894 | Every major mode function should run this normal hook at its very end. | 888 | This is a normal hook run by @code{run-mode-hooks}. It is run at the |
| 895 | It normally does not need to do so explicitly. Indeed, a major mode | 889 | very end of every properly-written major mode function. |
| 896 | function should normally run its mode hook with @code{run-mode-hooks} | ||
| 897 | as the very last thing it does, and the last thing | ||
| 898 | @code{run-mode-hooks} does is run @code{after-change-major-mode-hook}. | ||
| 899 | @end defvar | 890 | @end defvar |
| 900 | 891 | ||
| 901 | @node Example Major Modes | 892 | @node Example Major Modes |
| @@ -1058,9 +1049,8 @@ correspondingly more complicated. Here are excerpts from | |||
| 1058 | @end group | 1049 | @end group |
| 1059 | @end smallexample | 1050 | @end smallexample |
| 1060 | 1051 | ||
| 1061 | Much code is shared among the three Lisp modes. The following | 1052 | The three modes for Lisp share much of their code. For instance, |
| 1062 | function sets various variables; it is called by each of the major Lisp | 1053 | each calls the following function to set various variables: |
| 1063 | mode functions: | ||
| 1064 | 1054 | ||
| 1065 | @smallexample | 1055 | @smallexample |
| 1066 | @group | 1056 | @group |
| @@ -1072,13 +1062,10 @@ mode functions: | |||
| 1072 | @end group | 1062 | @end group |
| 1073 | @end smallexample | 1063 | @end smallexample |
| 1074 | 1064 | ||
| 1075 | Functions such as @code{forward-paragraph} use the value of the | 1065 | In Lisp and most programming languages, we want the paragraph |
| 1076 | @code{paragraph-start} variable. Since Lisp code is different from | 1066 | commands to treat only blank lines as paragraph separators. And the |
| 1077 | ordinary text, the @code{paragraph-start} variable needs to be set | 1067 | modes should undestand the Lisp conventions for comments. The rest of |
| 1078 | specially to handle Lisp. Also, comments are indented in a special | 1068 | @code{lisp-mode-variables} sets this up: |
| 1079 | fashion in Lisp and the Lisp modes need their own mode-specific | ||
| 1080 | @code{comment-indent-function}. The code to set these variables is the | ||
| 1081 | rest of @code{lisp-mode-variables}. | ||
| 1082 | 1069 | ||
| 1083 | @smallexample | 1070 | @smallexample |
| 1084 | @group | 1071 | @group |