diff options
| author | Luc Teirlinck | 2004-09-25 02:21:51 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2004-09-25 02:21:51 +0000 |
| commit | a3ee0299ed17ade533b0b668fd274fff48811c5d (patch) | |
| tree | 4faa209e393d0fea89f124b0db74dcd2c34d6bd7 | |
| parent | 45c9a0f754636bccb041c1414136546101e839a0 (diff) | |
| download | emacs-a3ee0299ed17ade533b0b668fd274fff48811c5d.tar.gz emacs-a3ee0299ed17ade533b0b668fd274fff48811c5d.zip | |
Various minor changes in addition to:
(Major Mode Conventions): Final call to `run-mode-hooks' should
not be inside the `delay-mode-hooks' form.
(Mode Hooks): New node.
(Hooks): Delete obsolete example.
Move definitions of `run-mode-hooks' and `delay-mode-hooks' to new
node "Mode Hooks".
| -rw-r--r-- | lispref/ChangeLog | 10 | ||||
| -rw-r--r-- | lispref/modes.texi | 89 |
2 files changed, 73 insertions, 26 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog index 2dd35cd1844..a7681ddfbf0 100644 --- a/lispref/ChangeLog +++ b/lispref/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2004-09-24 Luc Teirlinck <teirllm@auburn.edu> | ||
| 2 | |||
| 3 | * modes.texi: Various minor changes in addition to: | ||
| 4 | (Major Mode Conventions): Final call to `run-mode-hooks' should | ||
| 5 | not be inside the `delay-mode-hooks' form. | ||
| 6 | (Mode Hooks): New node. | ||
| 7 | (Hooks): Delete obsolete example. | ||
| 8 | Move definitions of `run-mode-hooks' and `delay-mode-hooks' to new | ||
| 9 | node "Mode Hooks". | ||
| 10 | |||
| 1 | 2004-09-22 Luc Teirlinck <teirllm@auburn.edu> | 11 | 2004-09-22 Luc Teirlinck <teirllm@auburn.edu> |
| 2 | 12 | ||
| 3 | * display.texi: Correct various typos. | 13 | * display.texi: Correct various typos. |
diff --git a/lispref/modes.texi b/lispref/modes.texi index 78b8fc440d7..f74f7c89da7 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | @c -*-texinfo-*- | 1 | @c -*-texinfo-*- |
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | 2 | @c This is part of the GNU Emacs Lisp Reference Manual. |
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003 | 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003, 2004 |
| 4 | @c Free Software Foundation, Inc. | 4 | @c Free Software Foundation, Inc. |
| 5 | @c See the file elisp.texi for copying conditions. | 5 | @c See the file elisp.texi for copying conditions. |
| 6 | @setfilename ../info/modes | 6 | @setfilename ../info/modes |
| @@ -103,6 +103,7 @@ Fundamental mode. Rmail mode is a complicated and specialized mode. | |||
| 103 | * Mode Help:: Finding out how to use a mode. | 103 | * Mode Help:: Finding out how to use a mode. |
| 104 | * Derived Modes:: Defining a new major mode based on another major | 104 | * Derived Modes:: Defining a new major mode based on another major |
| 105 | mode. | 105 | mode. |
| 106 | * Mode Hooks:: Hooks run at the end of major mode functions. | ||
| 106 | @end menu | 107 | @end menu |
| 107 | 108 | ||
| 108 | @node Major Mode Conventions | 109 | @node Major Mode Conventions |
| @@ -276,7 +277,7 @@ other packages would interfere with them. | |||
| 276 | Each major mode should have a @dfn{mode hook} named | 277 | Each major mode should have a @dfn{mode hook} named |
| 277 | @code{@var{modename}-mode-hook}. The major mode command should run that | 278 | @code{@var{modename}-mode-hook}. The major mode command should run that |
| 278 | hook, with @code{run-mode-hooks}, as the very last thing it | 279 | hook, with @code{run-mode-hooks}, as the very last thing it |
| 279 | does. @xref{Hooks}. | 280 | does. @xref{Mode Hooks}. |
| 280 | 281 | ||
| 281 | @item | 282 | @item |
| 282 | The major mode command may start by calling some other major mode | 283 | The major mode command may start by calling some other major mode |
| @@ -284,9 +285,11 @@ command (called the @dfn{parent mode}) and then alter some of its | |||
| 284 | settings. A mode that does this is called a @dfn{derived mode}. The | 285 | settings. A mode that does this is called a @dfn{derived mode}. The |
| 285 | recommended way to define one is to use @code{define-derived-mode}, | 286 | recommended way to define one is to use @code{define-derived-mode}, |
| 286 | but this is not required. Such a mode should use | 287 | but this is not required. Such a mode should use |
| 287 | @code{delay-mode-hooks} around its entire body, including the call to | 288 | @code{delay-mode-hooks} around its entire body (including the call to |
| 288 | the parent mode command and the final call to @code{run-mode-hooks}. | 289 | the parent mode command) @emph{except} for the final call to |
| 289 | (Using @code{define-derived-mode} does this automatically.) | 290 | @code{run-mode-hooks}, which runs the derived mode's hook. (Using |
| 291 | @code{define-derived-mode} does this automatically.) @xref{Derived | ||
| 292 | Modes}, and @ref{Mode Hooks}. | ||
| 290 | 293 | ||
| 291 | @item | 294 | @item |
| 292 | If something special should be done if the user switches a buffer from | 295 | If something special should be done if the user switches a buffer from |
| @@ -575,7 +578,7 @@ visited. It also processes local variables specified in the file text. | |||
| 575 | in particular. Other major modes are defined in effect by comparison | 578 | in particular. Other major modes are defined in effect by comparison |
| 576 | with this one---their definitions say what to change, starting from | 579 | with this one---their definitions say what to change, starting from |
| 577 | Fundamental mode. The @code{fundamental-mode} function does @emph{not} | 580 | Fundamental mode. The @code{fundamental-mode} function does @emph{not} |
| 578 | run any hooks; you're not supposed to customize it. (If you want Emacs | 581 | run any mode hooks; you're not supposed to customize it. (If you want Emacs |
| 579 | to behave differently in Fundamental mode, change the @emph{global} | 582 | to behave differently in Fundamental mode, change the @emph{global} |
| 580 | state of Emacs.) | 583 | state of Emacs.) |
| 581 | @end deffn | 584 | @end deffn |
| @@ -808,6 +811,58 @@ Do not write an @code{interactive} spec in the definition; | |||
| 808 | @code{define-derived-mode} does that automatically. | 811 | @code{define-derived-mode} does that automatically. |
| 809 | @end defmac | 812 | @end defmac |
| 810 | 813 | ||
| 814 | @node Mode Hooks | ||
| 815 | @subsection Mode Hooks | ||
| 816 | |||
| 817 | The two last things a major mode function does is to run its mode | ||
| 818 | hook and finally the mode independent normal hook | ||
| 819 | @code{after-change-major-mode-hook}. If the major mode is a derived | ||
| 820 | mode, that is if it calls another major mode (the parent mode) in its | ||
| 821 | body, then the parent's mode hook is run just before the derived | ||
| 822 | mode's hook. Neither the parent's mode hook nor | ||
| 823 | @code{after-change-major-mode-hook} are run at the end of the actual | ||
| 824 | call to the parent mode. This applies recursively if the parent mode | ||
| 825 | has itself a parent. That is, the mode hooks of all major modes called | ||
| 826 | directly or indirectly by the major mode function are all run in | ||
| 827 | sequence at the end, just before @code{after-change-major-mode-hook}. | ||
| 828 | |||
| 829 | If you are customizing a major mode, rather than defining one, the | ||
| 830 | above is all you need to know about the hooks run at the end of a | ||
| 831 | major mode. This also applies if you use @code{define-derived-mode} | ||
| 832 | to define a major mode, because that macro will automatically | ||
| 833 | implement the above for you. | ||
| 834 | |||
| 835 | Programmers wishing to define a major mode without using | ||
| 836 | @code{define-derived-mode}, should make sure that their major mode | ||
| 837 | follows the above conventions. @xref{Major Mode Conventions}, for how | ||
| 838 | this should be accomplished. Below, we give some implementation | ||
| 839 | details. | ||
| 840 | |||
| 841 | @defun run-mode-hooks &rest hookvars | ||
| 842 | Major modes should run their mode hook using this function. It is | ||
| 843 | similar to @code{run-hooks} (@pxref{Hooks}), but if run inside a | ||
| 844 | @code{delay-mode-hooks} form, this function does not run any hooks. | ||
| 845 | Instead, it arranges for @var{hookvars} to be run at a later call to | ||
| 846 | the function. Otherwise, @code{run-mode-hooks} runs any delayed hooks | ||
| 847 | in order, then @var{hookvars} and finally | ||
| 848 | @code{after-change-major-mode-hook}. | ||
| 849 | @end defun | ||
| 850 | |||
| 851 | @defmac delay-mode-hooks body... | ||
| 852 | This macro executes @var{body} like @code{progn}, but all calls to | ||
| 853 | @code{run-mode-hooks} inside @var{body} delay running their hooks. | ||
| 854 | They will be run by the first call to @code{run-mode-hooks} after exit | ||
| 855 | from @code{delay-mode-hooks}. | ||
| 856 | @end defmac | ||
| 857 | |||
| 858 | @defvar after-change-major-mode-hook | ||
| 859 | Every major mode function should run this normal hook at its very end. | ||
| 860 | It normally does not need to do so explicitly. Indeed, a major mode | ||
| 861 | function should normally run its mode hook with @code{run-mode-hooks} | ||
| 862 | as the very last thing it does and @code{run-mode-hooks} runs | ||
| 863 | @code{after-change-major-mode-hook} at its very end. | ||
| 864 | @end defvar | ||
| 865 | |||
| 811 | @node Minor Modes | 866 | @node Minor Modes |
| 812 | @section Minor Modes | 867 | @section Minor Modes |
| 813 | @cindex minor mode | 868 | @cindex minor mode |
| @@ -2087,7 +2142,7 @@ if there is no subexpression numbered @var{subexp} in @var{matcher}. | |||
| 2087 | Obviously, fontification of the subexpression numbered @var{subexp} will | 2142 | Obviously, fontification of the subexpression numbered @var{subexp} will |
| 2088 | not occur. However, fontification of other subexpressions (and other | 2143 | not occur. However, fontification of other subexpressions (and other |
| 2089 | regexps) will continue. If @var{laxmatch} is @code{nil}, and the | 2144 | regexps) will continue. If @var{laxmatch} is @code{nil}, and the |
| 2090 | specified subexpression is missing, then an error is signalled which | 2145 | specified subexpression is missing, then an error is signaled which |
| 2091 | terminates search-based fontification. | 2146 | terminates search-based fontification. |
| 2092 | 2147 | ||
| 2093 | Here are some examples of elements of this kind, and what they do: | 2148 | Here are some examples of elements of this kind, and what they do: |
| @@ -2450,7 +2505,7 @@ a file, don't have to do anything to use this feature. | |||
| 2450 | 2505 | ||
| 2451 | For buffers not visiting a file to have their state saved, the major | 2506 | For buffers not visiting a file to have their state saved, the major |
| 2452 | mode must bind the buffer local variable @code{desktop-save-buffer} to | 2507 | mode must bind the buffer local variable @code{desktop-save-buffer} to |
| 2453 | a non-nil value. | 2508 | a non-@code{nil} value. |
| 2454 | 2509 | ||
| 2455 | @defvar desktop-save-buffer | 2510 | @defvar desktop-save-buffer |
| 2456 | If this buffer-local variable is non-@code{nil}, the buffer will have | 2511 | If this buffer-local variable is non-@code{nil}, the buffer will have |
| @@ -2563,26 +2618,8 @@ obsolete.) If the value is a function (either a lambda expression or | |||
| 2563 | a symbol with a function definition), it is called. If it is a list | 2618 | a symbol with a function definition), it is called. If it is a list |
| 2564 | that isn't a function, its elements are called, consecutively. All | 2619 | that isn't a function, its elements are called, consecutively. All |
| 2565 | the hook functions are called with no arguments. | 2620 | the hook functions are called with no arguments. |
| 2566 | |||
| 2567 | For example, here's how @code{emacs-lisp-mode} runs its mode hook: | ||
| 2568 | |||
| 2569 | @example | ||
| 2570 | (run-hooks 'emacs-lisp-mode-hook) | ||
| 2571 | @end example | ||
| 2572 | @end defun | 2621 | @end defun |
| 2573 | 2622 | ||
| 2574 | @defun run-mode-hooks &rest hookvars | ||
| 2575 | Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks} | ||
| 2576 | macro. | ||
| 2577 | @end defun | ||
| 2578 | |||
| 2579 | @defmac delay-mode-hooks body... | ||
| 2580 | This macro executes the @var{body} forms but defers all calls to | ||
| 2581 | @code{run-mode-hooks} within them until the end of @var{body}. | ||
| 2582 | This macro enables a derived mode to arrange not to run | ||
| 2583 | its parent modes' mode hooks until the end. | ||
| 2584 | @end defmac | ||
| 2585 | |||
| 2586 | @defun run-hook-with-args hook &rest args | 2623 | @defun run-hook-with-args hook &rest args |
| 2587 | This function is the way to run an abnormal hook and always call all | 2624 | This function is the way to run an abnormal hook and always call all |
| 2588 | of the hook functions. It calls each of the hook functions one by | 2625 | of the hook functions. It calls each of the hook functions one by |