aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-05-28 14:22:08 -0400
committerChong Yidong2011-05-28 14:22:08 -0400
commitbf41276f9c9a6534a5deb1b44a5d84d9a30ccb4c (patch)
tree84c106bde7aacebe253cdda5324755b274f10c3f
parent6a639b16edf80d8255f64e9875eebd6755f32e66 (diff)
downloademacs-bf41276f9c9a6534a5deb1b44a5d84d9a30ccb4c.tar.gz
emacs-bf41276f9c9a6534a5deb1b44a5d84d9a30ccb4c.zip
Document prog-mode-hook in Emacs manual.
* custom.texi (Hooks): Reorganize. Mention Prog mode. * fixit.texi (Spelling): Mention using prog-mode-hook for flypsell prog mode (Bug#8240).
-rw-r--r--doc/emacs/ChangeLog7
-rw-r--r--doc/emacs/custom.texi89
-rw-r--r--doc/emacs/fixit.texi8
3 files changed, 57 insertions, 47 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index d2f2c23ee3d..89a78263e94 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,10 @@
12011-05-28 Chong Yidong <cyd@stupidchicken.com>
2
3 * custom.texi (Hooks): Reorganize. Mention Prog mode.
4
5 * fixit.texi (Spelling): Mention using prog-mode-hook for flypsell
6 prog mode (Bug#8240).
7
12011-05-27 Glenn Morris <rgm@gnu.org> 82011-05-27 Glenn Morris <rgm@gnu.org>
2 9
3 * custom.texi (Specifying File Variables): 10 * custom.texi (Specifying File Variables):
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 9add95a5b48..a0dce5b3216 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -888,53 +888,48 @@ your initialization file to set it those sessions (@pxref{Init File}).
888hook is a Lisp variable which holds a list of functions, to be called 888hook is a Lisp variable which holds a list of functions, to be called
889on some well-defined occasion. (This is called @dfn{running the 889on some well-defined occasion. (This is called @dfn{running the
890hook}.) The individual functions in the list are called the @dfn{hook 890hook}.) The individual functions in the list are called the @dfn{hook
891functions} of the hook. With rare exceptions, hooks in Emacs are 891functions} of the hook. For example, the hook @code{kill-emacs-hook}
892empty when Emacs starts up, so the only hook functions in any given 892runs just before exiting Emacs (@pxref{Exiting}).
893hook are the ones you explicitly put there as customization.
894
895 Most major modes run one or more @dfn{mode hooks} as the last step
896of initialization. This makes it easy for you to customize the
897behavior of the mode, by setting up a hook function to override the
898local variable assignments already made by the mode. But hooks are
899also used in other contexts. For example, the hook
900@code{kill-emacs-hook} runs just before quitting the Emacs job
901(@pxref{Exiting}).
902 893
903@cindex normal hook 894@cindex normal hook
904 Most Emacs hooks are @dfn{normal hooks}. This means that running the 895 Most hooks are @dfn{normal hooks}. This means that when Emacs runs
905hook operates by calling all the hook functions, unconditionally, with 896the hook, it calls each hook function in turn, with no arguments. We
906no arguments. We have made an effort to keep most hooks normal so that 897have made an effort to keep most hooks normal, so that you can use
907you can use them in a uniform way. Every variable in Emacs whose name 898them in a uniform way. Every variable whose name ends in @samp{-hook}
908ends in @samp{-hook} is a normal hook. 899is a normal hook.
909 900
910@cindex abnormal hook 901@cindex abnormal hook
911 There are also a few @dfn{abnormal hooks}. These variables' names end 902 A few hooks are @dfn{abnormal hooks}. Their names end in
912in @samp{-hooks} or @samp{-functions}, instead of @samp{-hook}. What 903@samp{-hooks} or @samp{-functions}, instead of @samp{-hook}. What
913makes these hooks abnormal is that there is something peculiar about the 904makes these hooks abnormal is the way its functions are
914way its functions are called---perhaps they are given arguments, or 905called---perhaps they are given arguments, or perhaps the values they
915perhaps the values they return are used in some way. For example, 906return are used in some way. For example,
916@code{find-file-not-found-functions} (@pxref{Visiting}) is abnormal because 907@code{find-file-not-found-functions} is abnormal because as soon as
917as soon as one hook function returns a non-@code{nil} value, the rest 908one hook function returns a non-@code{nil} value, the rest are not
918are not called at all. The documentation of each abnormal hook variable 909called at all (@pxref{Visiting}). The documentation of each abnormal
919explains in detail what is peculiar about it. 910hook variable explains how its functions are used.
920 911
921@findex add-hook 912@findex add-hook
922 You can set a hook variable with @code{setq} like any other Lisp 913 You can set a hook variable with @code{setq} like any other Lisp
923variable, but the recommended way to add a hook function to a hook 914variable, but the recommended way to add a function to a hook (either
924(either normal or abnormal) is by calling @code{add-hook}. 915normal or abnormal) is to use @code{add-hook}, as shown by the
925@xref{Hooks,,, elisp, The Emacs Lisp Reference Manual}. 916following examples. @xref{Hooks,,, elisp, The Emacs Lisp Reference
917Manual}, for details.
926 918
927 For example, here's how to set up a hook to turn on Auto Fill mode 919 Most major modes run one or more @dfn{mode hooks} as the last step
928when entering Text mode and other modes based on Text mode: 920of initialization. Mode hooks are a convenient way to customize the
921behavior of individual modes; they are always normal. For example,
922here's how to set up a hook to turn on Auto Fill mode when entering
923Text mode and other modes based on Text mode:
929 924
930@example 925@example
931(add-hook 'text-mode-hook 'turn-on-auto-fill) 926(add-hook 'text-mode-hook 'turn-on-auto-fill)
932@end example 927@end example
933 928
934 The next example shows how to use a hook to customize the indentation 929 Here is another example, showing how to use a hook to customize the
935of C code. (People often have strong personal preferences for one 930indentation of C code. The hook function uses an anonymous lambda
936format compared to another.) Here the hook function is an anonymous 931expression (@pxref{Lambda Expressions,,, elisp, The Emacs Lisp
937lambda expression. 932Reference Manual}).
938 933
939@example 934@example
940@group 935@group
@@ -944,24 +939,32 @@ lambda expression.
944@group 939@group
945 (c-cleanup-list . (scope-operator 940 (c-cleanup-list . (scope-operator
946 empty-defun-braces 941 empty-defun-braces
947 defun-close-semi)) 942 defun-close-semi))))
948@end group
949@group
950 (c-offsets-alist . ((arglist-close . c-lineup-arglist)
951 (substatement-open . 0)))))
952@end group 943@end group
953 944
954@group 945@group
955(add-hook 'c-mode-common-hook 946(add-hook 'c-mode-common-hook
956 '(lambda () 947 (lambda () (c-add-style "my-style" my-c-style t)))
957 (c-add-style "my-style" my-c-style t)))
958@end group 948@end group
959@end example 949@end example
960 950
951@cindex Prog mode
952@cindex program editing
953 Major mode hooks also apply to other major modes @dfn{derived} from
954the original mode (@pxref{Derived Modes,,, elisp, The Emacs Lisp
955Reference Manual}). For instance, HTML mode (@pxref{HTML Mode})
956inherits from Text mode; when HTML mode is enabled, it runs
957@code{text-mode-hook} before running @code{html-mode-hook}. This
958provides a convenient way to use a single hook to affect several
959related modes. In particular, if you want to apply a hook function to
960any programming language mode, add it to @code{prog-mode-hook}; Prog
961mode is a major mode that does little else than to let other major
962modes inherit from it, exactly for this purpose.
963
961 It is best to design your hook functions so that the order in which 964 It is best to design your hook functions so that the order in which
962they are executed does not matter. Any dependence on the order is 965they are executed does not matter. Any dependence on the order is
963``asking for trouble.'' However, the order is predictable: the most 966asking for trouble. However, the order is predictable: the hook
964recently added hook functions are executed first. 967functions are executed in the order they appear in the hook.
965 968
966@findex remove-hook 969@findex remove-hook
967 If you play with adding various different versions of a hook 970 If you play with adding various different versions of a hook
diff --git a/doc/emacs/fixit.texi b/doc/emacs/fixit.texi
index 0c9cc829fc3..c14041f2271 100644
--- a/doc/emacs/fixit.texi
+++ b/doc/emacs/fixit.texi
@@ -400,17 +400,16 @@ is a spell checking dictionary but no word completion dictionary.
400 400
401@cindex Flyspell mode 401@cindex Flyspell mode
402@findex flyspell-mode 402@findex flyspell-mode
403@findex turn-on-flyspell
403 Flyspell mode is a fully-automatic way to check spelling as you edit 404 Flyspell mode is a fully-automatic way to check spelling as you edit
404in Emacs. It operates by checking words as you change or insert them. 405in Emacs. It operates by checking words as you change or insert them.
405When it finds a word that it does not recognize, it highlights that 406When it finds a word that it does not recognize, it highlights that
406word. This does not interfere with your editing, but when you see the 407word. This does not interfere with your editing, but when you see the
407highlighted word, you can move to it and fix it. Type @kbd{M-x 408highlighted word, you can move to it and fix it. Type @kbd{M-x
408flyspell-mode} to enable or disable this mode in the current buffer. 409flyspell-mode} to enable or disable this mode in the current buffer.
409@findex turn-on-flyspell 410To enable Flyspell mode in all text mode buffers, add
410To enable @code{flyspell-mode} in all text mode buffers, add
411@code{turn-on-flyspell} to @code{text-mode-hook}. 411@code{turn-on-flyspell} to @code{text-mode-hook}.
412 412
413
414 When Flyspell mode highlights a word as misspelled, you can click on 413 When Flyspell mode highlights a word as misspelled, you can click on
415it with @kbd{Mouse-2} to display a menu of possible corrections and 414it with @kbd{Mouse-2} to display a menu of possible corrections and
416actions. You can also correct the word by editing it manually in any 415actions. You can also correct the word by editing it manually in any
@@ -421,4 +420,5 @@ way you like.
421that it only checks words in comments and string constants. This 420that it only checks words in comments and string constants. This
422feature is useful for editing programs. Type @kbd{M-x 421feature is useful for editing programs. Type @kbd{M-x
423flyspell-prog-mode} to enable or disable this mode in the current 422flyspell-prog-mode} to enable or disable this mode in the current
424buffer. 423buffer. To enable this mode in all programming mode buffers, add
424@code{flyspell-prog-mode} to @code{prog-mode-hook} (@pxref{Hooks}).