]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
Merged in changes from CVS trunk.
[gnu-emacs] / src / keyboard.c
index 4a4afa326f83a68050d9f287797d01cde5f6f887..74f8d7d51e0763a1a516dfc4e4154585fef6c47b 100644 (file)
@@ -1,6 +1,7 @@
 /* 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.
 
@@ -16,8 +17,8 @@ GNU General Public License for more details.
 
 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>
@@ -440,8 +441,11 @@ 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;
+
 /* Parent keymap of terminal-local key-translation-map instances.  */
-Lisp_Object Vglobal_key_translation_map;
+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.  */
@@ -1112,8 +1116,8 @@ struct kboard_stack
 static struct kboard_stack *kboard_stack;
 
 void
-push_display_kboard (d)
-     struct display *d;
+push_device_kboard (d)
+     struct device *d;
 {
 #ifdef MULTI_KBOARD
   struct kboard_stack *p
@@ -4007,7 +4011,7 @@ kbd_buffer_get_event (kbp, used_mouse_menu)
          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)).  */
@@ -4169,9 +4173,9 @@ kbd_buffer_get_event (kbp, used_mouse_menu)
       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;
 
@@ -6670,13 +6674,13 @@ read_avail_input (expected)
 {
   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)
         {
@@ -6702,7 +6706,7 @@ read_avail_input (expected)
               /* 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
@@ -6713,11 +6717,11 @@ read_avail_input (expected)
                    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)
@@ -6735,12 +6739,12 @@ read_avail_input (expected)
 
 /* 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)
 {
@@ -6749,10 +6753,10 @@ tty_read_avail_input (struct display *display,
      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
@@ -6782,7 +6786,7 @@ tty_read_avail_input (struct display *display,
   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;
     }
@@ -6811,14 +6815,14 @@ tty_read_avail_input (struct display *display,
          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 (
@@ -6998,8 +7002,6 @@ menu_bar_items (old)
 
   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
@@ -7015,8 +7017,6 @@ menu_bar_items (old)
     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
@@ -7120,7 +7120,6 @@ menu_bar_items (old)
   menu_bar_items_index = i;
 
   Vinhibit_quit = oquit;
-  UNGCPRO;
   return menu_bar_items_vector;
 }
 \f
@@ -8666,8 +8665,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   last_nonmenu_event = Qnil;
 
   delayed_switch_frame = Qnil;
-  fkey.map = fkey.parent = current_kboard->Vfunction_key_map;
-  keytran.map = keytran.parent = current_kboard->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;
@@ -10365,7 +10364,7 @@ interrupt_signal (signalnum)    /* If we don't have an argument, */
 {
   /* 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;
@@ -10377,8 +10376,8 @@ interrupt_signal (signalnum)    /* If we don't have an argument, */
   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. */
@@ -10392,7 +10391,7 @@ interrupt_signal (signalnum)    /* If we don't have an argument, */
          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 ();
     }
@@ -10421,7 +10420,7 @@ 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
       )
     {
@@ -10606,7 +10605,7 @@ See also `current-input-mode'.  */)
 
 #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.  */
@@ -10780,9 +10779,10 @@ init_kboard (kb)
   kb->reference_count = 0;
   kb->Vsystem_key_alist = Qnil;
   kb->system_key_syms = Qnil;
-  kb->Vfunction_key_map = Fmake_sparse_keymap (Qnil);
-  kb->Vkey_translation_map = Fmake_sparse_keymap (Qnil);
-  Fset_keymap_parent (kb->Vkey_translation_map, Vglobal_key_translation_map);
+  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;
 }
 
@@ -10819,7 +10819,7 @@ delete_kboard (kb)
       && FRAMEP (selected_frame)
       && FRAME_LIVE_P (XFRAME (selected_frame)))
     {
-      current_kboard = XFRAME (selected_frame)->display->kboard;
+      current_kboard = XFRAME (selected_frame)->device->kboard;
       if (current_kboard == kb)
        abort ();
     }
@@ -11163,6 +11163,9 @@ syms_of_keyboard ()
   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);
@@ -11439,6 +11442,7 @@ might happen repeatedly and make Emacs nonfunctional.  */);
               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,
@@ -11496,7 +11500,7 @@ 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 ("function-key-map", Vfunction_key_map,
+  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.
@@ -11517,14 +11521,22 @@ Typing `ESC O P' to `read-key-sequence' would return [f1].  Typing
 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'.
+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_KBOARD ("key-translation-map", Vkey_translation_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 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.
@@ -11538,11 +11550,10 @@ 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 ("global-key-translation-map", &Vglobal_key_translation_map,
-               doc: /* The parent keymap of all terminal-local `key-translation-map' instances.
-Key translations that are not specific to a display device flavour
-should go here.  */);
-  Vglobal_key_translation_map = Fmake_sparse_keymap (Qnil);
+  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.
@@ -11707,8 +11718,8 @@ mark_kboards ()
       mark_object (kb->Vlast_kbd_macro);
       mark_object (kb->Vsystem_key_alist);
       mark_object (kb->system_key_syms);
-      mark_object (kb->Vfunction_key_map);
-      mark_object (kb->Vkey_translation_map);
+      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);
     }