/* 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 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
+ 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
+ 2005 Free Software Foundation, Inc.
This file is part of GNU Emacs.
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
#include <config.h>
#include <signal.h>
/* User-supplied table to translate input characters. */
Lisp_Object Vkeyboard_translate_table;
-/* Keymap mapping ASCII function key sequences onto their preferred forms. */
-extern Lisp_Object Vfunction_key_map;
-
-/* Another keymap that maps key sequences into key sequences.
- This one takes precedence over ordinary definitions. */
-extern Lisp_Object Vkey_translation_map;
-
/* If non-nil, this implements the current input method. */
Lisp_Object Vinput_method_function;
Lisp_Object Qinput_method_function;
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;
+
+/* Parent keymap of terminal-local key-translation-map instances. */
+Lisp_Object Vkey_translation_map;
+
/* 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;
static struct kboard_stack *kboard_stack;
+void
+push_device_kboard (d)
+ struct device *d;
+{
+#ifdef MULTI_KBOARD
+ struct kboard_stack *p
+ = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack));
+
+ p->next = kboard_stack;
+ p->kboard = current_kboard;
+ kboard_stack = p;
+
+ current_kboard = d->kboard;
+#endif
+}
+
void
push_frame_kboard (f)
FRAME_PTR f;
kbd_fetch_ptr = event + 1;
}
#endif
-#if defined (HAVE_X11) || defined (HAVE_NTGUI)
+#if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
else if (event->kind == ICONIFY_EVENT)
{
/* Make an event (iconify-frame (FRAME)). */
x = Qnil;
/* XXX Can f or mouse_position_hook be NULL here? */
- if (f && FRAME_DISPLAY (f)->mouse_position_hook)
- (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, 0, &bar_window,
- &part, &x, &y, &time);
+ if (f && FRAME_DEVICE (f)->mouse_position_hook)
+ (*FRAME_DEVICE (f)->mouse_position_hook) (&f, 0, &bar_window,
+ &part, &x, &y, &time);
obj = Qnil;
{
int nread = 0;
int err = 0;
- struct display *d;
+ struct device *d;
- /* Loop through the available displays, and call their input hooks. */
- d = display_list;
+ /* Loop through the available devices, and call their input hooks. */
+ d = device_list;
while (d)
{
- struct display *next = d->next_display;
+ struct device *next = d->next_device;
if (d->read_socket_hook)
{
/* The display device terminated; it should be closed. */
/* Kill Emacs if this was our last display. */
- if (! display_list->next_display)
+ if (! device_list->next_device)
/* Formerly simply reported no input, but that
sometimes led to a failure of Emacs to terminate.
SIGHUP seems appropriate if we can't reach the
alone in its group. */
kill (getpid (), SIGHUP);
- /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */
- if (d->delete_display_hook)
- (*d->delete_display_hook) (d);
+ /* XXX Is calling delete_device safe here? It calls Fdelete_frame. */
+ if (d->delete_device_hook)
+ (*d->delete_device_hook) (d);
else
- delete_display (d);
+ delete_device (d);
}
if (hold_quit.kind != NO_EVENT)
/* This is the tty way of reading available input.
- Note that each terminal device has its own `struct display' object,
+ Note that each terminal device has its own `struct device' object,
and so this function is called once for each individual termcap
display. The first parameter indicates which device to read from. */
int
-tty_read_avail_input (struct display *display,
+tty_read_avail_input (struct device *device,
int expected,
struct input_event *hold_quit)
{
of characters on some systems when input is stuffed at us. */
unsigned char cbuf[KBD_BUFFER_SIZE - 1];
int n_to_read, i;
- struct tty_display_info *tty = display->display_info.tty;
+ struct tty_display_info *tty = device->display_info.tty;
int nread = 0;
- if (display->type != output_termcap)
+ if (device->type != output_termcap)
abort ();
/* XXX I think the following code should be moved to separate hook
if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0)
{
if (! noninteractive)
- return -2; /* Close this display. */
+ return -2; /* Close this device. */
else
n_to_read = 0;
}
when the control tty is taken away.
Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
if (nread == -1 && errno == EIO)
- return -2; /* Close this display. */
+ return -2; /* Close this device. */
#if defined (AIX) && (! defined (aix386) && defined (_BSD))
/* The kernel sometimes fails to deliver SIGHUP for ptys.
This looks incorrect, but it isn't, because _BSD causes
O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
and that causes a value other than 0 when there is no input. */
if (nread == 0)
- return -2; /* Close this display. */
+ return -2; /* Close this device. */
#endif
}
while (
int i;
- struct gcpro gcpro1;
-
/* 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
menu_bar_items_vector = Fmake_vector (make_number (24), Qnil);
menu_bar_items_index = 0;
- GCPRO1 (menu_bar_items_vector);
-
/* Build our list of keymaps.
If we recognize a function key and replace its escape sequence in
keybuf with its symbol, or if the sequence starts with a mouse
menu_bar_items_index = i;
Vinhibit_quit = oquit;
- UNGCPRO;
return menu_bar_items_vector;
}
\f
last_nonmenu_event = Qnil;
delayed_switch_frame = Qnil;
- fkey.map = fkey.parent = Vfunction_key_map;
- keytran.map = keytran.parent = Vkey_translation_map;
+ fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
+ keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map;
/* If there is no translation-map, turn off scanning. */
fkey.start = fkey.end = KEYMAPP (fkey.map) ? 0 : bufsize + 1;
keytran.start = keytran.end = KEYMAPP (keytran.map) ? 0 : bufsize + 1;
{
/* Must preserve main program's value of errno. */
int old_errno = errno;
- struct display *display;
+ struct device *device;
#if defined (USG) && !defined (POSIX_SIGNALS)
/* USG systems forget handlers when they are used;
SIGNAL_THREAD_CHECK (signalnum);
/* See if we have an active display on our controlling terminal. */
- display = get_named_tty_display (NULL);
- if (!display)
+ device = get_named_tty (NULL);
+ if (!device)
{
/* If there are no frames there, let's pretend that we are a
well-behaving UN*X program and quit. */
controlling tty, if we have a frame there. We disable the
interrupt key on secondary ttys, so the SIGINT must have come
from the controlling tty. */
- internal_last_event_frame = display->display_info.tty->top_frame;
+ internal_last_event_frame = device->display_info.tty->top_frame;
handle_interrupt ();
}
/* XXX This code needs to be revised for multi-tty support. */
if (!NILP (Vquit_flag)
#ifndef MSDOS
- && get_named_tty_display (NULL)
+ && get_named_tty (NULL)
#endif
)
{
#endif
#ifndef DOS_NT
- /* this causes startup screen to be restored and messes with the mouse */
- reset_all_sys_modes ();
+ if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
+ /* this causes startup screen to be restored and messes with the mouse */
+ reset_sys_modes (CURTTY ());
#endif
#ifdef SIGIO
/* Note SIGIO has been undef'd if FIONREAD is missing. */
- if (FRAME_DISPLAY (SELECTED_FRAME ())->read_socket_hook)
+ if (FRAME_DEVICE (SELECTED_FRAME ())->read_socket_hook)
{
/* When using X, don't give the user a real choice,
because we haven't implemented the mechanisms to support it. */
quit_char = XINT (quit) & (NILP (meta) ? 0177 : 0377);
#ifndef DOS_NT
- init_all_sys_modes ();
+ if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
+ init_sys_modes (CURTTY ());
#endif
#ifdef POLL_FOR_INPUT
kb->reference_count = 0;
kb->Vsystem_key_alist = Qnil;
kb->system_key_syms = Qnil;
+ kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
+ Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
+ kb->Vlocal_key_translation_map = Fmake_sparse_keymap (Qnil);
+ Fset_keymap_parent (kb->Vlocal_key_translation_map, Vkey_translation_map);
kb->Vdefault_minibuffer_frame = Qnil;
}
&& FRAMEP (selected_frame)
&& FRAME_LIVE_P (XFRAME (selected_frame)))
{
- current_kboard = XFRAME (selected_frame)->kboard;
+ current_kboard = XFRAME (selected_frame)->device->kboard;
if (current_kboard == kb)
abort ();
}
menu_bar_one_keymap_changed_items = Qnil;
staticpro (&menu_bar_one_keymap_changed_items);
+ menu_bar_items_vector = Qnil;
+ staticpro (&menu_bar_items_vector);
+
defsubr (&Sevent_convert_list);
defsubr (&Sread_key_sequence);
defsubr (&Sread_key_sequence_vector);
command exit.
The value `kill-region' is special; it means that the previous command
-was a kill command. */);
+was a kill command.
+
+`last-command' has a separate binding for each display device.
+See Info node `(elisp)Multiple displays'. */);
DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
doc: /* Same as `last-command', but never altered by Lisp code. */);
doc: /* Normal hook run when clearing the echo area. */);
#endif
Qecho_area_clear_hook = intern ("echo-area-clear-hook");
+ staticpro (&Qecho_area_clear_hook);
SET_SYMBOL_VALUE (Qecho_area_clear_hook, Qnil);
DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag,
It also replaces `overriding-local-map'.
This variable is intended to let commands such as `universal-argument'
-set up a different keymap for reading the next command. */);
+set up a different keymap for reading the next command.
+
+`overriding-terminal-local-map' has a separate binding for each display device.
+See Info node `(elisp)Multiple displays'. */);
DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
doc: /* Keymap that overrides all other local keymaps.
doc: /* Alist of system-specific X windows key symbols.
Each element should have the form (N . SYMBOL) where N is the
numeric keysym code (sans the \"system-specific\" bit 1<<28)
-and SYMBOL is its name. */);
+and SYMBOL is its name.
+
+`system-key-alist' has a separate binding for each display device.
+See Info node `(elisp)Multiple displays'.
+
+Note that the currently selected frame has very little to do with
+which binding of this variable is active at any given moment. If you
+need set or get the binding on a specific display, use
+`terminal-local-value' and `set-terminal-local-value'. */);
+
+ DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map,
+ doc: /* Keymap mapping ASCII function key sequences onto their preferred forms.
+This allows Emacs to recognize function keys sent from ASCII
+terminals at any point in a key sequence.
+
+The `read-key-sequence' function replaces any subsequence bound by
+`function-key-map' with its binding. More precisely, when the active
+keymaps have no binding for the current key sequence but
+`function-key-map' binds a suffix of the sequence to a vector or string,
+`read-key-sequence' replaces the matching suffix with its binding, and
+continues with the new sequence.
+
+The events that come from bindings in `function-key-map' are not
+themselves looked up in `function-key-map'.
+
+For example, suppose `function-key-map' binds `ESC O P' to [f1].
+Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
+`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix
+key, typing `ESC O P x' would return [f1 x].
+
+`function-key-map' has a separate binding for each display device.
+See Info node `(elisp)Multiple displays'. If you need to define a
+binding on all display devices, change `global-function-key-map'
+instead.
+
+Note that the currently selected frame has very little to do with
+which binding of this variable is active at any given moment. If you
+need set or get the binding on a specific display, use
+`terminal-local-value' and `set-terminal-local-value'. */);
+
+ 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 display devices should go
+here. */);
+ Vfunction_key_map = Fmake_sparse_keymap (Qnil);
+
+ DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_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.
+
+`key-translation-map' has a separate binding for each display device.
+(See Info node `(elisp)Multiple displays'.) If you need to set a key
+translation on all devices, change `global-key-translation-map' instead.
+
+Note that the currently selected frame has very little to do with
+which binding of this variable is active at any given moment. If you
+need set or get the binding on a specific display, use
+`terminal-local-value' and `set-terminal-local-value'. */);
+
+ DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
+ doc: /* The parent keymap of all `local-key-translation-map' instances.
+Key translations that apply to all display devices should go here. */);
+ Vkey_translation_map = Fmake_sparse_keymap (Qnil);
DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
doc: /* List of deferred actions to be performed at a later time.
mark_object (kb->Vlast_kbd_macro);
mark_object (kb->Vsystem_key_alist);
mark_object (kb->system_key_syms);
+ mark_object (kb->Vlocal_function_key_map);
+ mark_object (kb->Vlocal_key_translation_map);
mark_object (kb->Vdefault_minibuffer_frame);
mark_object (kb->echo_string);
}