aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2006-08-08 17:39:08 +0000
committerRichard M. Stallman2006-08-08 17:39:08 +0000
commit02a2b2ad4f23b253380485eca654bf4b338d0855 (patch)
tree57a2da0bcc5ecc575a893c0adedbe80e2ea0eccd
parent08e5fcf12acce1b89b667e552a2d8f23e34c2423 (diff)
downloademacs-02a2b2ad4f23b253380485eca654bf4b338d0855.tar.gz
emacs-02a2b2ad4f23b253380485eca654bf4b338d0855.zip
Clean up wording in previous change.
-rw-r--r--lispref/ChangeLog4
-rw-r--r--lispref/modes.texi179
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 @@
12006-08-08 Richard Stallman <rms@gnu.org>
2
3 * modes.texi: Clean up wording in previous change.
4
12006-08-07 Chong Yidong <cyd@stupidchicken.com> 52006-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.
52the @dfn{mode hook} as the one of the last steps of initialization. 52the @dfn{mode hook} as the one of the last steps of initialization.
53This makes it easy for a user to customize the behavior of the mode, 53This makes it easy for a user to customize the behavior of the mode,
54by overriding the buffer-local variable assignments already made by 54by overriding the buffer-local variable assignments already made by
55the mode. Most minor modes also run a mode hook at their end. But 55the mode. Most minor mode functions also run a mode hook at the end.
56hooks are used in other contexts too. For example, the hook 56But 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
69indicates it is probably an @dfn{abnormal hook}. Then you should look at its 69indicates it is probably an @dfn{abnormal hook}. That means the hook
70documentation to see how to use the hook properly. 70functions are called with arguments, or their return values are used
71in some way. The hook's documentation says how the functions are
72called. You can use @code{add-hook} to add a function to an abnormal
73hook, but you must write the function to follow the hook's calling
74convention.
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
73with arguments, or the return values are used in some way. By 77@samp{-hooks}. If the variable's name ends in @samp{-function}, then
74convention, abnormal hook names end in @samp{-functions} or 78its 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
76list, but you must take care in writing the function.
77
78 If the variable's name ends in @samp{-function}, then its value
79is 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
82in Lisp Interaction mode: 81in Lisp Interaction mode:
@@ -95,12 +94,12 @@ symbol that is a normal hook variable. These arguments are processed
95in the order specified. 94in the order specified.
96 95
97If a hook variable has a non-@code{nil} value, that value should be a 96If a hook variable has a non-@code{nil} value, that value should be a
98list of functions. Each function in this list is called, 97list of functions. @code{run-hooks} calls all the functions, one by
99consecutively, with no arguments. 98one, with no arguments.
100 99
101A hook variable can also be a single function (either a lambda 100The hook variable's value can also be a single function---either a
102expression or a symbol with a function definition) to be called. This 101lambda expression or a symbol with a function definition---which
103use 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
359Major modes modes for editing text should not define @key{RET} to do 358Major modes modes for editing text should not define @key{RET} to do
360anything other than insert a newline. The command to insert a newline 359anything other than insert a newline. However, it is ok for
361and then indent is @kbd{C-j}. It is ok for more specialized modes, 360specialized modes for text that users don't directly edit, such as
362such as Info mode, to redefine @key{RET} to something else. 361Dired and Info modes, to redefine @key{RET} to do something entirely
362different.
363 363
364@item 364@item
365Major modes should not alter options that are primarily a matter of user 365Major 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
805comment syntax and Font Lock mode. To define a generic mode, use the 805comment syntax and Font Lock mode. To define a generic mode, use the
806macro @code{define-generic-mode}. See the file @file{generic-x.el} 806macro @code{define-generic-mode}. See the file @file{generic-x.el}
807for some examples of the use of @code{define-generic-mode}. 807for 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
810This macro creates a new generic mode. The argument @var{mode} (an 810This macro defines a generic mode command named @var{mode} (a symbol,
811unquoted symbol) is the major mode command. The optional argument 811not quoted). The optional argument @var{docstring} is the
812@var{docstring} is the documentation for the mode command. If you do 812documentation for the mode command. If you do not supply it,
813not supply it, @code{define-generic-mode} uses a default documentation 813@code{define-generic-mode} generates one by default.
814string instead. 814
815 815The 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 816either a character, a string of one or two characters, or a cons cell.
817character, a string of one or two characters, or a cons cell. A 817A character or a string is set up in the mode's syntax table as a
818character 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
820up as a ``comment starter'' and the @sc{cdr} as a ``comment ender.'' 819up 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
822of the line.) Note that the syntax table has limitations about what 821of the line.) Note that the syntax table mechanism has limitations
823comment starters and enders are actually possible. @xref{Syntax 822about what comment starters and enders are actually possible.
824Tables}. 823@xref{Syntax Tables}.
825 824
826@var{keyword-list} is a list of keywords to highlight with 825The argument @var{keyword-list} is a list of keywords to highlight
827@code{font-lock-keyword-face}. Each keyword should be a string. 826with @code{font-lock-keyword-face}. Each keyword should be a string.
828@var{font-lock-list} is a list of additional expressions to highlight. 827Meanwhile, @var{font-lock-list} is a list of additional expressions to
829Each element of this list should have the same form as an element of 828highlight. Each element of this list should have the same form as an
830@code{font-lock-keywords}. @xref{Search-based Fontification}. 829element of @code{font-lock-keywords}. @xref{Search-based
831 830Fontification}.
832@var{auto-mode-list} is a list of regular expressions to add to the 831
833variable @code{auto-mode-alist}. These regular expressions are added 832The argument @var{auto-mode-list} is a list of regular expressions to
834when Emacs runs the macro expansion. 833add to the variable @code{auto-mode-alist}. They are added by the execution
835 834of 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
837additional setup. The mode command calls these functions just before 836Finally, @var{function-list} is a list of functions for the mode
838it runs the mode hook variable @code{@var{mode}-hook}. 837command to call for additional setup. It calls these functions just
838before 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
845hook and finally the mode independent normal hook 845the mode-independent normal hook @code{after-change-major-mode-hook}.
846@code{after-change-major-mode-hook}. If the major mode is a derived 846It does this by calling @code{run-mode-hooks}. If the major mode is a
847mode, that is if it calls another major mode (the parent mode) in its 847derived mode, that is if it calls another major mode (the parent mode)
848body, then the parent's mode hook is run just before the derived 848in its body, it should do this inside @code{delay-mode-hooks} so that
849mode's hook. Neither the parent's mode hook nor 849the 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 850call to @code{run-mode-hooks} runs the parent's mode hook too.
851call to the parent mode. This applies recursively if the parent mode 851@xref{Major Mode Conventions}.
852has itself a parent. That is, the mode hooks of all major modes 852
853called directly or indirectly by the major mode function are all run 853 Emacs versions before Emacs 22 did not have @code{delay-mode-hooks}.
854in sequence at the end, just before 854When user-implemented major modes have not been updated to use it,
855@code{after-change-major-mode-hook}. 855they won't entirely follow these conventions: they may run the
856 856parent'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
858implemented by users do not follow them yet. So if you put a function 858mode, please correct it to follow these conventions.
859onto @code{after-change-major-mode-hook}, keep in mind that some modes
860will 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
862fails to work. Please fix the major mode.'' In most cases, that is
863good enough, so go ahead and use @code{after-change-major-mode-hook}.
864However, if a certain feature needs to be completely reliable,
865it 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
868automatically makes sure these conventions are followed. If you 861automatically makes sure these conventions are followed. If you
869define a major mode ``from scratch,'' not using 862define a major mode ``by hand,'' not using @code{define-derived-mode},
870@code{define-derived-mode}, make sure the major mode command follows 863use the following functions to handle these conventions automatically.
871these and other conventions. @xref{Major Mode Conventions}. You use
872these functions to do it properly.
873 864
874@defun run-mode-hooks &rest hookvars 865@defun run-mode-hooks &rest hookvars
875Major modes should run their mode hook using this function. It is 866Major modes should run their mode hook using this function. It is
876similar to @code{run-hooks} (@pxref{Hooks}), but it also runs 867similar 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
879When the call to this function is dynamically inside a 870When 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.
881Instead, it arranges for the next call to @code{run-mode-hooks} to run 872Instead, it arranges for the next call to @code{run-mode-hooks} to run
882@var{hookvars}. 873them.
883@end defun 874@end defun
884 875
885@defmac delay-mode-hooks body@dots{} 876@defmac delay-mode-hooks body@dots{}
886This macro executes @var{body} like @code{progn}, but all calls to 877When 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}.
888They will be run by the first call to @code{run-mode-hooks} after exit 879
889from @code{delay-mode-hooks}. This is the proper way for a major mode 880This macro executes @var{body}, but tells all @code{run-mode-hooks}
890command to invoke its parent mode. 881calls during the execution of @var{body} to delay running their hooks.
882The hooks will actually run during the next call to
883@code{run-mode-hooks} after the end of the @code{delay-mode-hooks}
884construct.
891@end defmac 885@end defmac
892 886
893@defvar after-change-major-mode-hook 887@defvar after-change-major-mode-hook
894Every major mode function should run this normal hook at its very end. 888This is a normal hook run by @code{run-mode-hooks}. It is run at the
895It normally does not need to do so explicitly. Indeed, a major mode 889very end of every properly-written major mode function.
896function should normally run its mode hook with @code{run-mode-hooks}
897as 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,
1062function sets various variables; it is called by each of the major Lisp 1053each calls the following function to set various variables:
1063mode 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 1066commands to treat only blank lines as paragraph separators. And the
1077ordinary text, the @code{paragraph-start} variable needs to be set 1067modes should undestand the Lisp conventions for comments. The rest of
1078specially to handle Lisp. Also, comments are indented in a special 1068@code{lisp-mode-variables} sets this up:
1079fashion in Lisp and the Lisp modes need their own mode-specific
1080@code{comment-indent-function}. The code to set these variables is the
1081rest of @code{lisp-mode-variables}.
1082 1069
1083@smallexample 1070@smallexample
1084@group 1071@group