summaryrefslogtreecommitdiff
path: root/devdocs/elisp/hooks.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/hooks.html
new repository
Diffstat (limited to 'devdocs/elisp/hooks.html')
-rw-r--r--devdocs/elisp/hooks.html16
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/elisp/hooks.html b/devdocs/elisp/hooks.html
new file mode 100644
index 00000000..2d310d1e
--- /dev/null
+++ b/devdocs/elisp/hooks.html
@@ -0,0 +1,16 @@
+ <h3 class="section">Hooks</h3> <p>A <em>hook</em> is a variable where you can store a function or functions (see <a href="what-is-a-function">What Is a Function</a>) to be called on a particular occasion by an existing program. Emacs provides hooks for the sake of customization. Most often, hooks are set up in the init file (see <a href="init-file">Init File</a>), but Lisp programs can set them also. See <a href="standard-hooks">Standard Hooks</a>, for a list of some standard hook variables. </p> <p>Most of the hooks in Emacs are <em>normal hooks</em>. These variables contain lists of functions to be called with no arguments. By convention, whenever the hook name ends in ‘<samp>-hook</samp>’, that tells you it is normal. We try to make all hooks normal, as much as possible, so that you can use them in a uniform way. </p> <p>Every major mode command is supposed to run a normal hook called the <em>mode hook</em> as one of the last steps of initialization. This makes it easy for a user to customize the behavior of the mode, by overriding the buffer-local variable assignments already made by the mode. Most minor mode functions also run a mode hook at the end. But hooks are used in other contexts too. For example, the hook <code>suspend-hook</code> runs just before Emacs suspends itself (see <a href="suspending-emacs">Suspending Emacs</a>). </p> <p>If the hook variable’s name does not end with ‘<samp>-hook</samp>’, that indicates it is probably an <em>abnormal hook</em>. These differ from normal hooks in two ways: they can be called with one or more arguments, and their return values can be used in some way. The hook’s documentation says how the functions are called and how their return values are used. Any functions added to an abnormal hook must follow the hook’s calling convention. By convention, abnormal hook names end in ‘<samp>-functions</samp>’. </p> <p>If the name of the variable ends in ‘<samp>-predicate</samp>’ or ‘<samp>-function</samp>’ (singular) then its value must be a function, not a list of functions. As with abnormal hooks, the expected arguments and meaning of the return value vary across such <em>single function hooks</em>. The details are explained in each variable’s docstring. </p> <p>Since hooks (both multi and single function) are variables, their values can be modified with <code>setq</code> or temporarily with <code>let</code>. However, it is often useful to add or remove a particular function from a hook while preserving any other functions it might have. For multi function hooks, the recommended way of doing this is with <code>add-hook</code> and <code>remove-hook</code> (see <a href="setting-hooks">Setting Hooks</a>). Most normal hook variables are initially void; <code>add-hook</code> knows how to deal with this. You can add hooks either globally or buffer-locally with <code>add-hook</code>. For hooks which hold only a single function, <code>add-hook</code> is not appropriate, but you can use <code>add-function</code> (see <a href="advising-functions">Advising Functions</a>) to combine new functions with the hook. Note that some single function hooks may be <code>nil</code> which <code>add-function</code> cannot deal with, so you must check for that before calling <code>add-function</code>. </p> <table class="menu" border="0" cellspacing="0"> <tr>
+<td align="left" valign="top">• <a href="running-hooks" accesskey="1">Running Hooks</a>
+</td>
+<td> </td>
+<td align="left" valign="top">How to run a hook. </td>
+</tr> <tr>
+<td align="left" valign="top">• <a href="setting-hooks" accesskey="2">Setting Hooks</a>
+</td>
+<td> </td>
+<td align="left" valign="top">How to put functions on a hook, or remove them. </td>
+</tr> </table><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html</a>
+ </p>
+</div>