comparison src/keyboard.c @ 7428:e14086d8ba6f

(safe_run_hooks): New function, extracted from command_loop_1. Bind inhibit_quit.
author Karl Heuer <kwzh@gnu.org>
date Tue, 10 May 1994 05:48:20 +0000
parents 2ea6fdd2dacf
children cc5e8709ab89
comparison
equal deleted inserted replaced
7427:2ea6fdd2dacf 7428:e14086d8ba6f
898 /* This is the actual command reading loop, 898 /* This is the actual command reading loop,
899 sans error-handling encapsulation. */ 899 sans error-handling encapsulation. */
900 900
901 Lisp_Object Fcommand_execute (); 901 Lisp_Object Fcommand_execute ();
902 static int read_key_sequence (); 902 static int read_key_sequence ();
903 static void safe_run_hooks ();
903 904
904 Lisp_Object 905 Lisp_Object
905 command_loop_1 () 906 command_loop_1 ()
906 { 907 {
907 Lisp_Object cmd, tem; 908 Lisp_Object cmd, tem;
924 this_command_key_count = 0; 925 this_command_key_count = 0;
925 926
926 /* Make sure this hook runs after commands that get errors and 927 /* Make sure this hook runs after commands that get errors and
927 throw to top level. */ 928 throw to top level. */
928 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) 929 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
929 { 930 safe_run_hooks (&Vpost_command_hook);
930 /* If we get an error during the post-command-hook,
931 cause post-command-hook to be nil. */
932 Vcommand_hook_internal = Vpost_command_hook;
933 Vpost_command_hook = Qnil;
934
935 call1 (Vrun_hooks, Qcommand_hook_internal);
936
937 Vpost_command_hook = Vcommand_hook_internal;
938 }
939 931
940 /* Do this after running Vpost_command_hook, for consistency. */ 932 /* Do this after running Vpost_command_hook, for consistency. */
941 last_command = this_command; 933 last_command = this_command;
942 934
943 while (1) 935 while (1)
1055 1047
1056 /* Execute the command. */ 1048 /* Execute the command. */
1057 1049
1058 this_command = cmd; 1050 this_command = cmd;
1059 if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) 1051 if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks))
1060 { 1052 safe_run_hooks (&Vpre_command_hook);
1061 /* If we get an error during the pre-command-hook,
1062 cause pre-command-hook to be nil. */
1063 Vcommand_hook_internal = Vpre_command_hook;
1064 Vpre_command_hook = Qnil;
1065
1066 call1 (Vrun_hooks, Qcommand_hook_internal);
1067
1068 Vpre_command_hook = Vcommand_hook_internal;
1069 }
1070 1053
1071 if (NILP (this_command)) 1054 if (NILP (this_command))
1072 { 1055 {
1073 /* nil means key is undefined. */ 1056 /* nil means key is undefined. */
1074 bitch_at_user (); 1057 bitch_at_user ();
1192 1175
1193 } 1176 }
1194 directly_done: ; 1177 directly_done: ;
1195 1178
1196 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) 1179 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
1197 { 1180 safe_run_hooks (&Vpost_command_hook);
1198 /* If we get an error during the post-command-hook,
1199 cause post-command-hook to be nil. */
1200 Vcommand_hook_internal = Vpost_command_hook;
1201 Vpost_command_hook = Qnil;
1202
1203 call1 (Vrun_hooks, Qcommand_hook_internal);
1204
1205 Vpost_command_hook = Vcommand_hook_internal;
1206 }
1207 1181
1208 /* If there is a prefix argument, 1182 /* If there is a prefix argument,
1209 1) We don't want last_command to be ``universal-argument'' 1183 1) We don't want last_command to be ``universal-argument''
1210 (that would be dumb), so don't set last_command, 1184 (that would be dumb), so don't set last_command,
1211 2) we want to leave echoing on so that the prefix will be 1185 2) we want to leave echoing on so that the prefix will be
1230 } 1204 }
1231 else if (current_buffer != prev_buffer || MODIFF != prev_modiff) 1205 else if (current_buffer != prev_buffer || MODIFF != prev_modiff)
1232 call1 (Vrun_hooks, intern ("activate-mark-hook")); 1206 call1 (Vrun_hooks, intern ("activate-mark-hook"));
1233 } 1207 }
1234 } 1208 }
1209 }
1210
1211 /* If we get an error while running the hook, cause the hook variable
1212 to be nil. Also inhibit quits, so that C-g won't cause the hook
1213 to mysteriously evaporate. */
1214 static void
1215 safe_run_hooks (hook)
1216 Lisp_Object *hook;
1217 {
1218 int count = specpdl_ptr - specpdl;
1219 specbind (Qinhibit_quit, Qt);
1220
1221 Vcommand_hook_internal = *hook;
1222 *hook = Qnil;
1223 call1 (Vrun_hooks, Qcommand_hook_internal);
1224 *hook = Vcommand_hook_internal;
1225
1226 unbind_to (count, Qnil);
1235 } 1227 }
1236 1228
1237 /* Number of seconds between polling for input. */ 1229 /* Number of seconds between polling for input. */
1238 int polling_period; 1230 int polling_period;
1239 1231