Lisp_Object Fcommand_execute ();
static int read_key_sequence ();
+static void safe_run_hooks ();
Lisp_Object
command_loop_1 ()
/* Make sure this hook runs after commands that get errors and
throw to top level. */
if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
- {
- /* If we get an error during the post-command-hook,
- cause post-command-hook to be nil. */
- Vcommand_hook_internal = Vpost_command_hook;
- Vpost_command_hook = Qnil;
-
- call1 (Vrun_hooks, Qcommand_hook_internal);
-
- Vpost_command_hook = Vcommand_hook_internal;
- }
+ safe_run_hooks (&Vpost_command_hook);
/* Do this after running Vpost_command_hook, for consistency. */
last_command = this_command;
this_command = cmd;
if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks))
- {
- /* If we get an error during the pre-command-hook,
- cause pre-command-hook to be nil. */
- Vcommand_hook_internal = Vpre_command_hook;
- Vpre_command_hook = Qnil;
-
- call1 (Vrun_hooks, Qcommand_hook_internal);
-
- Vpre_command_hook = Vcommand_hook_internal;
- }
+ safe_run_hooks (&Vpre_command_hook);
if (NILP (this_command))
{
directly_done: ;
if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
- {
- /* If we get an error during the post-command-hook,
- cause post-command-hook to be nil. */
- Vcommand_hook_internal = Vpost_command_hook;
- Vpost_command_hook = Qnil;
-
- call1 (Vrun_hooks, Qcommand_hook_internal);
-
- Vpost_command_hook = Vcommand_hook_internal;
- }
+ safe_run_hooks (&Vpost_command_hook);
/* If there is a prefix argument,
1) We don't want last_command to be ``universal-argument''
}
}
}
+
+/* If we get an error while running the hook, cause the hook variable
+ to be nil. Also inhibit quits, so that C-g won't cause the hook
+ to mysteriously evaporate. */
+static void
+safe_run_hooks (hook)
+ Lisp_Object *hook;
+{
+ int count = specpdl_ptr - specpdl;
+ specbind (Qinhibit_quit, Qt);
+
+ Vcommand_hook_internal = *hook;
+ *hook = Qnil;
+ call1 (Vrun_hooks, Qcommand_hook_internal);
+ *hook = Vcommand_hook_internal;
+
+ unbind_to (count, Qnil);
+}
\f
/* Number of seconds between polling for input. */
int polling_period;