]> code.delx.au - gnu-emacs/blobdiff - src/keymap.c
(syms_of_keymap): staticpro global_map.
[gnu-emacs] / src / keymap.c
index bb141e84e6cf5a7a958fa04abf8d01c5a1b37d7f..e2a1b97c9dafc02f11d35a36ae1ccb55208b249e 100644 (file)
@@ -307,6 +307,11 @@ PARENT should be nil or another keymap.")
         If we came to the end, add the parent in PREV.  */
       if (! CONSP (list) || EQ (Qkeymap, XCONS (list)->car))
        {
+         /* If we already have the right parent, return now
+            so that we avoid the loops below.  */
+         if (EQ (XCONS (prev)->cdr, parent))
+           return parent;
+
          XCONS (prev)->cdr = parent;
          break;
        }
@@ -379,6 +384,11 @@ fix_submap_inheritance (map, event, submap)
   else
     parent_entry = Qnil;
 
+  /* If MAP's parent has something other than a keymap,
+     our own submap shadows it completely, so use nil as SUBMAP's parent.  */
+  if (! (CONSP (parent_entry) && EQ (XCONS (parent_entry)->car, Qkeymap)))
+    parent_entry = Qnil;
+
   if (! EQ (parent_entry, submap))
     Fset_keymap_parent (submap, parent_entry);
 }
@@ -2710,6 +2720,10 @@ syms_of_keymap ()
                      Fcons (Fmake_vector (make_number (0400), Qnil), Qnil));
   Fset (intern ("global-map"), global_map);
 
+  current_global_map = global_map;
+  staticpro (&global_map);
+  staticpro (&current_global_map);
+
   meta_map = Fmake_keymap (Qnil);
   Fset (intern ("esc-map"), meta_map);
   Ffset (intern ("ESC-prefix"), meta_map);
@@ -2740,8 +2754,6 @@ don't alter it yourself.");
     "Local keymap for minibuffer input with completion, for exact match.");
   Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil);
 
-  current_global_map = global_map;
-
   DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist,
     "Alist of keymaps to use for minor modes.\n\
 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\