diff options
| author | Chong Yidong | 2011-05-28 14:22:08 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-05-28 14:22:08 -0400 |
| commit | bf41276f9c9a6534a5deb1b44a5d84d9a30ccb4c (patch) | |
| tree | 84c106bde7aacebe253cdda5324755b274f10c3f | |
| parent | 6a639b16edf80d8255f64e9875eebd6755f32e66 (diff) | |
| download | emacs-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/ChangeLog | 7 | ||||
| -rw-r--r-- | doc/emacs/custom.texi | 89 | ||||
| -rw-r--r-- | doc/emacs/fixit.texi | 8 |
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 @@ | |||
| 1 | 2011-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 | |||
| 1 | 2011-05-27 Glenn Morris <rgm@gnu.org> | 8 | 2011-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}). | |||
| 888 | hook is a Lisp variable which holds a list of functions, to be called | 888 | hook is a Lisp variable which holds a list of functions, to be called |
| 889 | on some well-defined occasion. (This is called @dfn{running the | 889 | on some well-defined occasion. (This is called @dfn{running the |
| 890 | hook}.) The individual functions in the list are called the @dfn{hook | 890 | hook}.) The individual functions in the list are called the @dfn{hook |
| 891 | functions} of the hook. With rare exceptions, hooks in Emacs are | 891 | functions} of the hook. For example, the hook @code{kill-emacs-hook} |
| 892 | empty when Emacs starts up, so the only hook functions in any given | 892 | runs just before exiting Emacs (@pxref{Exiting}). |
| 893 | hook 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 | ||
| 896 | of initialization. This makes it easy for you to customize the | ||
| 897 | behavior of the mode, by setting up a hook function to override the | ||
| 898 | local variable assignments already made by the mode. But hooks are | ||
| 899 | also 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 |
| 905 | hook operates by calling all the hook functions, unconditionally, with | 896 | the hook, it calls each hook function in turn, with no arguments. We |
| 906 | no arguments. We have made an effort to keep most hooks normal so that | 897 | have made an effort to keep most hooks normal, so that you can use |
| 907 | you can use them in a uniform way. Every variable in Emacs whose name | 898 | them in a uniform way. Every variable whose name ends in @samp{-hook} |
| 908 | ends in @samp{-hook} is a normal hook. | 899 | is 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 |
| 912 | in @samp{-hooks} or @samp{-functions}, instead of @samp{-hook}. What | 903 | @samp{-hooks} or @samp{-functions}, instead of @samp{-hook}. What |
| 913 | makes these hooks abnormal is that there is something peculiar about the | 904 | makes these hooks abnormal is the way its functions are |
| 914 | way its functions are called---perhaps they are given arguments, or | 905 | called---perhaps they are given arguments, or perhaps the values they |
| 915 | perhaps the values they return are used in some way. For example, | 906 | return 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 |
| 917 | as soon as one hook function returns a non-@code{nil} value, the rest | 908 | one hook function returns a non-@code{nil} value, the rest are not |
| 918 | are not called at all. The documentation of each abnormal hook variable | 909 | called at all (@pxref{Visiting}). The documentation of each abnormal |
| 919 | explains in detail what is peculiar about it. | 910 | hook 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 |
| 923 | variable, but the recommended way to add a hook function to a hook | 914 | variable, but the recommended way to add a function to a hook (either |
| 924 | (either normal or abnormal) is by calling @code{add-hook}. | 915 | normal or abnormal) is to use @code{add-hook}, as shown by the |
| 925 | @xref{Hooks,,, elisp, The Emacs Lisp Reference Manual}. | 916 | following examples. @xref{Hooks,,, elisp, The Emacs Lisp Reference |
| 917 | Manual}, 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 |
| 928 | when entering Text mode and other modes based on Text mode: | 920 | of initialization. Mode hooks are a convenient way to customize the |
| 921 | behavior of individual modes; they are always normal. For example, | ||
| 922 | here's how to set up a hook to turn on Auto Fill mode when entering | ||
| 923 | Text 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 |
| 935 | of C code. (People often have strong personal preferences for one | 930 | indentation of C code. The hook function uses an anonymous lambda |
| 936 | format compared to another.) Here the hook function is an anonymous | 931 | expression (@pxref{Lambda Expressions,,, elisp, The Emacs Lisp |
| 937 | lambda expression. | 932 | Reference 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 | ||
| 954 | the original mode (@pxref{Derived Modes,,, elisp, The Emacs Lisp | ||
| 955 | Reference Manual}). For instance, HTML mode (@pxref{HTML Mode}) | ||
| 956 | inherits from Text mode; when HTML mode is enabled, it runs | ||
| 957 | @code{text-mode-hook} before running @code{html-mode-hook}. This | ||
| 958 | provides a convenient way to use a single hook to affect several | ||
| 959 | related modes. In particular, if you want to apply a hook function to | ||
| 960 | any programming language mode, add it to @code{prog-mode-hook}; Prog | ||
| 961 | mode is a major mode that does little else than to let other major | ||
| 962 | modes 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 |
| 962 | they are executed does not matter. Any dependence on the order is | 965 | they are executed does not matter. Any dependence on the order is |
| 963 | ``asking for trouble.'' However, the order is predictable: the most | 966 | asking for trouble. However, the order is predictable: the hook |
| 964 | recently added hook functions are executed first. | 967 | functions 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 |
| 404 | in Emacs. It operates by checking words as you change or insert them. | 405 | in Emacs. It operates by checking words as you change or insert them. |
| 405 | When it finds a word that it does not recognize, it highlights that | 406 | When it finds a word that it does not recognize, it highlights that |
| 406 | word. This does not interfere with your editing, but when you see the | 407 | word. This does not interfere with your editing, but when you see the |
| 407 | highlighted word, you can move to it and fix it. Type @kbd{M-x | 408 | highlighted word, you can move to it and fix it. Type @kbd{M-x |
| 408 | flyspell-mode} to enable or disable this mode in the current buffer. | 409 | flyspell-mode} to enable or disable this mode in the current buffer. |
| 409 | @findex turn-on-flyspell | 410 | To enable Flyspell mode in all text mode buffers, add |
| 410 | To 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 |
| 415 | it with @kbd{Mouse-2} to display a menu of possible corrections and | 414 | it with @kbd{Mouse-2} to display a menu of possible corrections and |
| 416 | actions. You can also correct the word by editing it manually in any | 415 | actions. You can also correct the word by editing it manually in any |
| @@ -421,4 +420,5 @@ way you like. | |||
| 421 | that it only checks words in comments and string constants. This | 420 | that it only checks words in comments and string constants. This |
| 422 | feature is useful for editing programs. Type @kbd{M-x | 421 | feature is useful for editing programs. Type @kbd{M-x |
| 423 | flyspell-prog-mode} to enable or disable this mode in the current | 422 | flyspell-prog-mode} to enable or disable this mode in the current |
| 424 | buffer. | 423 | buffer. To enable this mode in all programming mode buffers, add |
| 424 | @code{flyspell-prog-mode} to @code{prog-mode-hook} (@pxref{Hooks}). | ||