Merge from trunk
[bpt/emacs.git] / src / keyboard.c
index a2ba83c..d307250 100644 (file)
@@ -1,7 +1,6 @@
 /* Keyboard and mouse input; editor command loop.
-   Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
-                 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+
+Copyright (C) 1985-1989, 1993-1997, 1999-2011  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -125,9 +124,6 @@ int this_command_key_count_reset;
 Lisp_Object raw_keybuf;
 int raw_keybuf_count;
 
-/* Non-nil if the present key sequence was obtained by shift translation.  */
-Lisp_Object Vthis_command_keys_shift_translated;
-
 #define GROW_RAW_KEYBUF                                                        \
  if (raw_keybuf_count == XVECTOR (raw_keybuf)->size)                   \
    raw_keybuf = larger_vector (raw_keybuf, raw_keybuf_count * 2, Qnil)  \
@@ -141,19 +137,6 @@ int this_single_command_key_start;
 static int before_command_key_count;
 static int before_command_echo_length;
 
-/* If non-nil, the function that implements the display of help.
-   It's called with one argument, the help string to display.  */
-
-Lisp_Object Vshow_help_function;
-
-/* Nonzero means do menu prompting.  */
-
-static int menu_prompting;
-
-/* Character to see next line of menu prompt.  */
-
-static Lisp_Object menu_prompt_more_char;
-
 /* For longjmp to where kbd input is being done.  */
 
 static jmp_buf getcjmp;
@@ -182,49 +165,9 @@ struct kboard *echo_kboard;
 
 Lisp_Object echo_message_buffer;
 
-/* Nonzero means disregard local maps for the menu bar.  */
-static int inhibit_local_menu_bar_menus;
-
 /* Nonzero means C-g should cause immediate error-signal.  */
 int immediate_quit;
 
-/* The user's hook function for outputting an error message.  */
-Lisp_Object Vcommand_error_function;
-
-/* The user's ERASE setting.  */
-Lisp_Object Vtty_erase_char;
-
-/* Character to recognize as the help char.  */
-Lisp_Object Vhelp_char;
-
-/* List of other event types to recognize as meaning "help".  */
-Lisp_Object Vhelp_event_list;
-
-/* Form to execute when help char is typed.  */
-Lisp_Object Vhelp_form;
-
-/* Command to run when the help character follows a prefix key.  */
-Lisp_Object Vprefix_help_command;
-
-/* List of items that should move to the end of the menu bar.  */
-Lisp_Object Vmenu_bar_final_items;
-
-/* Expression to evaluate for the tool bar separator image.
-   This is used for build_desired_tool_bar_string only.  For GTK, we
-   use GTK tool bar seperators.  */
-
-Lisp_Object Vtool_bar_separator_image_expression;
-
-/* Non-nil means show the equivalent key-binding for
-   any M-x command that has one.
-   The value can be a length of time to show the message for.
-   If the value is non-nil and not a number, we wait 2 seconds.  */
-Lisp_Object Vsuggest_key_bindings;
-
-/* How long to display an echo-area message when the minibuffer is active.
-   If the value is not a number, such messages don't time out.  */
-Lisp_Object Vminibuffer_message_timeout;
-
 /* Character that causes a quit.  Normally C-g.
 
    If we are running on an ordinary terminal, this must be an ordinary
@@ -243,46 +186,9 @@ Lisp_Object Vminibuffer_message_timeout;
    ASCII character.  */
 int quit_char;
 
-/* If non-nil, this is a map that overrides all other local maps.  */
-Lisp_Object Voverriding_local_map;
-
-/* If non-nil, Voverriding_local_map applies to the menu bar.  */
-Lisp_Object Voverriding_local_map_menu_flag;
-
-/* Keymap that defines special misc events that should
-   be processed immediately at a low level.  */
-Lisp_Object Vspecial_event_map;
-
 /* Current depth in recursive edits.  */
 int command_loop_level;
 
-/* Total number of times command_loop has read a key sequence.  */
-EMACS_INT num_input_keys;
-
-/* Last input event read as a command.  */
-Lisp_Object last_command_event;
-
-/* Last input character read as a command, not counting menus
-   reached by the mouse.  */
-Lisp_Object last_nonmenu_event;
-
-/* Last input event read for any purpose.  */
-Lisp_Object last_input_event;
-
-/* If not Qnil, a list of objects to be read as subsequent command input.  */
-Lisp_Object Vunread_command_events;
-
-/* If not Qnil, a list of objects to be read as subsequent command input
-   including input method processing.  */
-Lisp_Object Vunread_input_method_events;
-
-/* If not Qnil, a list of objects to be read as subsequent command input
-   but NOT including input method processing.  */
-Lisp_Object Vunread_post_input_method_events;
-
-/* If not -1, an event to be read as subsequent command input.  */
-EMACS_INT unread_command_char;
-
 /* If not Qnil, this is a switch-frame event which we decided to put
    off until the end of a key sequence.  This should be read as the
    next command input, after any unread_command_events.
@@ -292,47 +198,19 @@ EMACS_INT unread_command_char;
    events until a non-ASCII event is acceptable as input.  */
 Lisp_Object unread_switch_frame;
 
-/* A mask of extra modifier bits to put into every keyboard char.  */
-EMACS_INT extra_keyboard_modifiers;
-
-/* Char to use as prefix when a meta character is typed in.
-   This is bound on entry to minibuffer in case ESC is changed there.  */
-
-Lisp_Object meta_prefix_char;
-
 /* Last size recorded for a current buffer which is not a minibuffer.  */
 static EMACS_INT last_non_minibuf_size;
 
-/* Number of idle seconds before an auto-save and garbage collection.  */
-static Lisp_Object Vauto_save_timeout;
-
-/* Total number of times read_char has returned.  */
-int num_input_events;
-
-/* Total number of times read_char has returned, outside of macros.  */
-EMACS_INT num_nonmacro_input_events;
-
-/* Auto-save automatically when this many characters have been typed
-   since the last time.  */
-
-static EMACS_INT auto_save_interval;
+/* Total number of times read_char has returned, modulo SIZE_MAX + 1.  */
+size_t num_input_events;
 
 /* Value of num_nonmacro_input_events as of last auto save.  */
 
 int last_auto_save;
 
-/* The command being executed by the command loop.
-   Commands may set this, and the value set will be copied into
-   current_kboard->Vlast_command instead of the actual command.  */
-Lisp_Object Vthis_command;
-
 /* This is like Vthis_command, except that commands never set it.  */
 Lisp_Object real_this_command;
 
-/* If the lookup of the command returns a binding, the original
-   command is stored in this-original-command.  It is nil otherwise.  */
-Lisp_Object Vthis_original_command;
-
 /* The value of point when the last command was started.  */
 EMACS_INT last_point_position;
 
@@ -349,22 +227,10 @@ Lisp_Object last_point_position_window;
    generated by the next character.  */
 Lisp_Object internal_last_event_frame;
 
-/* A user-visible version of the above, intended to allow users to
-   figure out where the last event came from, if the event doesn't
-   carry that information itself (i.e. if it was a character).  */
-Lisp_Object Vlast_event_frame;
-
 /* The timestamp of the last input event we received from the X server.
    X Windows wants this for selection ownership.  */
 unsigned long last_event_timestamp;
 
-/* If non-nil, active regions automatically become the window selection.  */
-Lisp_Object Vselect_active_regions;
-
-/* The text in the active region prior to modifying the buffer.
-   Used by the `select-active-regions' feature.  */
-Lisp_Object Vsaved_region_selection;
-
 Lisp_Object Qx_set_selection, QPRIMARY, Qhandle_switch_frame;
 
 Lisp_Object Qself_insert_command;
@@ -377,48 +243,18 @@ Lisp_Object Qtimer_event_handler;
    key sequence that it reads.  */
 Lisp_Object read_key_sequence_cmd;
 
-/* Echo unfinished commands after this many seconds of pause.  */
-Lisp_Object Vecho_keystrokes;
-
-/* Form to evaluate (if non-nil) when Emacs is started.  */
-Lisp_Object Vtop_level;
-
-/* If non-nil, this implements the current input method.  */
-Lisp_Object Vinput_method_function;
 Lisp_Object Qinput_method_function;
 
-/* When we call Vinput_method_function,
-   this holds the echo area message that was just erased.  */
-Lisp_Object Vinput_method_previous_message;
-
-/* Non-nil means deactivate the mark at end of this command.  */
-Lisp_Object Vdeactivate_mark;
 Lisp_Object Qdeactivate_mark;
 
-/* Menu bar specified in Lucid Emacs fashion.  */
-
-Lisp_Object Vlucid_menu_bar_dirty_flag;
 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
 
 Lisp_Object Qecho_area_clear_hook;
 
 /* Hooks to run before and after each command.  */
-Lisp_Object Qpre_command_hook, Vpre_command_hook;
-Lisp_Object Qpost_command_hook, Vpost_command_hook;
-Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal;
-
-/* Parent keymap of terminal-local function-key-map instances.  */
-Lisp_Object Vfunction_key_map;
-
-/* Keymap of key translations that can override keymaps.  */
-Lisp_Object Vkey_translation_map;
+Lisp_Object Qpre_command_hook;
+Lisp_Object Qpost_command_hook;
 
-/* List of deferred actions to be performed at a later time.
-   The precise format isn't relevant here; we just check whether it is nil.  */
-Lisp_Object Vdeferred_action_list;
-
-/* Function to call to handle deferred actions, when there are any.  */
-Lisp_Object Vdeferred_action_function;
 Lisp_Object Qdeferred_action_function;
 
 Lisp_Object Qinput_method_exit_on_first_char;
@@ -454,11 +290,6 @@ static struct input_event * volatile kbd_store_ptr;
    dequeuing functions?  Such a flag could be screwed up by interrupts
    at inopportune times.  */
 
-/* If this flag is non-nil, we check mouse_moved to see when the
-   mouse moves, and motion events will appear in the input stream.
-   Otherwise, mouse motion is ignored.  */
-Lisp_Object do_mouse_tracking;
-
 /* Symbols to head events.  */
 Lisp_Object Qmouse_movement;
 Lisp_Object Qscroll_bar_movement;
@@ -519,19 +350,13 @@ Lisp_Object Qmenu_bar;
 Lisp_Object recursive_edit_unwind (Lisp_Object buffer), command_loop (void);
 Lisp_Object Fthis_command_keys (void);
 Lisp_Object Qextended_command_history;
-EMACS_TIME timer_check (int do_it_now);
+EMACS_TIME timer_check (void);
 
 static void record_menu_key (Lisp_Object c);
 static int echo_length (void);
 
 Lisp_Object Qpolling_period;
 
-/* List of absolute timers.  Appears in order of next scheduled event.  */
-Lisp_Object Vtimer_list;
-
-/* List of idle time timers.  Appears in order of next scheduled event.  */
-Lisp_Object Vtimer_idle_list;
-
 /* Incremented whenever a timer is run.  */
 int timers_run;
 
@@ -565,18 +390,6 @@ int interrupts_deferred;
 #define POLL_FOR_INPUT
 #endif
 
-/* After a command is executed, if point is moved into a region that
-   has specific properties (e.g. composition, display), we adjust
-   point to the boundary of the region.  But, if a command sets this
-   variable to non-nil, we suppress this point adjustment.  This
-   variable is set to nil before reading a command.  */
-
-Lisp_Object Vdisable_point_adjustment;
-
-/* If non-nil, always disable point adjustment.  */
-
-Lisp_Object Vglobal_disable_point_adjustment;
-
 /* The time when Emacs started being idle.  */
 
 static EMACS_TIME timer_idleness_start_time;
@@ -586,11 +399,6 @@ static EMACS_TIME timer_idleness_start_time;
 
 static EMACS_TIME timer_last_idleness_start_time;
 
-/* If non-nil, events produced by disabled menu items and tool-bar
-   buttons are not ignored.  Help functions bind this to allow help on
-   those items and buttons.  */
-Lisp_Object Venable_disabled_menus_and_buttons;
-
 \f
 /* Global variable declarations.  */
 
@@ -625,28 +433,24 @@ static void restore_getcjmp (jmp_buf);
 static Lisp_Object apply_modifiers (int, Lisp_Object);
 static void clear_event (struct input_event *);
 static Lisp_Object restore_kboard_configuration (Lisp_Object);
-static SIGTYPE interrupt_signal (int signalnum);
+static void interrupt_signal (int signalnum);
 #ifdef SIGIO
-static SIGTYPE input_available_signal (int signo);
+static void input_available_signal (int signo);
 #endif
 static void handle_interrupt (void);
 static void timer_start_idle (void);
 static void timer_stop_idle (void);
 static void timer_resume_idle (void);
-static SIGTYPE handle_user_signal (int);
+static void handle_user_signal (int);
 static char *find_user_signal_name (int);
 static int store_user_signal_events (void);
 
-/* Nonzero means don't try to suspend even if the operating system seems
-   to support it.  */
-static int cannot_suspend;
-
 \f
 /* Add C to the echo string, if echoing is going on.
    C can be a character, which is printed prettily ("M-C-x" and all that
    jazz), or a symbol, whose name is printed.  */
 
-void
+static void
 echo_char (Lisp_Object c)
 {
   if (current_kboard->immediate_echo)
@@ -656,7 +460,7 @@ echo_char (Lisp_Object c)
       char *ptr = buffer;
       Lisp_Object echo_string;
 
-      echo_string = current_kboard->echo_string;
+      echo_string = KVAR (current_kboard, echo_string);
 
       /* If someone has passed us a composite event, use its head symbol.  */
       c = EVENT_HEAD (c);
@@ -678,7 +482,7 @@ echo_char (Lisp_Object c)
              ptr = buffer + offset;
            }
 
-         ptr += copy_text (SDATA (name), ptr, nbytes,
+         ptr += copy_text (SDATA (name), (unsigned char *) ptr, nbytes,
                            STRING_MULTIBYTE (name), 1);
        }
 
@@ -723,7 +527,7 @@ echo_char (Lisp_Object c)
       else if (STRINGP (echo_string))
        echo_string = concat2 (echo_string, build_string (" "));
 
-      current_kboard->echo_string
+      KVAR (current_kboard, echo_string)
        = concat2 (echo_string, make_string (buffer, ptr - buffer));
 
       echo_now ();
@@ -733,35 +537,35 @@ echo_char (Lisp_Object c)
 /* Temporarily add a dash to the end of the echo string if it's not
    empty, so that it serves as a mini-prompt for the very next character.  */
 
-void
+static void
 echo_dash (void)
 {
   /* Do nothing if not echoing at all.  */
-  if (NILP (current_kboard->echo_string))
+  if (NILP (KVAR (current_kboard, echo_string)))
     return;
 
   if (this_command_key_count == 0)
     return;
 
   if (!current_kboard->immediate_echo
-      && SCHARS (current_kboard->echo_string) == 0)
+      && SCHARS (KVAR (current_kboard, echo_string)) == 0)
     return;
 
   /* Do nothing if we just printed a prompt.  */
   if (current_kboard->echo_after_prompt
-      == SCHARS (current_kboard->echo_string))
+      == SCHARS (KVAR (current_kboard, echo_string)))
     return;
 
   /* Do nothing if we have already put a dash at the end.  */
-  if (SCHARS (current_kboard->echo_string) > 1)
+  if (SCHARS (KVAR (current_kboard, echo_string)) > 1)
     {
       Lisp_Object last_char, prev_char, idx;
 
-      idx = make_number (SCHARS (current_kboard->echo_string) - 2);
-      prev_char = Faref (current_kboard->echo_string, idx);
+      idx = make_number (SCHARS (KVAR (current_kboard, echo_string)) - 2);
+      prev_char = Faref (KVAR (current_kboard, echo_string), idx);
 
-      idx = make_number (SCHARS (current_kboard->echo_string) - 1);
-      last_char = Faref (current_kboard->echo_string, idx);
+      idx = make_number (SCHARS (KVAR (current_kboard, echo_string)) - 1);
+      last_char = Faref (KVAR (current_kboard, echo_string), idx);
 
       if (XINT (last_char) == '-' && XINT (prev_char) != ' ')
        return;
@@ -769,7 +573,7 @@ echo_dash (void)
 
   /* Put a dash at the end of the buffer temporarily,
      but make it go away when the next character is added.  */
-  current_kboard->echo_string = concat2 (current_kboard->echo_string,
+  KVAR (current_kboard, echo_string) = concat2 (KVAR (current_kboard, echo_string),
                                         build_string ("-"));
   echo_now ();
 }
@@ -812,9 +616,9 @@ echo_now (void)
     }
 
   echoing = 1;
-  message3_nolog (current_kboard->echo_string,
-                 SBYTES (current_kboard->echo_string),
-                 STRING_MULTIBYTE (current_kboard->echo_string));
+  message3_nolog (KVAR (current_kboard, echo_string),
+                 SBYTES (KVAR (current_kboard, echo_string)),
+                 STRING_MULTIBYTE (KVAR (current_kboard, echo_string)));
   echoing = 0;
 
   /* Record in what buffer we echoed, and from which kboard.  */
@@ -832,7 +636,7 @@ cancel_echoing (void)
 {
   current_kboard->immediate_echo = 0;
   current_kboard->echo_after_prompt = -1;
-  current_kboard->echo_string = Qnil;
+  KVAR (current_kboard, echo_string) = Qnil;
   ok_to_echo_at_next_pause = NULL;
   echo_kboard = NULL;
   echo_message_buffer = Qnil;
@@ -843,8 +647,8 @@ cancel_echoing (void)
 static int
 echo_length (void)
 {
-  return (STRINGP (current_kboard->echo_string)
-         ? SCHARS (current_kboard->echo_string)
+  return (STRINGP (KVAR (current_kboard, echo_string))
+         ? SCHARS (KVAR (current_kboard, echo_string))
          : 0);
 }
 
@@ -855,9 +659,9 @@ echo_length (void)
 static void
 echo_truncate (EMACS_INT nchars)
 {
-  if (STRINGP (current_kboard->echo_string))
-    current_kboard->echo_string
-      = Fsubstring (current_kboard->echo_string,
+  if (STRINGP (KVAR (current_kboard, echo_string)))
+    KVAR (current_kboard, echo_string)
+      = Fsubstring (KVAR (current_kboard, echo_string),
                    make_number (0), make_number (nchars));
   truncate_echo_area (nchars);
 }
@@ -1162,7 +966,7 @@ restore_kboard_configuration (Lisp_Object was_locked)
 /* Handle errors that are not handled at inner levels
    by printing an error message and returning to the editor command loop.  */
 
-Lisp_Object
+static Lisp_Object
 cmd_error (Lisp_Object data)
 {
   Lisp_Object old_level, old_length;
@@ -1188,8 +992,8 @@ cmd_error (Lisp_Object data)
   Vstandard_input = Qt;
   Vexecuting_kbd_macro = Qnil;
   executing_kbd_macro = Qnil;
-  current_kboard->Vprefix_arg = Qnil;
-  current_kboard->Vlast_prefix_arg = Qnil;
+  KVAR (current_kboard, Vprefix_arg) = Qnil;
+  KVAR (current_kboard, Vlast_prefix_arg) = Qnil;
   cancel_echoing ();
 
   /* Avoid unquittable loop if data contains a circular list.  */
@@ -1327,10 +1131,10 @@ command_loop_2 (Lisp_Object ignore)
   return Qnil;
 }
 
-Lisp_Object
+static Lisp_Object
 top_level_2 (void)
 {
-  return Feval (Vtop_level);
+  return Feval (Vtop_level, Qnil);
 }
 
 Lisp_Object
@@ -1364,6 +1168,7 @@ This also exits all active minibuffers.  */)
   Fthrow (Qtop_level, Qnil);
 }
 
+Lisp_Object Fexit_recursive_edit (void) NO_RETURN;
 DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "",
        doc: /* Exit from the innermost recursive edit or minibuffer.  */)
   (void)
@@ -1374,6 +1179,7 @@ DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0,
   error ("No recursive edit is in progress");
 }
 
+Lisp_Object Fabort_recursive_edit (void) NO_RETURN;
 DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "",
        doc: /* Abort the command that requested this recursive edit or minibuffer input.  */)
   (void)
@@ -1463,7 +1269,7 @@ some_mouse_moved (void)
 /* This is the actual command reading loop,
    sans error-handling encapsulation.  */
 
-static int read_key_sequence (Lisp_Object *, int, Lisp_Object,
+static int read_key_sequence (Lisp_Object *, size_t, Lisp_Object,
                               int, int, int);
 void safe_run_hooks (Lisp_Object);
 static void adjust_point_for_property (EMACS_INT, int);
@@ -1497,8 +1303,8 @@ command_loop_1 (void)
 #endif
   int already_adjusted = 0;
 
-  current_kboard->Vprefix_arg = Qnil;
-  current_kboard->Vlast_prefix_arg = Qnil;
+  KVAR (current_kboard, Vprefix_arg) = Qnil;
+  KVAR (current_kboard, Vlast_prefix_arg) = Qnil;
   Vdeactivate_mark = Qnil;
   waiting_for_input = 0;
   cancel_echoing ();
@@ -1526,10 +1332,10 @@ command_loop_1 (void)
     }
 
   /* Do this after running Vpost_command_hook, for consistency.  */
-  current_kboard->Vlast_command = Vthis_command;
-  current_kboard->Vreal_last_command = real_this_command;
+  KVAR (current_kboard, Vlast_command) = Vthis_command;
+  KVAR (current_kboard, Vreal_last_command) = real_this_command;
   if (!CONSP (last_command_event))
-    current_kboard->Vlast_repeatable_command = real_this_command;
+    KVAR (current_kboard, Vlast_repeatable_command) = real_this_command;
 
   while (1)
     {
@@ -1685,10 +1491,7 @@ command_loop_1 (void)
 
       Vthis_command = cmd;
       real_this_command = cmd;
-      /* Note that the value cell will never directly contain nil
-        if the symbol is a local variable.  */
-      if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks))
-       safe_run_hooks (Qpre_command_hook);
+      safe_run_hooks (Qpre_command_hook);
 
       already_adjusted = 0;
 
@@ -1699,9 +1502,9 @@ command_loop_1 (void)
          keys = Fkey_description (keys, Qnil);
          bitch_at_user ();
          message_with_string ("%s is undefined", keys, 0);
-         current_kboard->defining_kbd_macro = Qnil;
+         KVAR (current_kboard, defining_kbd_macro) = Qnil;
          update_mode_lines = 1;
-         current_kboard->Vprefix_arg = Qnil;
+         KVAR (current_kboard, Vprefix_arg) = Qnil;
        }
       else
        {
@@ -1718,7 +1521,7 @@ command_loop_1 (void)
               }
 #endif
 
-            if (NILP (current_kboard->Vprefix_arg)) /* FIXME: Why?  --Stef  */
+            if (NILP (KVAR (current_kboard, Vprefix_arg))) /* FIXME: Why?  --Stef  */
               Fundo_boundary ();
             Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil);
 
@@ -1732,20 +1535,16 @@ command_loop_1 (void)
             unbind_to (scount, Qnil);
 #endif
           }
-      current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg;
+      KVAR (current_kboard, Vlast_prefix_arg) = Vcurrent_prefix_arg;
 
-      /* Note that the value cell will never directly contain nil
-        if the symbol is a local variable.  */
-      if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
-       safe_run_hooks (Qpost_command_hook);
+      safe_run_hooks (Qpost_command_hook);
 
       /* If displaying a message, resize the echo area window to fit
         that message's size exactly.  */
       if (!NILP (echo_area_buffer[0]))
        resize_echo_area_exactly ();
 
-      if (!NILP (Vdeferred_action_list))
-       safe_run_hooks (Qdeferred_action_function);
+      safe_run_hooks (Qdeferred_action_function);
 
       /* If there is a prefix argument,
         1) We don't want Vlast_command to be ``universal-argument''
@@ -1760,19 +1559,19 @@ command_loop_1 (void)
         If the command didn't actually create a prefix arg,
         but is merely a frame event that is transparent to prefix args,
         then the above doesn't apply.  */
-      if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_event))
+      if (NILP (KVAR (current_kboard, Vprefix_arg)) || CONSP (last_command_event))
        {
-         current_kboard->Vlast_command = Vthis_command;
-         current_kboard->Vreal_last_command = real_this_command;
+         KVAR (current_kboard, Vlast_command) = Vthis_command;
+         KVAR (current_kboard, Vreal_last_command) = real_this_command;
          if (!CONSP (last_command_event))
-           current_kboard->Vlast_repeatable_command = real_this_command;
+           KVAR (current_kboard, Vlast_repeatable_command) = real_this_command;
          cancel_echoing ();
          this_command_key_count = 0;
          this_command_key_count_reset = 0;
          this_single_command_key_start = 0;
        }
 
-      if (!NILP (current_buffer->mark_active)
+      if (!NILP (BVAR (current_buffer, mark_active))
          && !NILP (Vrun_hooks))
        {
          /* In Emacs 22, setting transient-mark-mode to `only' was a
@@ -1794,7 +1593,7 @@ command_loop_1 (void)
              if (!NILP (Fwindow_system (Qnil))
                  /* Even if mark_active is non-nil, the actual buffer
                     marker may not have been set yet (Bug#7044).  */
-                 && XMARKER (current_buffer->mark)->buffer
+                 && XMARKER (BVAR (current_buffer, mark))->buffer
                  && (EQ (Vselect_active_regions, Qonly)
                      ? EQ (CAR_SAFE (Vtransient_mark_mode), Qonly)
                      : (!NILP (Vselect_active_regions)
@@ -1802,7 +1601,7 @@ command_loop_1 (void)
                  && !EQ (Vthis_command, Qhandle_switch_frame))
                {
                  EMACS_INT beg =
-                   XINT (Fmarker_position (current_buffer->mark));
+                   XINT (Fmarker_position (BVAR (current_buffer, mark)));
                  EMACS_INT end = PT;
                  if (beg < end)
                    call2 (Qx_set_selection, QPRIMARY,
@@ -1814,7 +1613,10 @@ command_loop_1 (void)
                }
 
              if (current_buffer != prev_buffer || MODIFF != prev_modiff)
-               call1 (Vrun_hooks, intern ("activate-mark-hook"));
+                {
+                  Lisp_Object hook = intern ("activate-mark-hook");
+                  Frun_hooks (1, &hook);
+                }
            }
 
          Vsaved_region_selection = Qnil;
@@ -1844,8 +1646,8 @@ command_loop_1 (void)
 
       /* Install chars successfully executed in kbd macro.  */
 
-      if (!NILP (current_kboard->defining_kbd_macro)
-         && NILP (current_kboard->Vprefix_arg))
+      if (!NILP (KVAR (current_kboard, defining_kbd_macro))
+         && NILP (KVAR (current_kboard, Vprefix_arg)))
        finalize_kbd_macro_chars ();
 #if 0 /* This shouldn't be necessary anymore.  --lorentey  */
       if (!was_locked)
@@ -2012,22 +1814,63 @@ adjust_point_for_property (EMACS_INT last_pt, int modified)
 static Lisp_Object
 safe_run_hooks_1 (void)
 {
-  if (NILP (Vrun_hooks))
-    return Qnil;
-  return call1 (Vrun_hooks, Vinhibit_quit);
+  eassert (CONSP (Vinhibit_quit));
+  return call0 (XCDR (Vinhibit_quit));
 }
 
-/* Subroutine for safe_run_hooks: handle an error by clearing out the hook.  */
+/* Subroutine for safe_run_hooks: handle an error by clearing out the function
+   from the hook.  */
+
+static Lisp_Object
+safe_run_hooks_error (Lisp_Object error_data)
+{
+  Lisp_Object hook
+    = CONSP (Vinhibit_quit) ? XCAR (Vinhibit_quit) : Vinhibit_quit;
+  Lisp_Object fun = CONSP (Vinhibit_quit) ? XCDR (Vinhibit_quit) : Qnil;
+  Lisp_Object args[4];
+  args[0] = build_string ("Error in %s (%s): %s");
+  args[1] = hook;
+  args[2] = fun;
+  args[3] = error_data;
+  Fmessage (4, args);
+  if (SYMBOLP (hook))
+    {
+      Lisp_Object val;
+      int found = 0;
+      Lisp_Object newval = Qnil;
+      for (val = find_symbol_value (hook); CONSP (val); val = XCDR (val))
+       if (EQ (fun, XCAR (val)))
+         found = 1;
+       else
+         newval = Fcons (XCAR (val), newval);
+      if (found)
+       return Fset (hook, Fnreverse (newval));
+      /* Not found in the local part of the hook.  Let's look at the global
+        part.  */
+      newval = Qnil;
+      for (val = (NILP (Fdefault_boundp (hook)) ? Qnil
+                 : Fdefault_value (hook));
+          CONSP (val); val = XCDR (val))
+       if (EQ (fun, XCAR (val)))
+         found = 1;
+       else
+         newval = Fcons (XCAR (val), newval);
+      if (found)
+       return Fset_default (hook, Fnreverse (newval));
+    }
+  return Qnil;
+}
 
 static Lisp_Object
-safe_run_hooks_error (Lisp_Object data)
+safe_run_hook_funcall (size_t nargs, Lisp_Object *args)
 {
-  Lisp_Object args[3];
-  args[0] = build_string ("Error in %s: %s");
-  args[1] = Vinhibit_quit;
-  args[2] = data;
-  Fmessage (3, args);
-  return Fset (Vinhibit_quit, Qnil);
+  eassert (nargs == 1);
+  if (CONSP (Vinhibit_quit))
+    XSETCDR (Vinhibit_quit, args[0]);
+  else
+    Vinhibit_quit = Fcons (Vinhibit_quit, args[0]);
+
+  return internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error);
 }
 
 /* If we get an error while running the hook, cause the hook variable
@@ -2037,20 +1880,18 @@ safe_run_hooks_error (Lisp_Object data)
 void
 safe_run_hooks (Lisp_Object hook)
 {
+  /* FIXME: our `internal_condition_case' does not provide any way to pass data
+     to its body or to its handlers other than via globals such as
+     dynamically-bound variables ;-)  */
   int count = SPECPDL_INDEX ();
   specbind (Qinhibit_quit, hook);
 
-  internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error);
+  run_hook_with_args (1, &hook, safe_run_hook_funcall);
 
   unbind_to (count, Qnil);
 }
 
 \f
-/* Number of seconds between polling for input.  This is a Lisp
-   variable that can be bound.  */
-
-EMACS_INT polling_period;
-
 /* Nonzero means polling for input is temporarily suppressed.  */
 
 int poll_suppress_count;
@@ -2085,7 +1926,7 @@ poll_for_input_1 (void)
 /* Timer callback function for poll_timer.  TIMER is equal to
    poll_timer.  */
 
-void
+static void
 poll_for_input (struct atimer *timer)
 {
   if (poll_suppress_count == 0)
@@ -2272,16 +2113,12 @@ make_ctrl_char (int c)
    the `display' property).  POS is the position in that string under
    the mouse.
 
-   OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
-   echo overwrites a keystroke echo currently displayed in the echo
-   area.
-
    Note: this function may only be called with HELP nil or a string
    from X code running asynchronously.  */
 
 void
 show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object,
-               Lisp_Object pos, int ok_to_overwrite_keystroke_echo)
+               Lisp_Object pos)
 {
   if (!NILP (help) && !STRINGP (help))
     {
@@ -2384,7 +2221,7 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
           int *used_mouse_menu, struct timeval *end_time)
 {
   volatile Lisp_Object c;
-  int count, jmpcount;
+  int jmpcount;
   jmp_buf local_getcjmp;
   jmp_buf save_jump;
   volatile int key_already_recorded = 0;
@@ -2661,21 +2498,21 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
        KBOARD *kb = FRAME_KBOARD (XFRAME (selected_frame));
        if (kb != current_kboard)
          {
-           Lisp_Object link = kb->kbd_queue;
+           Lisp_Object last = KVAR (kb, kbd_queue);
            /* We shouldn't get here if we were in single-kboard mode!  */
            if (single_kboard)
              abort ();
-           if (CONSP (link))
+           if (CONSP (last))
              {
-               while (CONSP (XCDR (link)))
-                 link = XCDR (link);
-               if (!NILP (XCDR (link)))
+               while (CONSP (XCDR (last)))
+                 last = XCDR (last);
+               if (!NILP (XCDR (last)))
                  abort ();
              }
-           if (!CONSP (link))
-             kb->kbd_queue = Fcons (c, Qnil);
+           if (!CONSP (last))
+             KVAR (kb, kbd_queue) = Fcons (c, Qnil);
            else
-             XSETCDR (link, Fcons (c, Qnil));
+             XSETCDR (last, Fcons (c, Qnil));
            kb->kbd_queue_has_data = 1;
            current_kboard = kb;
            /* This is going to exit from read_char
@@ -2845,12 +2682,12 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
     {
       if (current_kboard->kbd_queue_has_data)
        {
-         if (!CONSP (current_kboard->kbd_queue))
+         if (!CONSP (KVAR (current_kboard, kbd_queue)))
            abort ();
-         c = XCAR (current_kboard->kbd_queue);
-         current_kboard->kbd_queue
-           = XCDR (current_kboard->kbd_queue);
-         if (NILP (current_kboard->kbd_queue))
+         c = XCAR (KVAR (current_kboard, kbd_queue));
+         KVAR (current_kboard, kbd_queue)
+           = XCDR (KVAR (current_kboard, kbd_queue));
+         if (NILP (KVAR (current_kboard, kbd_queue)))
            current_kboard->kbd_queue_has_data = 0;
          input_pending = readable_events (0);
          if (EVENT_HAS_PARAMETERS (c)
@@ -2892,7 +2729,7 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
 
   if (NILP (c))
     {
-      KBOARD *kb;
+      KBOARD *kb IF_LINT (= NULL);
 
       if (end_time)
        {
@@ -2912,18 +2749,18 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
 
       if (! NILP (c) && (kb != current_kboard))
        {
-         Lisp_Object link = kb->kbd_queue;
-         if (CONSP (link))
+         Lisp_Object last = KVAR (kb, kbd_queue);
+         if (CONSP (last))
            {
-             while (CONSP (XCDR (link)))
-               link = XCDR (link);
-             if (!NILP (XCDR (link)))
+             while (CONSP (XCDR (last)))
+               last = XCDR (last);
+             if (!NILP (XCDR (last)))
                abort ();
            }
-         if (!CONSP (link))
-           kb->kbd_queue = Fcons (c, Qnil);
+         if (!CONSP (last))
+           KVAR (kb, kbd_queue) = Fcons (c, Qnil);
          else
-           XSETCDR (link, Fcons (c, Qnil));
+           XSETCDR (last, Fcons (c, Qnil));
          kb->kbd_queue_has_data = 1;
          c = Qnil;
          if (single_kboard)
@@ -3029,15 +2866,15 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
       if (XINT (c) == -1)
        goto exit;
 
-      if ((STRINGP (current_kboard->Vkeyboard_translate_table)
-          && SCHARS (current_kboard->Vkeyboard_translate_table) > (unsigned) XFASTINT (c))
-         || (VECTORP (current_kboard->Vkeyboard_translate_table)
-             && XVECTOR (current_kboard->Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
-         || (CHAR_TABLE_P (current_kboard->Vkeyboard_translate_table)
+      if ((STRINGP (KVAR (current_kboard, Vkeyboard_translate_table))
+          && SCHARS (KVAR (current_kboard, Vkeyboard_translate_table)) > (unsigned) XFASTINT (c))
+         || (VECTORP (KVAR (current_kboard, Vkeyboard_translate_table))
+             && XVECTOR (KVAR (current_kboard, Vkeyboard_translate_table))->size > (unsigned) XFASTINT (c))
+         || (CHAR_TABLE_P (KVAR (current_kboard, Vkeyboard_translate_table))
              && CHARACTERP (c)))
        {
          Lisp_Object d;
-         d = Faref (current_kboard->Vkeyboard_translate_table, c);
+         d = Faref (KVAR (current_kboard, Vkeyboard_translate_table), c);
          /* nil in keyboard-translate-table means no translation.  */
          if (!NILP (d))
            c = d;
@@ -3112,13 +2949,13 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
     {
       Lisp_Object keys;
       int key_count, key_count_reset;
-      struct gcpro gcpro1;
+      struct gcpro inner_gcpro1;
       int count = SPECPDL_INDEX ();
 
       /* Save the echo status.  */
       int saved_immediate_echo = current_kboard->immediate_echo;
       struct kboard *saved_ok_to_echo = ok_to_echo_at_next_pause;
-      Lisp_Object saved_echo_string = current_kboard->echo_string;
+      Lisp_Object saved_echo_string = KVAR (current_kboard, echo_string);
       int saved_echo_after_prompt = current_kboard->echo_after_prompt;
 
 #if 0
@@ -3140,7 +2977,7 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
        keys = Fcopy_sequence (this_command_keys);
       else
        keys = Qnil;
-      GCPRO1 (keys);
+      GCPRO1_VAR (keys, inner_gcpro);
 
       /* Clear out this_command_keys.  */
       this_command_key_count = 0;
@@ -3173,12 +3010,12 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
 
       cancel_echoing ();
       ok_to_echo_at_next_pause = saved_ok_to_echo;
-      current_kboard->echo_string = saved_echo_string;
+      KVAR (current_kboard, echo_string) = saved_echo_string;
       current_kboard->echo_after_prompt = saved_echo_after_prompt;
       if (saved_immediate_echo)
        echo_now ();
 
-      UNGCPRO;
+      UNGCPRO_VAR (inner_gcpro);
 
       /* The input method can return no events.  */
       if (! CONSP (tem))
@@ -3200,18 +3037,18 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
   if (CONSP (c) && EQ (XCAR (c), Qhelp_echo))
     {
       /* (help-echo FRAME HELP WINDOW OBJECT POS).  */
-      Lisp_Object help, object, position, window, tem;
+      Lisp_Object help, object, position, window, htem;
 
-      tem = Fcdr (XCDR (c));
-      help = Fcar (tem);
-      tem = Fcdr (tem);
-      window = Fcar (tem);
-      tem = Fcdr (tem);
-      object = Fcar (tem);
-      tem = Fcdr (tem);
-      position = Fcar (tem);
+      htem = Fcdr (XCDR (c));
+      help = Fcar (htem);
+      htem = Fcdr (htem);
+      window = Fcar (htem);
+      htem = Fcdr (htem);
+      object = Fcar (htem);
+      htem = Fcdr (htem);
+      position = Fcar (htem);
 
-      show_help_echo (help, window, object, position, 0);
+      show_help_echo (help, window, object, position);
 
       /* We stopped being idle for this event; undo that.  */
       if (!end_time)
@@ -3251,14 +3088,14 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event
   if (!NILP (Vhelp_form) && help_char_p (c))
     {
       Lisp_Object tem0;
-      count = SPECPDL_INDEX ();
+      int count = SPECPDL_INDEX ();
 
       help_form_saved_window_configs
        = Fcons (Fcurrent_window_configuration (Qnil),
                 help_form_saved_window_configs);
       record_unwind_protect (read_char_help_form_unwind, Qnil);
 
-      tem0 = Feval (Vhelp_form);
+      tem0 = Feval (Vhelp_form, Qnil);
       if (STRINGP (tem0))
        internal_with_output_to_temp_buffer ("*Help*", print_help, tem0);
 
@@ -3513,7 +3350,7 @@ static int
 readable_events (int flags)
 {
   if (flags & READABLE_EVENTS_DO_TIMERS_NOW)
-    timer_check (1);
+    timer_check ();
 
   /* If the buffer contains only FOCUS_IN_EVENT events, and
      READABLE_EVENTS_FILTER_EVENTS is set, report it as empty.  */
@@ -3611,11 +3448,7 @@ kbd_buffer_nr_stored (void)
        : ((kbd_buffer + KBD_BUFFER_SIZE) - kbd_fetch_ptr
           + (kbd_store_ptr - kbd_buffer)));
 }
-#endif /* subprocesses */
-
-Lisp_Object Vthrow_on_input;
-
-/* Store an event obtained at interrupt level into kbd_buffer, fifo */
+#endif /* Store an event obtained at interrupt level into kbd_buffer, fifo */
 
 void
 kbd_buffer_store_event (register struct input_event *event)
@@ -3663,7 +3496,7 @@ kbd_buffer_store_event_hold (register struct input_event *event,
 
          if (single_kboard && kb != current_kboard)
            {
-             kb->kbd_queue
+             KVAR (kb, kbd_queue)
                = Fcons (make_lispy_switch_frame (event->frame_or_window),
                         Fcons (make_number (c), Qnil));
              kb->kbd_queue_has_data = 1;
@@ -4228,7 +4061,7 @@ kbd_buffer_get_event (KBOARD **kbp,
       Lisp_Object bar_window;
       enum scroll_bar_part part;
       Lisp_Object x, y;
-      unsigned long time;
+      unsigned long t;
 
       *kbp = current_kboard;
       /* Note that this uses F to determine which terminal to look at.
@@ -4239,7 +4072,7 @@ kbd_buffer_get_event (KBOARD **kbp,
       /* XXX Can f or mouse_position_hook be NULL here? */
       if (f && FRAME_TERMINAL (f)->mouse_position_hook)
         (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, 0, &bar_window,
-                                                    &part, &x, &y, &time);
+                                                    &part, &x, &y, &t);
 
       obj = Qnil;
 
@@ -4263,7 +4096,7 @@ kbd_buffer_get_event (KBOARD **kbp,
       /* If we didn't decide to make a switch-frame event, go ahead and
         return a mouse-motion event.  */
       if (!NILP (x) && NILP (obj))
-       obj = make_lispy_movement (f, bar_window, part, x, y, time);
+       obj = make_lispy_movement (f, bar_window, part, x, y, t);
     }
 #endif /* HAVE_MOUSE || HAVE GPM */
   else
@@ -4591,14 +4424,10 @@ timer_check_2 (void)
    Returns the time to wait until the next timer fires.
    If no timer is active, return -1.
 
-   As long as any timer is ripe, we run it.
-
-   DO_IT_NOW is now ignored.  It used to mean that we should
-   run the timer directly instead of queueing a timer-event.
-   Now we always run timers directly.  */
+   As long as any timer is ripe, we run it.  */
 
 EMACS_TIME
-timer_check (int do_it_now)
+timer_check (void)
 {
   EMACS_TIME nexttime;
 
@@ -5232,16 +5061,6 @@ static int last_mouse_x;
 static int last_mouse_y;
 static unsigned long button_down_time;
 
-/* The maximum time between clicks to make a double-click, or Qnil to
-   disable double-click detection, or Qt for no time limit.  */
-
-Lisp_Object Vdouble_click_time;
-
-/* Maximum number of pixels the mouse may be moved between clicks
-   to make a double-click.  */
-
-EMACS_INT double_click_fuzz;
-
 /* The number of clicks in this multiple-click. */
 
 int double_click_count;
@@ -5251,7 +5070,7 @@ int double_click_count;
 
 static Lisp_Object
 make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
-                    unsigned long time)
+                    unsigned long t)
 {
   enum window_part part;
   Lisp_Object posn = Qnil;
@@ -5367,8 +5186,12 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
          int width2, height2;
          /* The pixel X coordinate passed to buffer_posn_from_coords
             is the X coordinate relative to the text area for
-            text-area clicks, zero otherwise.  */
-         int x2 = (part == ON_TEXT) ? xret : 0;
+            text-area and right-margin clicks, zero otherwise.  */
+         int x2
+           = (part == ON_TEXT) ? xret
+           : (part == ON_RIGHT_FRINGE || part == ON_RIGHT_MARGIN)
+           ? (XINT (x) - window_box_left (w, TEXT_AREA))
+           : 0;
          int y2 = wy;
 
          string2 = buffer_posn_from_coords (w, &x2, &y2, &p,
@@ -5428,7 +5251,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
                Fcons (posn,
                       Fcons (Fcons (make_number (xret),
                                     make_number (yret)),
-                             Fcons (make_number (time),
+                             Fcons (make_number (t),
                                     extra_info))));
 }
 
@@ -5532,13 +5355,13 @@ make_lispy_event (struct input_event *event)
        {
          /* We need to use an alist rather than a vector as the cache
             since we can't make a vector long enuf.  */
-         if (NILP (current_kboard->system_key_syms))
-           current_kboard->system_key_syms = Fcons (Qnil, Qnil);
+         if (NILP (KVAR (current_kboard, system_key_syms)))
+           KVAR (current_kboard, system_key_syms) = Fcons (Qnil, Qnil);
          return modify_event_symbol (event->code,
                                      event->modifiers,
                                      Qfunction_key,
-                                     current_kboard->Vsystem_key_alist,
-                                     0, &current_kboard->system_key_syms,
+                                     KVAR (current_kboard, Vsystem_key_alist),
+                                     0, &KVAR (current_kboard, system_key_syms),
                                      (unsigned) -1);
        }
 
@@ -5613,7 +5436,6 @@ make_lispy_event (struct input_event *event)
                && (event->modifiers & down_modifier))
              {
                Lisp_Object items, item;
-               int hpos;
                int i;
 
                /* Find the menu bar item under `column'.  */
@@ -5852,19 +5674,19 @@ make_lispy_event (struct input_event *event)
          /* On window-system frames, use the value of
             double-click-fuzz as is.  On other frames, interpret it
             as a multiple of 1/8 characters.  */
-         struct frame *f;
+         struct frame *fr;
          int fuzz;
          int symbol_num;
          int is_double;
 
          if (WINDOWP (event->frame_or_window))
-           f = XFRAME (XWINDOW (event->frame_or_window)->frame);
+           fr = XFRAME (XWINDOW (event->frame_or_window)->frame);
          else if (FRAMEP (event->frame_or_window))
-           f = XFRAME (event->frame_or_window);
+           fr = XFRAME (event->frame_or_window);
          else
            abort ();
 
-         fuzz = FRAME_WINDOW_P (f)
+         fuzz = FRAME_WINDOW_P (fr)
            ? double_click_fuzz : double_click_fuzz / 8;
 
          if (event->modifiers & up_modifier)
@@ -6137,7 +5959,7 @@ make_lispy_event (struct input_event *event)
 
 static Lisp_Object
 make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part,
-                    Lisp_Object x, Lisp_Object y, unsigned long time)
+                    Lisp_Object x, Lisp_Object y, unsigned long t)
 {
   /* Is it a scroll bar movement?  */
   if (frame && ! NILP (bar_window))
@@ -6149,7 +5971,7 @@ make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_pa
                    Fcons (list5 (bar_window,
                                  Qvertical_scroll_bar,
                                  Fcons (x, y),
-                                 make_number (time),
+                                 make_number (t),
                                  part_sym),
                           Qnil));
     }
@@ -6157,7 +5979,7 @@ make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_pa
   else
     {
       Lisp_Object position;
-      position = make_lispy_position (frame, x, y, time);
+      position = make_lispy_position (frame, x, y, t);
       return list2 (Qmouse_movement, position);
     }
 }
@@ -6182,10 +6004,10 @@ make_lispy_switch_frame (Lisp_Object frame)
    This doesn't use any caches.  */
 
 static int
-parse_modifiers_uncached (Lisp_Object symbol, int *modifier_end)
+parse_modifiers_uncached (Lisp_Object symbol, EMACS_INT *modifier_end)
 {
   Lisp_Object name;
-  int i;
+  EMACS_INT i;
   int modifiers;
 
   CHECK_SYMBOL (symbol);
@@ -6195,7 +6017,7 @@ parse_modifiers_uncached (Lisp_Object symbol, int *modifier_end)
 
   for (i = 0; i+2 <= SBYTES (name); )
     {
-      int this_mod_end = 0;
+      EMACS_INT this_mod_end = 0;
       int this_mod = 0;
 
       /* See if the name continues with a modifier word.
@@ -6235,7 +6057,7 @@ parse_modifiers_uncached (Lisp_Object symbol, int *modifier_end)
 
 #define MULTI_LETTER_MOD(BIT, NAME, LEN)                       \
          if (i + LEN + 1 <= SBYTES (name)                      \
-             && ! strncmp (SDATA (name) + i, NAME, LEN))       \
+             && ! strncmp (SSDATA (name) + i, NAME, LEN))      \
            {                                                   \
              this_mod_end = i + LEN;                           \
              this_mod = BIT;                                   \
@@ -6273,13 +6095,13 @@ parse_modifiers_uncached (Lisp_Object symbol, int *modifier_end)
   if (! (modifiers & (down_modifier | drag_modifier
                      | double_modifier | triple_modifier))
       && i + 7 == SBYTES (name)
-      && strncmp (SDATA (name) + i, "mouse-", 6) == 0
+      && strncmp (SSDATA (name) + i, "mouse-", 6) == 0
       && ('0' <= SREF (name, i + 6) && SREF (name, i + 6) <= '9'))
     modifiers |= click_modifier;
 
   if (! (modifiers & (double_modifier | triple_modifier))
       && i + 6 < SBYTES (name)
-      && strncmp (SDATA (name) + i, "wheel-", 6) == 0)
+      && strncmp (SSDATA (name) + i, "wheel-", 6) == 0)
     modifiers |= click_modifier;
 
   if (modifier_end)
@@ -6392,12 +6214,12 @@ parse_modifiers (Lisp_Object symbol)
     return elements;
   else
     {
-      int end;
+      EMACS_INT end;
       int modifiers = parse_modifiers_uncached (symbol, &end);
       Lisp_Object unmodified;
       Lisp_Object mask;
 
-      unmodified = Fintern (make_string (SDATA (SYMBOL_NAME (symbol)) + end,
+      unmodified = Fintern (make_string (SSDATA (SYMBOL_NAME (symbol)) + end,
                                         SBYTES (SYMBOL_NAME (symbol)) - end),
                            Qnil);
 
@@ -6446,7 +6268,7 @@ DEFUN ("internal-event-symbol-parse-modifiers", Fevent_symbol_parse_modifiers,
 static Lisp_Object
 apply_modifiers (int modifiers, Lisp_Object base)
 {
-  Lisp_Object cache, index, entry, new_symbol;
+  Lisp_Object cache, idx, entry, new_symbol;
 
   /* Mask out upper bits.  We don't know where this value's been.  */
   modifiers &= INTMASK;
@@ -6456,8 +6278,8 @@ apply_modifiers (int modifiers, Lisp_Object base)
 
   /* The click modifier never figures into cache indices.  */
   cache = Fget (base, Qmodifier_cache);
-  XSETFASTINT (index, (modifiers & ~click_modifier));
-  entry = assq_no_quit (index, cache);
+  XSETFASTINT (idx, (modifiers & ~click_modifier));
+  entry = assq_no_quit (idx, cache);
 
   if (CONSP (entry))
     new_symbol = XCDR (entry);
@@ -6465,19 +6287,19 @@ apply_modifiers (int modifiers, Lisp_Object base)
     {
       /* We have to create the symbol ourselves.  */
       new_symbol = apply_modifiers_uncached (modifiers,
-                                            SDATA (SYMBOL_NAME (base)),
+                                            SSDATA (SYMBOL_NAME (base)),
                                             SCHARS (SYMBOL_NAME (base)),
                                             SBYTES (SYMBOL_NAME (base)));
 
       /* Add the new symbol to the base's cache.  */
-      entry = Fcons (index, new_symbol);
+      entry = Fcons (idx, new_symbol);
       Fput (base, Qmodifier_cache, Fcons (entry, cache));
 
       /* We have the parsing info now for free, so we could add it to
         the caches:
-         XSETFASTINT (index, modifiers);
+         XSETFASTINT (idx, modifiers);
          Fput (new_symbol, Qevent_symbol_element_mask,
-               Fcons (base, Fcons (index, Qnil)));
+               Fcons (base, Fcons (idx, Qnil)));
          Fput (new_symbol, Qevent_symbol_elements,
                Fcons (base, lispy_modifier_list (modifiers)));
         Sadly, this is only correct if `base' is indeed a base event,
@@ -6728,7 +6550,7 @@ parse_solitary_modifier (Lisp_Object symbol)
 
 #define MULTI_LETTER_MOD(BIT, NAME, LEN)               \
       if (LEN == SBYTES (name)                         \
-         && ! strncmp (SDATA (name), NAME, LEN))       \
+         && ! strncmp (SSDATA (name), NAME, LEN))      \
        return BIT;
 
     case 'A':
@@ -7031,16 +6853,17 @@ decode_keyboard_code (struct tty_display_info *tty,
     return;
   for (i = 0, p = coding->destination; i < coding->produced_char; i++)
     {
-      struct input_event buf;
+      struct input_event event_buf;
 
-      EVENT_INIT (buf);
-      buf.code = STRING_CHAR_ADVANCE (p);
-      buf.kind = (ASCII_CHAR_P (buf.code)
-                 ? ASCII_KEYSTROKE_EVENT : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
+      EVENT_INIT (event_buf);
+      event_buf.code = STRING_CHAR_ADVANCE (p);
+      event_buf.kind =
+       (ASCII_CHAR_P (event_buf.code)
+        ? ASCII_KEYSTROKE_EVENT : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
       /* See the comment in tty_read_avail_input.  */
-      buf.frame_or_window = tty->top_frame;
-      buf.arg = Qnil;
-      kbd_buffer_store_event (&buf);
+      event_buf.frame_or_window = tty->top_frame;
+      event_buf.arg = Qnil;
+      kbd_buffer_store_event (&event_buf);
     }
 }
 
@@ -7100,11 +6923,11 @@ tty_read_avail_input (struct terminal *terminal,
   if (gpm_tty == tty)
   {
       Gpm_Event event;
-      struct input_event hold_quit;
+      struct input_event gpm_hold_quit;
       int gpm, fd = gpm_fd;
 
-      EVENT_INIT (hold_quit);
-      hold_quit.kind = NO_EVENT;
+      EVENT_INIT (gpm_hold_quit);
+      gpm_hold_quit.kind = NO_EVENT;
 
       /* gpm==1 if event received.
          gpm==0 if the GPM daemon has closed the connection, in which case
@@ -7113,13 +6936,13 @@ tty_read_avail_input (struct terminal *terminal,
                select masks.
          gpm==-1 if a protocol error or EWOULDBLOCK; the latter is normal. */
       while (gpm = Gpm_GetEvent (&event), gpm == 1) {
-         nread += handle_one_term_event (tty, &event, &hold_quit);
+         nread += handle_one_term_event (tty, &event, &gpm_hold_quit);
       }
       if (gpm == 0)
        /* Presumably the GPM daemon has closed the connection.  */
        close_gpm (fd);
-      if (hold_quit.kind != NO_EVENT)
-         kbd_buffer_store_event (&hold_quit);
+      if (gpm_hold_quit.kind != NO_EVENT)
+         kbd_buffer_store_event (&gpm_hold_quit);
       if (nread)
          return nread;
   }
@@ -7159,7 +6982,7 @@ tty_read_avail_input (struct terminal *terminal,
      NREAD is set to the number of chars read.  */
   do
     {
-      nread = emacs_read (fileno (tty->input), cbuf, n_to_read);
+      nread = emacs_read (fileno (tty->input), (char *) cbuf, n_to_read);
       /* POSIX infers that processes which are not in the session leader's
          process group won't get SIGHUP's at logout time.  BSDI adheres to
          this part standard and returns -1 from read (0) with errno==EIO
@@ -7266,7 +7089,7 @@ tty_read_avail_input (struct terminal *terminal,
   return nread;
 }
 \f
-void
+static void
 handle_async_input (void)
 {
   interrupt_input_pending = 0;
@@ -7304,7 +7127,7 @@ process_pending_signals (void)
 #ifdef SIGIO   /* for entire page */
 /* Note SIGIO has been undef'd if FIONREAD is missing.  */
 
-static SIGTYPE
+static void
 input_available_signal (int signo)
 {
   /* Must preserve main program's value of errno.  */
@@ -7382,7 +7205,7 @@ add_user_signal (int sig, const char *name)
   signal (sig, handle_user_signal);
 }
 
-static SIGTYPE
+static void
 handle_user_signal (int sig)
 {
   int old_errno = errno;
@@ -7539,8 +7362,6 @@ menu_bar_items (Lisp_Object old)
   int mapno;
   Lisp_Object oquit;
 
-  int i;
-
   /* In order to build the menus, we need to call the keymap
      accessors.  They all call QUIT.  But this function is called
      during redisplay, during which a quit is fatal.  So inhibit
@@ -7570,8 +7391,8 @@ menu_bar_items (Lisp_Object old)
        /* Yes, use them (if non-nil) as well as the global map.  */
        maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
        nmaps = 0;
-       if (!NILP (current_kboard->Voverriding_terminal_local_map))
-         maps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
+       if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map)))
+         maps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
        if (!NILP (Voverriding_local_map))
          maps[nmaps++] = Voverriding_local_map;
       }
@@ -7642,15 +7463,18 @@ menu_bar_items (Lisp_Object old)
     }
 
   /* Add nil, nil, nil, nil at the end.  */
-  i = menu_bar_items_index;
-  if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
-    menu_bar_items_vector = larger_vector (menu_bar_items_vector, 2 * i, Qnil);
-  /* Add this item.  */
-  XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
-  XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
-  XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
-  XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
-  menu_bar_items_index = i;
+  {
+    int i = menu_bar_items_index;
+    if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
+      menu_bar_items_vector =
+       larger_vector (menu_bar_items_vector, 2 * i, Qnil);
+    /* Add this item.  */
+    XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
+    XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
+    XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
+    XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
+    menu_bar_items_index = i;
+  }
 
   Vinhibit_quit = oquit;
   return menu_bar_items_vector;
@@ -7747,6 +7571,12 @@ menu_item_eval_property_1 (Lisp_Object arg)
   return Qnil;
 }
 
+static Lisp_Object
+eval_dyn (Lisp_Object form)
+{
+  return Feval (form, Qnil);
+}
+
 /* Evaluate an expression and return the result (or nil if something
    went wrong).  Used to evaluate dynamic parts of menu items.  */
 Lisp_Object
@@ -7755,7 +7585,7 @@ menu_item_eval_property (Lisp_Object sexpr)
   int count = SPECPDL_INDEX ();
   Lisp_Object val;
   specbind (Qinhibit_redisplay, Qt);
-  val = internal_condition_case_1 (Feval, sexpr, Qerror,
+  val = internal_condition_case_1 (eval_dyn, sexpr, Qerror,
                                   menu_item_eval_property_1);
   return unbind_to (count, val);
 }
@@ -8107,8 +7937,8 @@ tool_bar_items (Lisp_Object reuse, int *nitems)
       /* Yes, use them (if non-nil) as well as the global map.  */
       maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
       nmaps = 0;
-      if (!NILP (current_kboard->Voverriding_terminal_local_map))
-       maps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
+      if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map)))
+       maps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
       if (!NILP (Voverriding_local_map))
        maps[nmaps++] = Voverriding_local_map;
     }
@@ -8294,7 +8124,7 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
   item = XCDR (item);
   if (!CONSP (item))
     {
-      if (menu_separator_name_p (SDATA (caption)))
+      if (menu_separator_name_p (SSDATA (caption)))
        {
          PROP (TOOL_BAR_ITEM_TYPE) = Qt;
 #if !defined (USE_GTK) && !defined (HAVE_NS)
@@ -8322,12 +8152,12 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
   /* Process the rest of the properties.  */
   for (; CONSP (item) && CONSP (XCDR (item)); item = XCDR (XCDR (item)))
     {
-      Lisp_Object key, value;
+      Lisp_Object ikey, value;
 
-      key = XCAR (item);
+      ikey = XCAR (item);
       value = XCAR (XCDR (item));
 
-      if (EQ (key, QCenable))
+      if (EQ (ikey, QCenable))
        {
          /* `:enable FORM'.  */
          if (!NILP (Venable_disabled_menus_and_buttons))
@@ -8335,20 +8165,20 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
          else
            PROP (TOOL_BAR_ITEM_ENABLED_P) = value;
        }
-      else if (EQ (key, QCvisible))
+      else if (EQ (ikey, QCvisible))
        {
          /* `:visible FORM'.  If got a visible property and that
             evaluates to nil then ignore this item.  */
          if (NILP (menu_item_eval_property (value)))
            return 0;
        }
-      else if (EQ (key, QChelp))
+      else if (EQ (ikey, QChelp))
         /* `:help HELP-STRING'.  */
         PROP (TOOL_BAR_ITEM_HELP) = value;
-      else if (EQ (key, QCvert_only))
+      else if (EQ (ikey, QCvert_only))
         /* `:vert-only t/nil'.  */
         PROP (TOOL_BAR_ITEM_VERT_ONLY) = value;
-      else if (EQ (key, QClabel))
+      else if (EQ (ikey, QClabel))
         {
           const char *bad_label = "!!?GARBLED ITEM?!!";
           /* `:label LABEL-STRING'.  */
@@ -8357,10 +8187,10 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
             : make_string (bad_label, strlen (bad_label));
           have_label = 1;
         }
-      else if (EQ (key, QCfilter))
+      else if (EQ (ikey, QCfilter))
        /* ':filter FORM'.  */
        filter = value;
-      else if (EQ (key, QCbutton) && CONSP (value))
+      else if (EQ (ikey, QCbutton) && CONSP (value))
        {
          /* `:button (TYPE . SELECTED)'.  */
          Lisp_Object type, selected;
@@ -8373,13 +8203,13 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
              PROP (TOOL_BAR_ITEM_TYPE) = type;
            }
        }
-      else if (EQ (key, QCimage)
+      else if (EQ (ikey, QCimage)
               && (CONSP (value)
                   || (VECTORP (value) && XVECTOR (value)->size == 4)))
        /* Value is either a single image specification or a vector
           of 4 such specifications for the different button states.  */
        PROP (TOOL_BAR_ITEM_IMAGES) = value;
-      else if (EQ (key, Qrtl))
+      else if (EQ (ikey, Qrtl))
         /* ':rtl STRING' */
        PROP (TOOL_BAR_ITEM_RTL_IMAGE) = value;
     }
@@ -8388,35 +8218,34 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
   if (!have_label)
     {
       /* Try to make one from caption and key.  */
-      Lisp_Object key = PROP (TOOL_BAR_ITEM_KEY);
-      Lisp_Object capt = PROP (TOOL_BAR_ITEM_CAPTION);
-      const char *label = SYMBOLP (key) ? (char *) SDATA (SYMBOL_NAME (key)) : "";
-      const char *caption = STRINGP (capt) ? (char *) SDATA (capt) : "";
+      Lisp_Object tkey = PROP (TOOL_BAR_ITEM_KEY);
+      Lisp_Object tcapt = PROP (TOOL_BAR_ITEM_CAPTION);
+      const char *label = SYMBOLP (tkey) ? SSDATA (SYMBOL_NAME (tkey)) : "";
+      const char *capt = STRINGP (tcapt) ? SSDATA (tcapt) : "";
       EMACS_INT max_lbl = 2 * tool_bar_max_label_size;
       char *buf = (char *) xmalloc (max_lbl + 1);
       Lisp_Object new_lbl;
-      size_t caption_len = strlen (caption);
+      size_t caption_len = strlen (capt);
 
-      if (caption_len <= max_lbl && caption[0] != '\0')
+      if (caption_len <= max_lbl && capt[0] != '\0')
         {
-          strcpy (buf, caption);
+          strcpy (buf, capt);
           while (caption_len > 0 && buf[caption_len - 1] == '.')
             caption_len--;
          buf[caption_len] = '\0';
-         label = caption = buf;
+         label = capt = buf;
         }
 
       if (strlen (label) <= max_lbl && label[0] != '\0')
         {
-          int i;
+          int j;
           if (label != buf)
            strcpy (buf, label);
 
-          for (i = 0; buf[i] != '\0'; ++i)
-           if (buf[i] == '-')
-             buf[i] = ' ';
+          for (j = 0; buf[j] != '\0'; ++j)
+           if (buf[j] == '-')
+             buf[j] = ' ';
           label = buf;
-
         }
       else
        label = "";
@@ -8649,7 +8478,7 @@ read_char_minibuf_menu_prompt (int commandflag, int nmaps, Lisp_Object *maps)
   menu = read_char_minibuf_menu_text;
 
   /* Prompt string always starts with map's prompt, and a space.  */
-  strcpy (menu, SDATA (name));
+  strcpy (menu, SSDATA (name));
   nlength = SBYTES (name);
   menu[nlength++] = ':';
   menu[nlength++] = ' ';
@@ -8818,18 +8647,18 @@ read_char_minibuf_menu_prompt (int commandflag, int nmaps, Lisp_Object *maps)
 
       /* Prompt with that and read response.  */
       message2_nolog (menu, strlen (menu),
-                     ! NILP (current_buffer->enable_multibyte_characters));
+                     ! NILP (BVAR (current_buffer, enable_multibyte_characters)));
 
       /* Make believe its not a keyboard macro in case the help char
         is pressed.  Help characters are not recorded because menu prompting
         is not used on replay.
         */
-      orig_defn_macro = current_kboard->defining_kbd_macro;
-      current_kboard->defining_kbd_macro = Qnil;
+      orig_defn_macro = KVAR (current_kboard, defining_kbd_macro);
+      KVAR (current_kboard, defining_kbd_macro) = Qnil;
       do
        obj = read_char (commandflag, 0, 0, Qt, 0, NULL);
       while (BUFFERP (obj));
-      current_kboard->defining_kbd_macro = orig_defn_macro;
+      KVAR (current_kboard, defining_kbd_macro) = orig_defn_macro;
 
       if (!INTEGERP (obj))
        return obj;
@@ -8842,7 +8671,7 @@ read_char_minibuf_menu_prompt (int commandflag, int nmaps, Lisp_Object *maps)
          && (!INTEGERP (menu_prompt_more_char)
              || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char))))))
        {
-         if (!NILP (current_kboard->defining_kbd_macro))
+         if (!NILP (KVAR (current_kboard, defining_kbd_macro)))
            store_kbd_macro_char (obj);
          return obj;
        }
@@ -8970,7 +8799,7 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt,
    The return value is non-zero if the remapping actually took place.  */
 
 static int
-keyremap_step (Lisp_Object *keybuf, int bufsize, volatile keyremap *fkey,
+keyremap_step (Lisp_Object *keybuf, size_t bufsize, volatile keyremap *fkey,
               int input, int doit, int *diff, Lisp_Object prompt)
 {
   Lisp_Object next, key;
@@ -9063,7 +8892,7 @@ keyremap_step (Lisp_Object *keybuf, int bufsize, volatile keyremap *fkey,
    from the selected window's buffer.  */
 
 static int
-read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
+read_key_sequence (Lisp_Object *keybuf, size_t bufsize, Lisp_Object prompt,
                   int dont_downcase_last, int can_return_switch_frame,
                   int fix_current_buffer)
 {
@@ -9075,7 +8904,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
 
   /* The length of the echo buffer when we started reading, and
      the length of this_command_keys when we started reading.  */
-  int echo_start;
+  int echo_start IF_LINT (= 0);
   int keys_start;
 
   /* The number of keymaps we're scanning right now, and the number of
@@ -9153,7 +8982,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
   Lisp_Object first_event;
 #endif
 
-  Lisp_Object original_uppercase;
+  Lisp_Object original_uppercase IF_LINT (= Qnil);
   int original_uppercase_position = -1;
 
   /* Gets around Microsoft compiler limitations.  */
@@ -9168,9 +8997,9 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
   int junk;
 #endif
 
-  struct gcpro gcpro1;
+  struct gcpro outer_gcpro1;
 
-  GCPRO1 (fake_prefixed_keys);
+  GCPRO1_VAR (fake_prefixed_keys, outer_gcpro);
   raw_keybuf_count = 0;
 
   last_nonmenu_event = Qnil;
@@ -9184,7 +9013,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
          /* Install the string STR as the beginning of the string of
             echoing, so that it serves as a prompt for the next
             character.  */
-         current_kboard->echo_string = prompt;
+         KVAR (current_kboard, echo_string) = prompt;
          current_kboard->echo_after_prompt = SCHARS (prompt);
          echo_now ();
        }
@@ -9222,8 +9051,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
      happens if we switch keyboards between rescans.  */
  replay_entire_sequence:
 
-  indec.map = indec.parent = current_kboard->Vinput_decode_map;
-  fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
+  indec.map = indec.parent = KVAR (current_kboard, Vinput_decode_map);
+  fkey.map = fkey.parent = KVAR (current_kboard, Vlocal_function_key_map);
   keytran.map = keytran.parent = Vkey_translation_map;
   indec.start = indec.end = 0;
   fkey.start = fkey.end = 0;
@@ -9244,7 +9073,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
      the initial keymaps from the current buffer.  */
   nmaps = 0;
 
-  if (!NILP (current_kboard->Voverriding_terminal_local_map))
+  if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map)))
     {
       if (2 > nmaps_allocated)
        {
@@ -9252,7 +9081,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
          defs    = (Lisp_Object *) alloca (2 * sizeof (defs[0]));
          nmaps_allocated = 2;
        }
-      submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
+      submaps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
     }
   else if (!NILP (Voverriding_local_map))
     {
@@ -9332,7 +9161,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
         while those allow us to restart the entire key sequence,
         echo_local_start and keys_local_start allow us to throw away
         just one key.  */
-      int echo_local_start, keys_local_start, local_first_binding;
+      int echo_local_start IF_LINT (= 0);
+      int keys_local_start, local_first_binding;
 
       eassert (indec.end == t || (indec.end > t && indec.end <= mock_input));
       eassert (indec.start <= indec.end);
@@ -9428,29 +9258,29 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
 
                if (!NILP (delayed_switch_frame))
                  {
-                   interrupted_kboard->kbd_queue
+                   KVAR (interrupted_kboard, kbd_queue)
                      = Fcons (delayed_switch_frame,
-                              interrupted_kboard->kbd_queue);
+                              KVAR (interrupted_kboard, kbd_queue));
                    delayed_switch_frame = Qnil;
                  }
 
                while (t > 0)
-                 interrupted_kboard->kbd_queue
-                   = Fcons (keybuf[--t], interrupted_kboard->kbd_queue);
+                 KVAR (interrupted_kboard, kbd_queue)
+                   = Fcons (keybuf[--t], KVAR (interrupted_kboard, kbd_queue));
 
                /* If the side queue is non-empty, ensure it begins with a
                   switch-frame, so we'll replay it in the right context.  */
-               if (CONSP (interrupted_kboard->kbd_queue)
-                   && (key = XCAR (interrupted_kboard->kbd_queue),
+               if (CONSP (KVAR (interrupted_kboard, kbd_queue))
+                   && (key = XCAR (KVAR (interrupted_kboard, kbd_queue)),
                        !(EVENT_HAS_PARAMETERS (key)
                          && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)),
                                 Qswitch_frame))))
                  {
                    Lisp_Object frame;
                    XSETFRAME (frame, interrupted_frame);
-                   interrupted_kboard->kbd_queue
+                   KVAR (interrupted_kboard, kbd_queue)
                      = Fcons (make_lispy_switch_frame (frame),
-                              interrupted_kboard->kbd_queue);
+                              KVAR (interrupted_kboard, kbd_queue));
                  }
                mock_input = 0;
                orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
@@ -9464,7 +9294,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
          if (EQ (key, Qt))
            {
              unbind_to (count, Qnil);
-             UNGCPRO;
+             UNGCPRO_VAR (outer_gcpro);
              return -1;
            }
 
@@ -9580,80 +9410,84 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
                    last_real_key_start = t - 1;
                }
 
-             /* Key sequences beginning with mouse clicks are
-                read using the keymaps in the buffer clicked on,
-                not the current buffer.  If we're at the
-                beginning of a key sequence, switch buffers.  */
-             if (last_real_key_start == 0
-                 && WINDOWP (window)
-                 && BUFFERP (XWINDOW (window)->buffer)
-                 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
+             if (last_real_key_start == 0)
                {
-                 XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key;
-                 keybuf[t] = key;
-                 mock_input = t + 1;
-
-                 /* Arrange to go back to the original buffer once we're
-                    done reading the key sequence.  Note that we can't
-                    use save_excursion_{save,restore} here, because they
-                    save point as well as the current buffer; we don't
-                    want to save point, because redisplay may change it,
-                    to accommodate a Fset_window_start or something.  We
-                    don't want to do this at the top of the function,
-                    because we may get input from a subprocess which
-                    wants to change the selected window and stuff (say,
-                    emacsclient).  */
-                 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
-
-                 if (! FRAME_LIVE_P (XFRAME (selected_frame)))
-                   Fkill_emacs (Qnil);
-                 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
-                 orig_local_map = get_local_map (PT, current_buffer,
-                                                 Qlocal_map);
-                 orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
-                 goto replay_sequence;
-               }
+                 /* Key sequences beginning with mouse clicks are
+                    read using the keymaps in the buffer clicked on,
+                    not the current buffer.  If we're at the
+                    beginning of a key sequence, switch buffers.  */
+                 if (WINDOWP (window)
+                     && BUFFERP (XWINDOW (window)->buffer)
+                     && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
+                   {
+                     XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key;
+                     keybuf[t] = key;
+                     mock_input = t + 1;
+
+                     /* Arrange to go back to the original buffer once we're
+                        done reading the key sequence.  Note that we can't
+                        use save_excursion_{save,restore} here, because they
+                        save point as well as the current buffer; we don't
+                        want to save point, because redisplay may change it,
+                        to accommodate a Fset_window_start or something.  We
+                        don't want to do this at the top of the function,
+                        because we may get input from a subprocess which
+                        wants to change the selected window and stuff (say,
+                        emacsclient).  */
+                     record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
+
+                     if (! FRAME_LIVE_P (XFRAME (selected_frame)))
+                       Fkill_emacs (Qnil);
+                     set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
+                     orig_local_map = get_local_map (PT, current_buffer,
+                                                     Qlocal_map);
+                     orig_keymap = get_local_map (PT, current_buffer,
+                                                  Qkeymap);
+                     goto replay_sequence;
+                   }
 
-             /* For a mouse click, get the local text-property keymap
-                of the place clicked on, rather than point.  */
-             if (last_real_key_start == 0
-                 && CONSP (XCDR (key))
-                 && ! localized_local_map)
-               {
-                 Lisp_Object map_here, start, pos;
+                 /* For a mouse click, get the local text-property keymap
+                    of the place clicked on, rather than point.  */
+                 if (CONSP (XCDR (key))
+                     && ! localized_local_map)
+                   {
+                     Lisp_Object map_here, start, pos;
 
-                 localized_local_map = 1;
-                 start = EVENT_START (key);
+                     localized_local_map = 1;
+                     start = EVENT_START (key);
 
-                 if (CONSP (start) && POSN_INBUFFER_P (start))
-                   {
-                     pos = POSN_BUFFER_POSN (start);
-                     if (INTEGERP (pos)
-                         && XINT (pos) >= BEGV
-                         && XINT (pos) <= ZV)
+                     if (CONSP (start) && POSN_INBUFFER_P (start))
                        {
-                         map_here = get_local_map (XINT (pos),
-                                                   current_buffer, Qlocal_map);
-                         if (!EQ (map_here, orig_local_map))
+                         pos = POSN_BUFFER_POSN (start);
+                         if (INTEGERP (pos)
+                             && XINT (pos) >= BEGV
+                             && XINT (pos) <= ZV)
                            {
-                             orig_local_map = map_here;
-                             ++localized_local_map;
-                           }
+                             map_here = get_local_map (XINT (pos),
+                                                       current_buffer,
+                                                       Qlocal_map);
+                             if (!EQ (map_here, orig_local_map))
+                               {
+                                 orig_local_map = map_here;
+                                 ++localized_local_map;
+                               }
 
-                         map_here = get_local_map (XINT (pos),
-                                                    current_buffer, Qkeymap);
-                         if (!EQ (map_here, orig_keymap))
-                           {
-                             orig_keymap = map_here;
-                             ++localized_local_map;
-                           }
+                             map_here = get_local_map (XINT (pos),
+                                                       current_buffer,
+                                                       Qkeymap);
+                             if (!EQ (map_here, orig_keymap))
+                               {
+                                 orig_keymap = map_here;
+                                 ++localized_local_map;
+                               }
 
-                         if (localized_local_map > 1)
-                           {
-                             keybuf[t] = key;
-                             mock_input = t + 1;
+                             if (localized_local_map > 1)
+                               {
+                                 keybuf[t] = key;
+                                 mock_input = t + 1;
 
-                             goto replay_sequence;
+                                 goto replay_sequence;
+                               }
                            }
                        }
                    }
@@ -10042,7 +9876,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
          && /* indec.start >= t && fkey.start >= t && */ keytran.start >= t
          && INTEGERP (key)
          && ((CHARACTERP (make_number (XINT (key) & ~CHAR_MODIFIER_MASK))
-              && UPPERCASEP (XINT (key) & ~CHAR_MODIFIER_MASK))
+              && uppercasep (XINT (key) & ~CHAR_MODIFIER_MASK))
              || (XINT (key) & shift_modifier)))
        {
          Lisp_Object new_key;
@@ -10053,7 +9887,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
          if (XINT (key) & shift_modifier)
            XSETINT (new_key, XINT (key) & ~shift_modifier);
          else
-           XSETINT (new_key, (DOWNCASE (XINT (key) & ~CHAR_MODIFIER_MASK)
+           XSETINT (new_key, (downcase (XINT (key) & ~CHAR_MODIFIER_MASK)
                               | (XINT (key) & CHAR_MODIFIER_MASK)));
 
          /* We have to do this unconditionally, regardless of whether
@@ -10080,14 +9914,14 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
              /* Treat uppercase keys as shifted.  */
              || (INTEGERP (key)
                  && (KEY_TO_CHAR (key)
-                     < XCHAR_TABLE (current_buffer->downcase_table)->size)
-                 && UPPERCASEP (KEY_TO_CHAR (key))))
+                     < XCHAR_TABLE (BVAR (current_buffer, downcase_table))->size)
+                 && uppercasep (KEY_TO_CHAR (key))))
            {
              Lisp_Object new_key
                = (modifiers & shift_modifier
                   ? apply_modifiers (modifiers & ~shift_modifier,
                                      XCAR (breakdown))
-                  : make_number (DOWNCASE (KEY_TO_CHAR (key)) | modifiers));
+                  : make_number (downcase (KEY_TO_CHAR (key)) | modifiers));
 
              original_uppercase = key;
              original_uppercase_position = t - 1;
@@ -10147,7 +9981,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
       add_command_key (keybuf[t]);
     }
 
-  UNGCPRO;
+  UNGCPRO_VAR (outer_gcpro);
   return t;
 }
 
@@ -10194,11 +10028,11 @@ is nil, then the event will be put off until after the current key sequence.
 sequences, where they wouldn't conflict with ordinary bindings.  See
 `function-key-map' for more details.
 
-The optional fifth argument COMMAND-LOOP, if non-nil, means
+The optional fifth argument CMD-LOOP, if non-nil, means
 that this key sequence is being read by something that will
 read commands one after another.  It should be nil if the caller
 will read just one key sequence.  */)
-  (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object command_loop)
+  (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop)
 {
   Lisp_Object keybuf[30];
   register int i;
@@ -10210,9 +10044,9 @@ will read just one key sequence.  */)
   QUIT;
 
   specbind (Qinput_method_exit_on_first_char,
-           (NILP (command_loop) ? Qt : Qnil));
+           (NILP (cmd_loop) ? Qt : Qnil));
   specbind (Qinput_method_use_echo_area,
-           (NILP (command_loop) ? Qt : Qnil));
+           (NILP (cmd_loop) ? Qt : Qnil));
 
   memset (keybuf, 0, sizeof keybuf);
   GCPRO1 (keybuf[0]);
@@ -10255,7 +10089,7 @@ will read just one key sequence.  */)
 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
        Sread_key_sequence_vector, 1, 5, 0,
        doc: /* Like `read-key-sequence' but always return a vector.  */)
-  (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object command_loop)
+  (Lisp_Object prompt, Lisp_Object continue_echo, Lisp_Object dont_downcase_last, Lisp_Object can_return_switch_frame, Lisp_Object cmd_loop)
 {
   Lisp_Object keybuf[30];
   register int i;
@@ -10267,9 +10101,9 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
   QUIT;
 
   specbind (Qinput_method_exit_on_first_char,
-           (NILP (command_loop) ? Qt : Qnil));
+           (NILP (cmd_loop) ? Qt : Qnil));
   specbind (Qinput_method_use_echo_area,
-           (NILP (command_loop) ? Qt : Qnil));
+           (NILP (cmd_loop) ? Qt : Qnil));
 
   memset (keybuf, 0, sizeof keybuf);
   GCPRO1 (keybuf[0]);
@@ -10325,9 +10159,9 @@ a special event, so ignore the prefix argument and don't clear it.  */)
 
   if (NILP (special))
     {
-      prefixarg = current_kboard->Vprefix_arg;
+      prefixarg = KVAR (current_kboard, Vprefix_arg);
       Vcurrent_prefix_arg = prefixarg;
-      current_kboard->Vprefix_arg = Qnil;
+      KVAR (current_kboard, Vprefix_arg) = Qnil;
     }
   else
     prefixarg = Qnil;
@@ -10335,11 +10169,11 @@ a special event, so ignore the prefix argument and don't clear it.  */)
   if (SYMBOLP (cmd))
     {
       tem = Fget (cmd, Qdisabled);
-      if (!NILP (tem) && !NILP (Vrun_hooks))
+      if (!NILP (tem))
        {
          tem = Fsymbol_value (Qdisabled_command_function);
          if (!NILP (tem))
-           return call1 (Vrun_hooks, Qdisabled_command_function);
+           return Frun_hooks (1, &Qdisabled_command_function);
        }
     }
 
@@ -10461,7 +10295,7 @@ give to the command you invoke, if it asks for an argument.  */)
   UNGCPRO;
 
   function = Fintern (function, Qnil);
-  current_kboard->Vprefix_arg = prefixarg;
+  KVAR (current_kboard, Vprefix_arg) = prefixarg;
   Vthis_command = function;
   real_this_command = function;
 
@@ -10512,9 +10346,9 @@ give to the command you invoke, if it asks for an argument.  */)
          sprintf (newmessage, "You can run the command `%s' with %s",
                   SDATA (SYMBOL_NAME (function)),
                   SDATA (binding));
-         message2_nolog (newmessage,
-                         strlen (newmessage),
-                         STRING_MULTIBYTE (binding));
+         message2 (newmessage,
+                   strlen (newmessage),
+                   STRING_MULTIBYTE (binding));
          if (NUMBERP (Vsuggest_key_bindings))
            waited = sit_for (Vsuggest_key_bindings, 0, 2);
          else
@@ -10772,7 +10606,7 @@ If FILE is nil, close any open dribble file.  */)
   if (!NILP (file))
     {
       file = Fexpand_file_name (file, Qnil);
-      dribble = fopen (SDATA (file), "w");
+      dribble = fopen (SSDATA (file), "w");
       if (dribble == 0)
        report_file_error ("Opening dribble", Fcons (file, Qnil));
     }
@@ -10784,7 +10618,7 @@ DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0,
 Also end any kbd macro being defined.  */)
   (void)
 {
-  if (!NILP (current_kboard->defining_kbd_macro))
+  if (!NILP (KVAR (current_kboard, defining_kbd_macro)))
     {
       /* Discard the last command from the macro.  */
       Fcancel_kbd_macro_events ();
@@ -10823,6 +10657,7 @@ On such systems, Emacs starts a subshell instead of suspending.  */)
   int old_height, old_width;
   int width, height;
   struct gcpro gcpro1;
+  Lisp_Object hook;
 
   if (tty_list && tty_list->next)
     error ("There are other tty frames open; close them before suspending Emacs");
@@ -10831,8 +10666,8 @@ On such systems, Emacs starts a subshell instead of suspending.  */)
     CHECK_STRING (stuffstring);
 
   /* Run the functions in suspend-hook.  */
-  if (!NILP (Vrun_hooks))
-    call1 (Vrun_hooks, intern ("suspend-hook"));
+  hook = intern ("suspend-hook");
+  Frun_hooks (1, &hook);
 
   GCPRO1 (stuffstring);
   get_tty_size (fileno (CURTTY ()->input), &old_width, &old_height);
@@ -10856,8 +10691,8 @@ On such systems, Emacs starts a subshell instead of suspending.  */)
     change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
 
   /* Run suspend-resume-hook.  */
-  if (!NILP (Vrun_hooks))
-    call1 (Vrun_hooks, intern ("suspend-resume-hook"));
+  hook = intern ("suspend-resume-hook");
+  Frun_hooks (1, &hook);
 
   UNGCPRO;
   return Qnil;
@@ -10932,7 +10767,7 @@ clear_waiting_for_input (void)
    SIGINT was generated by C-g, so we call handle_interrupt.
    Otherwise, the handler kills Emacs.  */
 
-static SIGTYPE
+static void
 interrupt_signal (int signalnum)       /* If we don't have an argument, some */
                                        /* compilers complain in signal calls. */
 {
@@ -11434,30 +11269,30 @@ The `posn-' functions access elements of such lists.  */)
 void
 init_kboard (KBOARD *kb)
 {
-  kb->Voverriding_terminal_local_map = Qnil;
-  kb->Vlast_command = Qnil;
-  kb->Vreal_last_command = Qnil;
-  kb->Vkeyboard_translate_table = Qnil;
-  kb->Vlast_repeatable_command = Qnil;
-  kb->Vprefix_arg = Qnil;
-  kb->Vlast_prefix_arg = Qnil;
-  kb->kbd_queue = Qnil;
+  KVAR (kb, Voverriding_terminal_local_map) = Qnil;
+  KVAR (kb, Vlast_command) = Qnil;
+  KVAR (kb, Vreal_last_command) = Qnil;
+  KVAR (kb, Vkeyboard_translate_table) = Qnil;
+  KVAR (kb, Vlast_repeatable_command) = Qnil;
+  KVAR (kb, Vprefix_arg) = Qnil;
+  KVAR (kb, Vlast_prefix_arg) = Qnil;
+  KVAR (kb, kbd_queue) = Qnil;
   kb->kbd_queue_has_data = 0;
   kb->immediate_echo = 0;
-  kb->echo_string = Qnil;
+  KVAR (kb, echo_string) = Qnil;
   kb->echo_after_prompt = -1;
   kb->kbd_macro_buffer = 0;
   kb->kbd_macro_bufsize = 0;
-  kb->defining_kbd_macro = Qnil;
-  kb->Vlast_kbd_macro = Qnil;
+  KVAR (kb, defining_kbd_macro) = Qnil;
+  KVAR (kb, Vlast_kbd_macro) = Qnil;
   kb->reference_count = 0;
-  kb->Vsystem_key_alist = Qnil;
-  kb->system_key_syms = Qnil;
-  kb->Vwindow_system = Qt;     /* Unset.  */
-  kb->Vinput_decode_map = Fmake_sparse_keymap (Qnil);
-  kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
-  Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
-  kb->Vdefault_minibuffer_frame = Qnil;
+  KVAR (kb, Vsystem_key_alist) = Qnil;
+  KVAR (kb, system_key_syms) = Qnil;
+  KVAR (kb, Vwindow_system) = Qt;      /* Unset.  */
+  KVAR (kb, Vinput_decode_map) = Fmake_sparse_keymap (Qnil);
+  KVAR (kb, Vlocal_function_key_map) = Fmake_sparse_keymap (Qnil);
+  Fset_keymap_parent (KVAR (kb, Vlocal_function_key_map), Vfunction_key_map);
+  KVAR (kb, Vdefault_minibuffer_frame) = Qnil;
 }
 
 /*
@@ -11533,7 +11368,7 @@ init_keyboard (void)
   init_kboard (current_kboard);
   /* A value of nil for Vwindow_system normally means a tty, but we also use
      it for the initial terminal since there is no window system there.  */
-  current_kboard->Vwindow_system = Qnil;
+  KVAR (current_kboard, Vwindow_system) = Qnil;
 
   if (!noninteractive)
     {
@@ -11658,9 +11493,6 @@ syms_of_keyboard (void)
   Qdeferred_action_function = intern_c_string ("deferred-action-function");
   staticpro (&Qdeferred_action_function);
 
-  Qcommand_hook_internal = intern_c_string ("command-hook-internal");
-  staticpro (&Qcommand_hook_internal);
-
   Qfunction_key = intern_c_string ("function-key");
   staticpro (&Qfunction_key);
   Qmouse_click = intern_c_string ("mouse-click");
@@ -11780,12 +11612,12 @@ syms_of_keyboard (void)
   last_point_position_window = Qnil;
 
   {
-    const struct event_head *p;
+    int i;
+    int len = sizeof (head_table) / sizeof (head_table[0]);
 
-    for (p = head_table;
-        p < head_table + (sizeof (head_table) / sizeof (head_table[0]));
-        p++)
+    for (i = 0; i < len; i++)
       {
+       const struct event_head *p = &head_table[i];
        *p->var = intern_c_string (p->name);
        staticpro (p->var);
        Fput (*p->var, Qevent_kind, *p->kind);
@@ -11888,19 +11720,19 @@ syms_of_keyboard (void)
   defsubr (&Sposn_at_point);
   defsubr (&Sposn_at_x_y);
 
-  DEFVAR_LISP ("last-command-event", &last_command_event,
+  DEFVAR_LISP ("last-command-event", last_command_event,
                     doc: /* Last input event that was part of a command.  */);
 
-  DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event,
+  DEFVAR_LISP ("last-nonmenu-event", last_nonmenu_event,
               doc: /* Last input event in a command, except for mouse menu events.
 Mouse menus give back keys that don't look like mouse events;
 this variable holds the actual mouse event that led to the menu,
 so that you can determine whether the command was run by mouse or not.  */);
 
-  DEFVAR_LISP ("last-input-event", &last_input_event,
+  DEFVAR_LISP ("last-input-event", last_input_event,
               doc: /* Last input event.  */);
 
-  DEFVAR_LISP ("unread-command-events", &Vunread_command_events,
+  DEFVAR_LISP ("unread-command-events", Vunread_command_events,
               doc: /* List of events to be read as the command input.
 These events are processed first, before actual keyboard input.
 Events read from this list are not normally added to `this-command-keys',
@@ -11908,16 +11740,16 @@ as they will already have been added once as they were read for the first time.
 An element of the form (t . EVENT) forces EVENT to be added to that list.  */);
   Vunread_command_events = Qnil;
 
-  DEFVAR_INT ("unread-command-char", &unread_command_char,
+  DEFVAR_INT ("unread-command-char", unread_command_char,
              doc: /* If not -1, an object to be read as next command input event.  */);
 
-  DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events,
+  DEFVAR_LISP ("unread-post-input-method-events", Vunread_post_input_method_events,
               doc: /* List of events to be processed as input by input methods.
 These events are processed before `unread-command-events'
 and actual keyboard input, but are not given to `input-method-function'.  */);
   Vunread_post_input_method_events = Qnil;
 
-  DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events,
+  DEFVAR_LISP ("unread-input-method-events", Vunread_input_method_events,
               doc: /* List of events to be processed as input by input methods.
 These events are processed after `unread-command-events', but
 before actual keyboard input.
@@ -11925,7 +11757,7 @@ If there's an active input method, the events are given to
 `input-method-function'.  */);
   Vunread_input_method_events = Qnil;
 
-  DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char,
+  DEFVAR_LISP ("meta-prefix-char", meta_prefix_char,
               doc: /* Meta-prefix character code.
 Meta-foo as command input turns into this character followed by foo.  */);
   XSETINT (meta_prefix_char, 033);
@@ -11955,59 +11787,59 @@ See Info node `(elisp)Multiple Terminals'.  */);
 The last command executed that was not bound to an input event.
 This is the command `repeat' will try to repeat.  */);
 
-  DEFVAR_LISP ("this-command", &Vthis_command,
+  DEFVAR_LISP ("this-command", Vthis_command,
               doc: /* The command now being executed.
 The command can set this variable; whatever is put here
 will be in `last-command' during the following command.  */);
   Vthis_command = Qnil;
 
   DEFVAR_LISP ("this-command-keys-shift-translated",
-              &Vthis_command_keys_shift_translated,
+              Vthis_command_keys_shift_translated,
               doc: /* Non-nil if the key sequence activating this command was shift-translated.
 Shift-translation occurs when there is no binding for the key sequence
 as entered, but a binding was found by changing an upper-case letter
 to lower-case, or a shifted function key to an unshifted one.  */);
   Vthis_command_keys_shift_translated = Qnil;
 
-  DEFVAR_LISP ("this-original-command", &Vthis_original_command,
+  DEFVAR_LISP ("this-original-command", Vthis_original_command,
               doc: /* The command bound to the current key sequence before remapping.
 It equals `this-command' if the original command was not remapped through
 any of the active keymaps.  Otherwise, the value of `this-command' is the
 result of looking up the original command in the active keymaps.  */);
   Vthis_original_command = Qnil;
 
-  DEFVAR_INT ("auto-save-interval", &auto_save_interval,
+  DEFVAR_INT ("auto-save-interval", auto_save_interval,
              doc: /* *Number of input events between auto-saves.
 Zero means disable autosaving due to number of characters typed.  */);
   auto_save_interval = 300;
 
-  DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout,
+  DEFVAR_LISP ("auto-save-timeout", Vauto_save_timeout,
               doc: /* *Number of seconds idle time before auto-save.
 Zero or nil means disable auto-saving due to idleness.
 After auto-saving due to this many seconds of idle time,
 Emacs also does a garbage collection if that seems to be warranted.  */);
   XSETFASTINT (Vauto_save_timeout, 30);
 
-  DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes,
+  DEFVAR_LISP ("echo-keystrokes", Vecho_keystrokes,
               doc: /* *Nonzero means echo unfinished commands after this many seconds of pause.
 The value may be integer or floating point.  */);
   Vecho_keystrokes = make_number (1);
 
-  DEFVAR_INT ("polling-period", &polling_period,
+  DEFVAR_INT ("polling-period", polling_period,
              doc: /* *Interval between polling for input during Lisp execution.
 The reason for polling is to make C-g work to stop a running program.
 Polling is needed only when using X windows and SIGIO does not work.
 Polling is automatically disabled in all other cases.  */);
   polling_period = 2;
 
-  DEFVAR_LISP ("double-click-time", &Vdouble_click_time,
+  DEFVAR_LISP ("double-click-time", Vdouble_click_time,
               doc: /* *Maximum time between mouse clicks to make a double-click.
 Measured in milliseconds.  The value nil means disable double-click
 recognition; t means double-clicks have no time limit and are detected
 by position only.  */);
   Vdouble_click_time = make_number (500);
 
-  DEFVAR_INT ("double-click-fuzz", &double_click_fuzz,
+  DEFVAR_INT ("double-click-fuzz", double_click_fuzz,
              doc: /* *Maximum mouse movement between clicks to make a double-click.
 On window-system frames, value is the number of pixels the mouse may have
 moved horizontally or vertically between two clicks to make a double-click.
@@ -12018,54 +11850,54 @@ This variable is also the threshold for motion of the mouse
 to count as a drag.  */);
   double_click_fuzz = 3;
 
-  DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus,
+  DEFVAR_BOOL ("inhibit-local-menu-bar-menus", inhibit_local_menu_bar_menus,
               doc: /* *Non-nil means inhibit local map menu bar menus.  */);
   inhibit_local_menu_bar_menus = 0;
 
-  DEFVAR_INT ("num-input-keys", &num_input_keys,
+  DEFVAR_INT ("num-input-keys", num_input_keys,
              doc: /* Number of complete key sequences read as input so far.
 This includes key sequences read from keyboard macros.
 The number is effectively the number of interactive command invocations.  */);
   num_input_keys = 0;
 
-  DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events,
+  DEFVAR_INT ("num-nonmacro-input-events", num_nonmacro_input_events,
              doc: /* Number of input events read from the keyboard so far.
 This does not include events generated by keyboard macros.  */);
   num_nonmacro_input_events = 0;
 
-  DEFVAR_LISP ("last-event-frame", &Vlast_event_frame,
+  DEFVAR_LISP ("last-event-frame", Vlast_event_frame,
               doc: /* The frame in which the most recently read event occurred.
 If the last event came from a keyboard macro, this is set to `macro'.  */);
   Vlast_event_frame = Qnil;
 
   /* This variable is set up in sysdep.c.  */
-  DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char,
+  DEFVAR_LISP ("tty-erase-char", Vtty_erase_char,
               doc: /* The ERASE character as set by the user with stty.  */);
 
-  DEFVAR_LISP ("help-char", &Vhelp_char,
+  DEFVAR_LISP ("help-char", Vhelp_char,
               doc: /* Character to recognize as meaning Help.
 When it is read, do `(eval help-form)', and display result if it's a string.
 If the value of `help-form' is nil, this char can be read normally.  */);
   XSETINT (Vhelp_char, Ctl ('H'));
 
-  DEFVAR_LISP ("help-event-list", &Vhelp_event_list,
+  DEFVAR_LISP ("help-event-list", Vhelp_event_list,
               doc: /* List of input events to recognize as meaning Help.
 These work just like the value of `help-char' (see that).  */);
   Vhelp_event_list = Qnil;
 
-  DEFVAR_LISP ("help-form", &Vhelp_form,
+  DEFVAR_LISP ("help-form", Vhelp_form,
               doc: /* Form to execute when character `help-char' is read.
 If the form returns a string, that string is displayed.
 If `help-form' is nil, the help char is not recognized.  */);
   Vhelp_form = Qnil;
 
-  DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command,
+  DEFVAR_LISP ("prefix-help-command", Vprefix_help_command,
               doc: /* Command to run when `help-char' character follows a prefix key.
 This command is used only when there is no actual binding
 for that character after that prefix key.  */);
   Vprefix_help_command = Qnil;
 
-  DEFVAR_LISP ("top-level", &Vtop_level,
+  DEFVAR_LISP ("top-level", Vtop_level,
               doc: /* Form to evaluate when Emacs starts up.
 Useful to set before you dump a modified Emacs.  */);
   Vtop_level = Qnil;
@@ -12086,12 +11918,12 @@ output.  See also `translation-table-for-input'.
 This variable has a separate binding for each terminal.
 See Info node `(elisp)Multiple Terminals'.  */);
 
-  DEFVAR_BOOL ("cannot-suspend", &cannot_suspend,
+  DEFVAR_BOOL ("cannot-suspend", cannot_suspend,
               doc: /* Non-nil means to always spawn a subshell instead of suspending.
 \(Even if the operating system has support for stopping a process.\)  */);
   cannot_suspend = 0;
 
-  DEFVAR_BOOL ("menu-prompting", &menu_prompting,
+  DEFVAR_BOOL ("menu-prompting", menu_prompting,
               doc: /* Non-nil means prompt with menus when appropriate.
 This is done when reading from a keymap that has a prompt string,
 for elements that have prompt strings.
@@ -12101,12 +11933,12 @@ time and the previous event was a mouse click prefix key.
 Otherwise, menu prompting uses the echo area.  */);
   menu_prompting = 1;
 
-  DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char,
+  DEFVAR_LISP ("menu-prompt-more-char", menu_prompt_more_char,
               doc: /* Character to see next line of menu prompt.
 Type this character while in a menu prompt to rotate around the lines of it.  */);
   XSETINT (menu_prompt_more_char, ' ');
 
-  DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers,
+  DEFVAR_INT ("extra-keyboard-modifiers", extra_keyboard_modifiers,
              doc: /* A mask of additional modifier keys to use with every keyboard character.
 Emacs applies the modifiers of the character stored here to each keyboard
 character it reads.  For example, after evaluating the expression
@@ -12119,7 +11951,7 @@ with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
 cancels any modification.  */);
   extra_keyboard_modifiers = 0;
 
-  DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark,
+  DEFVAR_LISP ("deactivate-mark", Vdeactivate_mark,
               doc: /* If an editing command sets this to t, deactivate the mark afterward.
 The command loop sets this to nil before each command,
 and tests the value when the command returns.
@@ -12128,22 +11960,18 @@ Buffer modification stores t in this variable.  */);
   Qdeactivate_mark = intern_c_string ("deactivate-mark");
   staticpro (&Qdeactivate_mark);
 
-  DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal,
-              doc: /* Temporary storage of `pre-command-hook' or `post-command-hook'.  */);
-  Vcommand_hook_internal = Qnil;
-
-  DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook,
+  DEFVAR_LISP ("pre-command-hook", Vpre_command_hook,
               doc: /* Normal hook run before each command is executed.
 If an unhandled error happens in running this hook,
-the hook value is set to nil, since otherwise the error
-might happen repeatedly and make Emacs nonfunctional.  */);
+the function in which the error occurred is unconditionally removed, since
+otherwise the error might happen repeatedly and make Emacs nonfunctional.  */);
   Vpre_command_hook = Qnil;
 
-  DEFVAR_LISP ("post-command-hook", &Vpost_command_hook,
+  DEFVAR_LISP ("post-command-hook", Vpost_command_hook,
               doc: /* Normal hook run after each command is executed.
 If an unhandled error happens in running this hook,
-the hook value is set to nil, since otherwise the error
-might happen repeatedly and make Emacs nonfunctional.  */);
+the function in which the error occurred is unconditionally removed, since
+otherwise the error might happen repeatedly and make Emacs nonfunctional.  */);
   Vpost_command_hook = Qnil;
 
 #if 0
@@ -12154,16 +11982,16 @@ might happen repeatedly and make Emacs nonfunctional.  */);
   staticpro (&Qecho_area_clear_hook);
   Fset (Qecho_area_clear_hook, Qnil);
 
-  DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag,
+  DEFVAR_LISP ("lucid-menu-bar-dirty-flag", Vlucid_menu_bar_dirty_flag,
               doc: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed.  */);
   Vlucid_menu_bar_dirty_flag = Qnil;
 
-  DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items,
+  DEFVAR_LISP ("menu-bar-final-items", Vmenu_bar_final_items,
               doc: /* List of menu bar items to move to the end of the menu bar.
 The elements of the list are event types that may have menu bar bindings.  */);
   Vmenu_bar_final_items = Qnil;
 
-  DEFVAR_LISP ("tool-bar-separator-image-expression", &Vtool_bar_separator_image_expression,
+  DEFVAR_LISP ("tool-bar-separator-image-expression", Vtool_bar_separator_image_expression,
     doc: /* Expression evaluating to the image spec for a tool-bar separator.
 This is used internally by graphical displays that do not render
 tool-bar separators natively.  Otherwise it is unused (e.g. on GTK).  */);
@@ -12183,23 +12011,23 @@ set up a different keymap for reading the next command.
 terminal device.
 See Info node `(elisp)Multiple Terminals'.  */);
 
-  DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
+  DEFVAR_LISP ("overriding-local-map", Voverriding_local_map,
               doc: /* Keymap that overrides all other local keymaps.
 If this variable is non-nil, it is used as a keymap--replacing the
 buffer's local map, the minor mode keymaps, and char property keymaps.  */);
   Voverriding_local_map = Qnil;
 
-  DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag,
+  DEFVAR_LISP ("overriding-local-map-menu-flag", Voverriding_local_map_menu_flag,
               doc: /* Non-nil means `overriding-local-map' applies to the menu bar.
 Otherwise, the menu bar continues to reflect the buffer's local map
 and the minor mode maps regardless of `overriding-local-map'.  */);
   Voverriding_local_map_menu_flag = Qnil;
 
-  DEFVAR_LISP ("special-event-map", &Vspecial_event_map,
+  DEFVAR_LISP ("special-event-map", Vspecial_event_map,
               doc: /* Keymap defining bindings for special events to execute at low level.  */);
   Vspecial_event_map = Fcons (intern_c_string ("keymap"), Qnil);
 
-  DEFVAR_LISP ("track-mouse", &do_mouse_tracking,
+  DEFVAR_LISP ("track-mouse", do_mouse_tracking,
               doc: /* *Non-nil means generate motion events for mouse motion.  */);
 
   DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist,
@@ -12259,7 +12087,7 @@ themselves looked up in `input-decode-map'.
 
 This variable is keyboard-local.  */);
 
-  DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
+  DEFVAR_LISP ("function-key-map", Vfunction_key_map,
                doc: /* The parent keymap of all `local-function-key-map' instances.
 Function key definitions that apply to all terminal devices should go
 here.  If a mapping is defined in both the current
@@ -12267,39 +12095,39 @@ here.  If a mapping is defined in both the current
 definition will take precendence.  */);
   Vfunction_key_map = Fmake_sparse_keymap (Qnil);
 
-  DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
+  DEFVAR_LISP ("key-translation-map", Vkey_translation_map,
                doc: /* Keymap of key translations that can override keymaps.
 This keymap works like `function-key-map', but comes after that,
 and its non-prefix bindings override ordinary bindings.
 Another difference is that it is global rather than keyboard-local.  */);
   Vkey_translation_map = Fmake_sparse_keymap (Qnil);
 
-  DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
+  DEFVAR_LISP ("deferred-action-list", Vdeferred_action_list,
               doc: /* List of deferred actions to be performed at a later time.
 The precise format isn't relevant here; we just check whether it is nil.  */);
   Vdeferred_action_list = Qnil;
 
-  DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function,
+  DEFVAR_LISP ("deferred-action-function", Vdeferred_action_function,
               doc: /* Function to call to handle deferred actions, after each command.
 This function is called with no arguments after each command
 whenever `deferred-action-list' is non-nil.  */);
   Vdeferred_action_function = Qnil;
 
-  DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings,
+  DEFVAR_LISP ("suggest-key-bindings", Vsuggest_key_bindings,
               doc: /* *Non-nil means show the equivalent key-binding when M-x command has one.
 The value can be a length of time to show the message for.
 If the value is non-nil and not a number, we wait 2 seconds.  */);
   Vsuggest_key_bindings = Qt;
 
-  DEFVAR_LISP ("timer-list", &Vtimer_list,
+  DEFVAR_LISP ("timer-list", Vtimer_list,
               doc: /* List of active absolute time timers in order of increasing time.  */);
   Vtimer_list = Qnil;
 
-  DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list,
+  DEFVAR_LISP ("timer-idle-list", Vtimer_idle_list,
               doc: /* List of active idle-time timers in order of increasing time.  */);
   Vtimer_idle_list = Qnil;
 
-  DEFVAR_LISP ("input-method-function", &Vinput_method_function,
+  DEFVAR_LISP ("input-method-function", Vinput_method_function,
               doc: /* If non-nil, the function that implements the current input method.
 It's called with one argument, a printing character that was just read.
 \(That means a character with code 040...0176.)
@@ -12321,18 +12149,18 @@ for guidance on what to do.  */);
   Vinput_method_function = Qnil;
 
   DEFVAR_LISP ("input-method-previous-message",
-              &Vinput_method_previous_message,
+              Vinput_method_previous_message,
               doc: /* When `input-method-function' is called, hold the previous echo area message.
 This variable exists because `read-event' clears the echo area
 before running the input method.  It is nil if there was no message.  */);
   Vinput_method_previous_message = Qnil;
 
-  DEFVAR_LISP ("show-help-function", &Vshow_help_function,
+  DEFVAR_LISP ("show-help-function", Vshow_help_function,
               doc: /* If non-nil, the function that implements the display of help.
 It's called with one argument, the help string to display.  */);
   Vshow_help_function = Qnil;
 
-  DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment,
+  DEFVAR_LISP ("disable-point-adjustment", Vdisable_point_adjustment,
               doc: /* If non-nil, suppress point adjustment after executing a command.
 
 After a command is executed, if point is moved into a region that has
@@ -12345,7 +12173,7 @@ just after executing the command.  */);
   Vdisable_point_adjustment = Qnil;
 
   DEFVAR_LISP ("global-disable-point-adjustment",
-              &Vglobal_disable_point_adjustment,
+              Vglobal_disable_point_adjustment,
               doc: /* *If non-nil, always suppress point adjustment.
 
 The default value is nil, in which case, point adjustment are
@@ -12353,18 +12181,18 @@ suppressed only after special commands that set
 `disable-point-adjustment' (which see) to non-nil.  */);
   Vglobal_disable_point_adjustment = Qnil;
 
-  DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout,
+  DEFVAR_LISP ("minibuffer-message-timeout", Vminibuffer_message_timeout,
               doc: /* *How long to display an echo-area message when the minibuffer is active.
 If the value is not a number, such messages don't time out.  */);
   Vminibuffer_message_timeout = make_number (2);
 
-  DEFVAR_LISP ("throw-on-input", &Vthrow_on_input,
+  DEFVAR_LISP ("throw-on-input", Vthrow_on_input,
               doc: /* If non-nil, any keyboard input throws to this symbol.
 The value of that variable is passed to `quit-flag' and later causes a
 peculiar kind of quitting.  */);
   Vthrow_on_input = Qnil;
 
-  DEFVAR_LISP ("command-error-function", &Vcommand_error_function,
+  DEFVAR_LISP ("command-error-function", Vcommand_error_function,
               doc: /* If non-nil, function to output error messages.
 The arguments are the error data, a list of the form
  (SIGNALED-CONDITIONS . SIGNAL-DATA)
@@ -12374,7 +12202,7 @@ and the Lisp function within which the error was signaled.  */);
   Vcommand_error_function = Qnil;
 
   DEFVAR_LISP ("enable-disabled-menus-and-buttons",
-              &Venable_disabled_menus_and_buttons,
+              Venable_disabled_menus_and_buttons,
               doc: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar.
 
 Help functions bind this to allow help on disabled menu items
@@ -12382,7 +12210,7 @@ and tool-bar buttons.  */);
   Venable_disabled_menus_and_buttons = Qnil;
 
   DEFVAR_LISP ("select-active-regions",
-              &Vselect_active_regions,
+              Vselect_active_regions,
               doc: /* If non-nil, an active region automatically sets the primary selection.
 If the value is `only', only temporarily active regions (usually made
 by mouse-dragging or shift-selection) set the window selection.
@@ -12391,7 +12219,7 @@ This takes effect only when Transient Mark mode is enabled.  */);
   Vselect_active_regions = Qt;
 
   DEFVAR_LISP ("saved-region-selection",
-              &Vsaved_region_selection,
+              Vsaved_region_selection,
               doc: /* Contents of active region prior to buffer modification.
 If `select-active-regions' is non-nil, Emacs sets this to the
 text in the region before modifying the buffer.  The next
@@ -12476,23 +12304,23 @@ mark_kboards (void)
       if (kb->kbd_macro_buffer)
        for (p = kb->kbd_macro_buffer; p < kb->kbd_macro_ptr; p++)
          mark_object (*p);
-      mark_object (kb->Voverriding_terminal_local_map);
-      mark_object (kb->Vlast_command);
-      mark_object (kb->Vreal_last_command);
-      mark_object (kb->Vkeyboard_translate_table);
-      mark_object (kb->Vlast_repeatable_command);
-      mark_object (kb->Vprefix_arg);
-      mark_object (kb->Vlast_prefix_arg);
-      mark_object (kb->kbd_queue);
-      mark_object (kb->defining_kbd_macro);
-      mark_object (kb->Vlast_kbd_macro);
-      mark_object (kb->Vsystem_key_alist);
-      mark_object (kb->system_key_syms);
-      mark_object (kb->Vwindow_system);
-      mark_object (kb->Vinput_decode_map);
-      mark_object (kb->Vlocal_function_key_map);
-      mark_object (kb->Vdefault_minibuffer_frame);
-      mark_object (kb->echo_string);
+      mark_object (KVAR (kb, Voverriding_terminal_local_map));
+      mark_object (KVAR (kb, Vlast_command));
+      mark_object (KVAR (kb, Vreal_last_command));
+      mark_object (KVAR (kb, Vkeyboard_translate_table));
+      mark_object (KVAR (kb, Vlast_repeatable_command));
+      mark_object (KVAR (kb, Vprefix_arg));
+      mark_object (KVAR (kb, Vlast_prefix_arg));
+      mark_object (KVAR (kb, kbd_queue));
+      mark_object (KVAR (kb, defining_kbd_macro));
+      mark_object (KVAR (kb, Vlast_kbd_macro));
+      mark_object (KVAR (kb, Vsystem_key_alist));
+      mark_object (KVAR (kb, system_key_syms));
+      mark_object (KVAR (kb, Vwindow_system));
+      mark_object (KVAR (kb, Vinput_decode_map));
+      mark_object (KVAR (kb, Vlocal_function_key_map));
+      mark_object (KVAR (kb, Vdefault_minibuffer_frame));
+      mark_object (KVAR (kb, echo_string));
     }
   {
     struct input_event *event;
@@ -12511,4 +12339,3 @@ mark_kboards (void)
       }
   }
 }
-