/* 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;
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
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)
{
}
}
#endif /* MULTI_FRAME */
+#endif /* 0 */
/* Read next key sequence; i gets its length. */
i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0);
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 ();
{
/* 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));
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));
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)
{
nonundocount = 0;
if (NILP (Vprefix_arg))
Fundo_boundary ();
- Fcommand_execute (cmd, Qnil);
+ Fcommand_execute (this_command, Qnil);
}
directly_done: ;
}
#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 */
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;
if (noninteractive && XTYPE (c) == Lisp_Int && XINT (c) < 0)
Fkill_emacs (make_number (1));
- /* Test for ControlMask and Mod1Mask. */
- if (extra_keyboard_modifiers & 4)
- c &= ~0140;
- if (extra_keyboard_modifiers & 8)
- c |= 0200;
+ if (XTYPE (c) == Lisp_Int)
+ {
+ /* Add in any extra modifiers, where appropriate. */
+ if ((extra_keyboard_modifiers & CHAR_CTL)
+ || ((extra_keyboard_modifiers & 0177) < ' '
+ && (extra_keyboard_modifiers & 0177) != 0))
+ XSETINT (c, make_ctrl_char (XINT (c)));
+
+ /* Transfer any other modifier bits directly from
+ extra_keyboard_modifiers to c. Ignore the actual character code
+ in the low 16 bits of extra_keyboard_modifiers. */
+ c |= (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL);
+ }
non_reread:
{
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 ();
if (! NILP (focus))
frame = focus;
- if (! EQ (frame, internal_last_event_frame))
- {
- internal_last_event_frame = frame;
- obj = make_lispy_switch_frame (frame);
- }
+ if (! EQ (frame, internal_last_event_frame)
+ && XFRAME (frame) != selected_frame)
+ obj = make_lispy_switch_frame (frame);
+ internal_last_event_frame = frame;
}
#endif
if (NILP (frame))
XSET (frame, Lisp_Frame, f);
- if (! EQ (frame, internal_last_event_frame))
- {
- XSET (internal_last_event_frame, Lisp_Frame, frame);
- obj = make_lispy_switch_frame (internal_last_event_frame);
- }
+ if (! EQ (frame, internal_last_event_frame)
+ && XFRAME (frame) != selected_frame)
+ obj = make_lispy_switch_frame (internal_last_event_frame);
+ internal_last_event_frame = frame;
}
#endif
"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 */
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));
{
window = Qnil;
posn = Qnil;
+ XFASTINT (x) = 0;
+ XFASTINT (y) = 0;
}
return Fcons (Qmouse_movement,
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]))
static Lisp_Object modifier_symbols;
int i;
modifier_list = Qnil;
- for (i = 0; (1<<i) <= modifiers; i++)
+ for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++)
if (modifiers & (1<<i))
- {
- if (i >= XVECTOR (modifier_symbols)->size)
- abort ();
- modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i],
- modifier_list);
- }
+ modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i],
+ modifier_list);
return modifier_list;
}
{
Lisp_Object cache, index, entry, new_symbol;
+ /* Mask out upper bits. We don't know where this value's been. */
+ modifiers &= (1<<VALBITS) - 1;
+
/* The click modifier never figures into cache indices. */
cache = Fget (base, Qmodifier_cache);
- if (modifiers & ~((1<<VALBITS) - 1))
- abort ();
XFASTINT (index) = (modifiers & ~click_modifier);
entry = Fassq (index, cache);
Fput (base, Qmodifier_cache, Fcons (entry, cache));
/* We have the parsing info now for free, so add it to the caches. */
- if (modifiers & ~((1<<VALBITS) - 1))
- abort ();
XFASTINT (index) = modifiers;
Fput (new_symbol, Qevent_symbol_element_mask,
Fcons (base, Fcons (index, Qnil)));
You'd think we could just set this once and for all when we
intern the symbol above, but reorder_modifiers may call us when
BASE's property isn't set right; we can't assume that just
- because we found something in the cache it must have its kind set
- right. */
+ because it has a Qmodifier_cache property it must have its
+ Qevent_kind set right as well. */
if (NILP (Fget (new_symbol, Qevent_kind)))
{
Lisp_Object kind = Fget (base, Qevent_kind);
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
{
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
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.
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)
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)
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)
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;
}
if (XTYPE (head) == Lisp_Symbol)
{
Lisp_Object breakdown = parse_modifiers (head);
- Lisp_Object modifiers =
- XINT (XCONS (XCONS (breakdown)->cdr)->car);
+ int modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car);
/* We drop unbound `down-' events altogether. */
if (modifiers & down_modifier)
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;
{
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);
init_sys_modes ();
return Qnil;
}
+
+DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0,
+ "Return information about the way Emacs currently reads keyboard input.\n\
+The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
+ INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\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 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'.")
+ ()
+{
+ Lisp_Object val[4];
+
+ val[0] = interrupt_input ? Qt : Qnil;
+ val[1] = flow_control ? 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]));
+}
+
\f
init_keyboard ()
{
defsubr (&Sdiscard_input);
defsubr (&Sopen_dribble_file);
defsubr (&Sset_input_mode);
+ defsubr (&Scurrent_input_mode);
defsubr (&Sexecute_extended_command);
DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook,
DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers,
"A mask of additional modifier keys to use with every keyboard character.\n\
-These bits follow the convention for X windows,\n\
-but the control and meta bits work even when you are not using X:\n\
- 1 -- shift bit 2 -- lock bit\n\
- 4 -- control bit 8 -- meta bit.");
+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\
+Note that the character ?\C-@, equivalent to the integer zero, does\n\
+not count as a control character; rather, it counts as a character\n\
+with no modifiers; thus, setting extra_keyboard_modifiers to zero\n\
+cancels any modification.");
extra_keyboard_modifiers = 0;
DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark,