]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
(lispy_function_keys): Add kp-numlock. Fix kp-backspace.
[gnu-emacs] / src / keyboard.c
index 2b51d6abb9066bd1e1499dfe5c832c6058c2c4ca..6b267bd8e087b362c33fc15593239c301ef89c54 100644 (file)
@@ -271,7 +271,9 @@ FILE *dribble;
 /* Nonzero if input is available.  */
 int input_pending;
 
-/* Nonzero if should obey 0200 bit in input chars as "Meta".  */
+/* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
+   keep 0200 bit in input chars.  0 to ignore the 0200 bit.  */
+
 int meta_key;
 
 extern char *pending_malloc_warning;
@@ -330,10 +332,10 @@ static struct input_event *kbd_store_ptr;
    dequeuing functions?  Such a flag could be screwed up by interrupts
    at inopportune times.  */
 
-/* If this flag is non-zero, we will check mouse_moved to see when the
+/* If this flag is non-zero, we check mouse_moved to see when the
    mouse moves, and motion events will appear in the input stream.  If
-   it is zero, mouse motion will be ignored.  */
-int do_mouse_tracking;
+   it is zero, mouse motion is ignored.  */
+static int do_mouse_tracking;
 
 /* The window system handling code should set this if the mouse has
    moved since the last call to the mouse_position_hook.  Calling that
@@ -941,6 +943,7 @@ command_loop_1 ()
       if (! NILP (Vlucid_menu_bar_dirty_flag))
        call0 (Qrecompute_lucid_menubar);
 
+#if 0 /* This is done in xdisp.c now.  */
 #ifdef MULTI_FRAME
       for (tem = Vframe_list; CONSP (tem); tem = XCONS (tem)->cdr)
        {
@@ -967,6 +970,7 @@ command_loop_1 ()
            }
        }
 #endif /* MULTI_FRAME */
+#endif /* 0 */
 
       /* Read next key sequence; i gets its length.  */
       i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0);
@@ -1010,7 +1014,7 @@ command_loop_1 ()
       if (!NILP (Vpre_command_hook))
        call1 (Vrun_hooks, Qpre_command_hook);
 
-      if (NILP (cmd))
+      if (NILP (this_command))
        {
          /* nil means key is undefined.  */
          bitch_at_user ();
@@ -1025,7 +1029,7 @@ command_loop_1 ()
            {
              /* Recognize some common commands in common situations and
                 do them directly.  */
-             if (EQ (cmd, Qforward_char) && point < ZV)
+             if (EQ (this_command, Qforward_char) && point < ZV)
                {
                   struct Lisp_Vector *dp
                    = window_display_table (XWINDOW (selected_window));
@@ -1046,7 +1050,7 @@ command_loop_1 ()
                    no_redisplay = direct_output_forward_char (1);
                  goto directly_done;
                }
-             else if (EQ (cmd, Qbackward_char) && point > BEGV)
+             else if (EQ (this_command, Qbackward_char) && point > BEGV)
                {
                   struct Lisp_Vector *dp
                    = window_display_table (XWINDOW (selected_window));
@@ -1067,7 +1071,7 @@ command_loop_1 ()
                    no_redisplay = direct_output_forward_char (-1);
                  goto directly_done;
                }
-             else if (EQ (cmd, Qself_insert_command)
+             else if (EQ (this_command, Qself_insert_command)
                       /* Try this optimization only on ascii keystrokes.  */
                       && XTYPE (last_command_char) == Lisp_Int)
                {
@@ -1130,7 +1134,7 @@ command_loop_1 ()
          nonundocount = 0;
          if (NILP (Vprefix_arg))
            Fundo_boundary ();
-         Fcommand_execute (cmd, Qnil);
+         Fcommand_execute (this_command, Qnil);
 
        }
     directly_done: ;
@@ -1226,6 +1230,45 @@ stop_polling ()
     }
 #endif
 }
+\f
+/* Applying the control modifier to CHARACTER.  */
+int
+make_ctrl_char (c)
+     int c;
+{
+  /* Save the upper bits here.  */
+  int upper = c & ~0177;
+
+  c &= 0177;
+
+  /* Everything in the columns containing the upper-case letters
+     denotes a control character.  */
+  if (c >= 0100 && c < 0140)
+    {
+      int oc = c;
+      c &= ~0140;
+      /* Set the shift modifier for a control char
+        made from a shifted letter.  But only for letters!  */
+      if (oc >= 'A' && oc <= 'Z')
+       c |= shift_modifier;
+    }
+
+  /* The lower-case letters denote control characters too.  */
+  else if (c >= 'a' && c <= 'z')
+    c &= ~0140;
+
+  /* Include the bits for control and shift
+     only if the basic ASCII code can't indicate them.  */
+  else if (c >= ' ')
+    c |= ctrl_modifier;
+
+  /* Replace the high bits.  */
+  c |= (upper & ~ctrl_modifier);
+
+  return c;
+}
+
+
 \f
 /* Input of single characters from keyboard */
 
@@ -1297,7 +1340,11 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
       Vlast_event_frame = internal_last_event_frame = Qmacro;
 #endif
 
-      if (executing_macro_index >= XFASTINT (Flength (Vexecuting_macro)))
+      /* Exit the macro if we are at the end.
+        Also, some things replace the macro with t
+        to force an early exit.  */
+      if (EQ (Vexecuting_macro, Qt)
+         || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro)))
        {
          XSET (c, Lisp_Int, -1);
          return c;
@@ -1454,26 +1501,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
       if ((extra_keyboard_modifiers & CHAR_CTL)
          || ((extra_keyboard_modifiers & 0177) < ' '
              && (extra_keyboard_modifiers & 0177) != 0))
-       {
-         /* If it's already a control character, don't mess with it.  */
-         if ((c & 0177) == 0)
-           ;
-
-         /* Making ? a control character should result in DEL.  */
-         else if ((c & 0177) == '?')
-           c |= 0177;
-
-         /* ASCII control chars are made from letters (both cases),
-            as well as the non-letters within 0100...0137.  */
-         else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
-           c = (c & (037 | ~0177));
-         else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
-           c = (c & (037 | ~0177));
-
-         /* Anything else must get its high control bit set.  */
-         else
-           c = c | ctrl_modifier;
-       }
+       XSETINT (c, make_ctrl_char (XINT (c)));
 
       /* Transfer any other modifier bits directly from
         extra_keyboard_modifiers to c.  Ignore the actual character code
@@ -1684,6 +1712,9 @@ kbd_buffer_store_event (event)
     {
       register int c = XFASTINT (event->code) & 0377;
 
+      if (event->modifiers & ctrl_modifier)
+       c = make_ctrl_char (c);
+
       if (c == quit_char)
        {
          extern SIGTYPE interrupt_signal ();
@@ -1995,9 +2026,9 @@ static char *lispy_function_keys[] =
     "insertchar",
     "deletechar",
     "backtab",
-    "kp_backtab",              /* 0x1000ff75 */
+    "kp-backtab",              /* 0x1000ff75 */
     0,                         /* 0xff76 */
-    0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */
+    0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock",      /* 0xff7f */
     "kp-space",                        /* 0xff80 */    /* IsKeypadKey */
     0, 0, 0, 0, 0, 0, 0, 0,
     "kp-tab",                  /* 0xff89 */
@@ -2082,14 +2113,14 @@ make_lispy_event (event)
     case ascii_keystroke:
       {
        int c = XFASTINT (event->code);
-       /* Include the bits for control and shift
-          only if the basic ASCII code can't indicate them.  */
-       if ((event->modifiers & ctrl_modifier)
-           && c >= 040)
-         c |= ctrl_modifier;
-       if (XFASTINT (event->code) < 040
-           && (event->modifiers & shift_modifier))
-         c |= shift_modifier;
+       /* Turn ASCII characters into control characters
+          when proper.  */
+       if (event->modifiers & ctrl_modifier)
+         c = make_ctrl_char (c);
+
+       /* Add in the other modifier bits.  We took care of ctrl_modifier
+          just above, and the shift key was taken care of by the X code,
+          and applied to control characters by make_ctrl_char.  */
        c |= (event->modifiers
              & (meta_modifier | alt_modifier
                 | hyper_modifier | super_modifier));
@@ -2323,6 +2354,8 @@ make_lispy_movement (frame, bar_window, part, x, y, time)
        {
          window = Qnil;
          posn = Qnil;
+         XFASTINT (x) = 0;
+         XFASTINT (y) = 0;
        }
 
       return Fcons (Qmouse_movement,
@@ -2490,8 +2523,8 @@ apply_modifiers_uncached (modifiers, base, base_len)
 
 static char *modifier_names[] =
 {
-  "up", 0, 0, 0, 0, 0, 0, "down",
-  "drag", "click", 0, 0, 0, 0, 0, 0,
+  "up", "down", "drag", "click", 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, "alt", "super", "hyper", "shift", "control", "meta"
 };
 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
@@ -2706,7 +2739,14 @@ modify_event_symbol (symbol_num, modifiers, symbol_kind, name_table,
   if (NILP (*slot))
     {
       /* No; let's create it.  */
-      *slot = intern (name_table[symbol_num]);
+      if (name_table[symbol_num])
+       *slot = intern (name_table[symbol_num]);
+      else
+       {
+         char buf[20];
+         sprintf (buf, "key-%d", symbol_num);
+         *slot = intern (buf);
+       }
 
       /* Fill in the cache entries for this symbol; this also  
         builds the Qevent_symbol_elements property, which the user
@@ -2846,9 +2886,10 @@ read_avail_input (expected)
        {
          buf[i].kind = ascii_keystroke;
          buf[i].modifiers = 0;
-         if (meta_key && (cbuf[i] & 0x80))
+         if (meta_key == 1 && (cbuf[i] & 0x80))
            buf[i].modifiers = meta_modifier;
-         cbuf[i] &= ~0x80;
+         if (meta_key != 2)
+           cbuf[i] &= ~0x80;
            
          XSET (buf[i].code,            Lisp_Int,   cbuf[i]);
 #ifdef MULTI_FRAME
@@ -2921,6 +2962,22 @@ input_available_signal (signo)
   errno = old_errno;
 }
 #endif /* SIGIO */
+
+/* Send ourselves a SIGIO.
+
+   This function exists so that the UNBLOCK_INPUT macro in
+   blockinput.h can have some way to take care of input we put off
+   dealing with, without assuming that every file which uses
+   UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
+void
+reinvoke_input_signal ()
+{
+#ifdef SIGIO  
+  kill (0, SIGIO);
+#endif
+}
+
+
 \f
 /* Return the prompt-string of a sparse keymap.
    This is the first element which is a string.
@@ -3151,6 +3208,15 @@ read_char_menu_prompt (nmaps, maps, prev_event, used_mouse_menu)
          realmaps[nmaps1++] = maps[mapno];
 
       value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps));
+      if (CONSP (value))
+       {
+         /* If we got more than one event, put all but the first
+            onto this list to be read later.
+            Return just the first event now.  */
+         unread_command_events
+           = nconc2 (XCONS (value)->cdr, unread_command_events);
+         value = XCONS (value)->car;
+       }
       if (NILP (value))
        XSET (value, Lisp_Int, quit_char);
       if (used_mouse_menu)
@@ -3347,7 +3413,9 @@ follow_key (key, nmaps, current, defs, next)
      lower-case letter, return the bindings for the lower-case letter.  */
   if (first_binding == nmaps
       && XTYPE (key) == Lisp_Int
-      && (UPPERCASEP (XINT (key) & 0x3ffff)
+      && ((((XINT (key) & 0x3ffff)
+           < XSTRING (current_buffer->downcase_table)->size)
+          && UPPERCASEP (XINT (key) & 0x3ffff))
          || (XINT (key) & shift_modifier)))
     {
       if (XINT (key) & shift_modifier)
@@ -3477,14 +3545,6 @@ read_key_sequence (keybuf, bufsize, prompt)
   if (NILP (Fkeymapp (Vfunction_key_map)))
     fkey_start = fkey_end = bufsize + 1;
 
-  /* We need to save the current buffer in case we switch buffers to
-     find the right binding for a mouse click.  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 accomodate a Fset_window_start or
-     something.  */
-  record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
-                        
   last_nonmenu_event = Qnil;
 
   if (INTERACTIVE)
@@ -3655,6 +3715,18 @@ read_key_sequence (keybuf, bufsize, prompt)
                          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 accomodate 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 ());
+                        
                      set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
                      goto replay_sequence;
                    }
@@ -4441,9 +4513,11 @@ First arg INTERRUPT non-nil means use input interrupts;\n\
  nil means use CBREAK mode.\n\
 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
  (no effect except in CBREAK mode).\n\
-Third arg META non-nil means accept 8-bit input (for a Meta key).\n\
- Otherwise, the top bit is ignored, on the assumption it is parity.\n\
-Optional fourth arg QUIT if non-nil specifies character to use for quitting.")
+Third arg META t means accept 8-bit input (for a Meta key).\n\
+ META nil means ignore the top bit, on the assumption it is parity.\n\
+ Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
+Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
+See also `current-input-mode'.")
   (interrupt, flow, meta, quit)
      Lisp_Object interrupt, flow, meta, quit;
 {
@@ -4469,7 +4543,12 @@ Optional fourth arg QUIT if non-nil specifies character to use for quitting.")
   interrupt_input = 1;
 #endif
   flow_control = !NILP (flow);
-  meta_key = !NILP (meta);
+  if (NILP (meta))
+    meta_key = 0;
+  else if (EQ (meta, Qt))
+    meta_key = 1;
+  else
+    meta_key = 2;
   if (!NILP (quit))
     /* Don't let this value be out of range.  */
     quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
@@ -4485,18 +4564,20 @@ The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
     nil, Emacs is using CBREAK mode.\n\
   FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
     terminal; this does not apply if Emacs uses interrupt-driven input.\n\
-  META is non-nil if Emacs is accepting 8-bit input; otherwise, Emacs\n\
-    clears the eighth bit of every input character.\n\
+  META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
+    META nil means ignoring the top bit, on the assumption it is parity.\n\
+    META is neither t nor nil if accepting 8-bit input and using\n\
+    all 8 bits as the character code.\n\
   QUIT is the character Emacs currently uses to quit.\n\
 The elements of this list correspond to the arguments of\n\
-set-input-mode.")
+`set-input-mode'.")
   ()
 {
   Lisp_Object val[4];
 
   val[0] = interrupt_input ? Qt : Qnil;
   val[1] = flow_control ? Qt : Qnil;
-  val[2] = meta_key ? Qt : Qnil;
+  val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil;
   XSETINT (val[3], quit_char);
 
   return Flist (val, sizeof (val) / sizeof (val[0]));
@@ -4830,8 +4911,8 @@ Type this character while in a menu prompt to rotate around the lines of it.");
 
   DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers,
     "A mask of additional modifier keys to use with every keyboard character.\n\
-The modifiers of the character stored here apply to each keyboard\n\
-character we read.  For example, after evaluating the expression\n\
+Emacs applies the modifiers of the character stored here to each keyboard\n\
+character it reads.  For example, after evaluating the expression\n\
     (setq extra-keyboard-modifiers ?\C-x)\n\
 all input characters will have the control modifier applied to them.\n\
 \n\