#include "dispextern.h"
#include "keyboard.h"
#include "intervals.h"
+#include "blockinput.h"
#include <setjmp.h>
#include <errno.h>
extern int errno;
+/* Variables for blockinput.h: */
+
+/* Non-zero if interrupt input is blocked right now. */
+int interrupt_input_blocked;
+
+/* Nonzero means an input interrupt has arrived
+ during the current critical section. */
+int interrupt_input_pending;
+
+
#ifdef HAVE_X_WINDOWS
extern Lisp_Object Vmouse_grabbed;
/* 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
/* Symbols to head events. */
Lisp_Object Qmouse_movement;
Lisp_Object Qscroll_bar_movement;
-
Lisp_Object Qswitch_frame;
/* Symbols to denote kinds of events. */
Lisp_Object Qevent_kind;
Lisp_Object Qevent_symbol_elements;
+Lisp_Object Qmenu_enable;
+
/* An event header symbol HEAD may have a property named
Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
BASE is the base, unmodified version of HEAD, and MODIFIERS is the
{
if (!immediate_echo && echoptr == echobuf)
return;
+ /* Do nothing if not echoing at all. */
+ if (echoptr == 0)
+ return;
/* Put a dash at the end of the buffer temporarily,
but make it go away when the next character is added. */
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)
{
struct frame *f = XFRAME (XCONS (tem)->car);
struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
+
+ /* If the user has switched buffers or windows, we need to
+ recompute to reflect the new bindings. But we'll
+ recompute when update_mode_lines is set too; that means
+ that people can use force-mode-line-update to request
+ that the menu bar be recomputed. The adverse effect on
+ the rest of the redisplay algorithm is about the same as
+ windows_or_buffers_changed anyway. */
if (windows_or_buffers_changed
+ || update_mode_lines
|| (XFASTINT (w->last_modified) < MODIFF
&& (XFASTINT (w->last_modified)
<= XBUFFER (w->buffer)->save_modified)))
}
}
#endif /* MULTI_FRAME */
+#endif /* 0 */
/* Read next key sequence; i gets its length. */
i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0);
last_command_char = keybuf[i - 1];
+ /* If the previous command tried to force a specific window-start,
+ forget about that, in case this command moves point far away
+ from that position. */
+ XWINDOW (selected_window)->force_start = Qnil;
+
cmd = read_key_sequence_cmd;
if (!NILP (Vexecuting_macro))
{
SIGTYPE
input_poll_signal ()
{
-#ifdef HAVE_X_WINDOWS
- extern int x_input_blocked;
- if (x_input_blocked == 0)
-#endif
- if (!waiting_for_input)
- read_avail_input (0);
+ if (interrupt_input_blocked == 0
+ && !waiting_for_input)
+ read_avail_input (0);
signal (SIGALRM, input_poll_signal);
alarm (polling_period);
}
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;
XSET (internal_last_event_frame, Lisp_Frame, selected_frame);
Vlast_event_frame = internal_last_event_frame;
#endif
+ /* If we report the quit char as an event,
+ don't do so more than once. */
+ if (!NILP (Vinhibit_quit))
+ Vquit_flag = Qnil;
goto non_reread;
}
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))
+ {
+ /* 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;
+ }
+
+ /* 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:
and don't actually appear to the command loop. */
if (event->kind == selection_request_event)
{
+#ifdef HAVE_X11
x_handle_selection_request (event);
kbd_fetch_ptr = event + 1;
goto retry;
+#else
+ /* We're getting selection request events, but we don't have
+ a window system. */
+ abort ();
+#endif
}
if (event->kind == selection_clear_event)
{
+#ifdef HAVE_X11
x_handle_selection_clear (event);
kbd_fetch_ptr = event + 1;
goto retry;
+#else
+ /* We're getting selection request events, but we don't have
+ a window system. */
+ abort ();
+#endif
}
#ifdef MULTI_FRAME
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
if ((event->modifiers & ctrl_modifier)
&& c >= 040)
c |= ctrl_modifier;
- if (XFASTINT (event->code) < 040
+ /* Set the shift modifier for a control char
+ made from a shifted letter. But only for letters! */
+ if (XFASTINT (event->code) >= 'A' - 0100
+ && XFASTINT (event->code) <= 'Z' - 0100
&& (event->modifiers & shift_modifier))
c |= shift_modifier;
c |= (event->modifiers
if (event->kind == mouse_click)
{
int part;
- struct frame *f = XFRAME (event->frame_or_window);
+ FRAME_PTR f = XFRAME (event->frame_or_window);
Lisp_Object window
= window_from_coordinates (f, XINT (event->x), XINT (event->y),
&part);
"drag", "click", 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;
}
Qnil);
Lisp_Object mask;
+ if (modifiers & ~((1<<VALBITS) - 1))
+ abort ();
XFASTINT (mask) = modifiers;
elements = Fcons (unmodified, Fcons (mask, Qnil));
{
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);
XFASTINT (index) = (modifiers & ~click_modifier);
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);
{
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)
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)
}
DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0,
- "Return string of the keystrokes that invoked this command.")
+ "Return the key sequence that invoked this command.\n\
+The value is a string or a vector.")
()
{
return make_event_array (this_command_key_count,
If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
to be read as terminal input by Emacs's parent, after suspension.\n\
\n\
-Before suspending, call the functions in `suspend-hooks' with no args.\n\
+Before suspending, call the functions in `suspend-hook' with no args.\n\
If any of them returns nil, don't call the rest and don't suspend.\n\
Otherwise, suspend normally and after resumption run the normal hook\n\
`suspend-resume-hook' if that is bound and non-nil.\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\
+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.")
(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 non-nil if Emacs is accepting 8-bit input; otherwise, Emacs\n\
+ clears the eighth bit of every input character.\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 ? Qt : Qnil;
+ XSETINT (val[3], quit_char);
+
+ return Flist (val, sizeof (val) / sizeof (val[0]));
+}
+
\f
init_keyboard ()
{
Qmouse_click = intern ("mouse-click");
staticpro (&Qmouse_click);
+ Qmenu_enable = intern ("menu-enable");
+ staticpro (&Qmenu_enable);
+
Qmode_line = intern ("mode-line");
staticpro (&Qmode_line);
Qvertical_line = intern ("vertical-line");
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,