(Flookup_key): Add error message for trying to bind [DEL], [RET], etc.
authorRichard M. Stallman <rms@gnu.org>
Fri, 28 Dec 2001 18:39:20 +0000 (18:39 +0000)
committerRichard M. Stallman <rms@gnu.org>
Fri, 28 Dec 2001 18:39:20 +0000 (18:39 +0000)
src/ChangeLog
src/keymap.c

index aa59837..8428636 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-28  Richard M. Stallman  <rms@gnu.org>
+
+       * keymap.c (Flookup_key):
+       Add error message for trying to bind [DEL], [RET], etc.
+
 2001-12-28  Gerd Moellmann  <gerd@gnu.org>
 
        * xterm.c (x_setup_relief_colors): Don't compute an image's
index cc70f63..38cafb9 100644 (file)
@@ -48,6 +48,9 @@ Lisp_Object meta_map;         /* The keymap used for globally bound
 Lisp_Object control_x_map;     /* The keymap used for globally bound
                                   C-x-prefixed default commands */
 
+/* Alist of elements like (DEL . "\d").  */
+Lisp_Object exclude_keys;
+
 /* was MinibufLocalMap */
 Lisp_Object Vminibuffer_local_map;
                                /* The keymap used by the minibuf for local
@@ -1008,6 +1011,12 @@ the front of KEYMAP.  */)
       if (CONSP (c) && lucid_event_type_list_p (c))
        c = Fevent_convert_list (c);
 
+      if (SYMBOLP (c) && ! NILP (Fassoc (Fsymbol_name (c), exclude_keys)))
+       error ("To bind the key %s, use; use \"%s\", not [%s]",
+              XSYMBOL (c)->name->data,
+              XSTRING (XCDR (Fassoc (Fsymbol_name (c), exclude_keys)))->data,
+              XSYMBOL (c)->name->data);
+
       if (INTEGERP (c)
          && (XINT (c) & meta_bit)
          && !metized)
@@ -1025,7 +1034,7 @@ the front of KEYMAP.  */)
        }
 
       if (!INTEGERP (c) && !SYMBOLP (c) && !CONSP (c))
-       error ("Key sequence contains invalid events");
+       error ("Key sequence contains invalid event");
 
       if (idx == length)
        RETURN_UNGCPRO (store_in_keymap (keymap, c, def));
@@ -1098,6 +1107,9 @@ recognize the default bindings, just as `read-key-sequence' does.  */)
       if (XINT (c) & 0x80 && STRINGP (key))
        XSETINT (c, (XINT (c) | meta_modifier) & ~0x80);
 
+      if (!INTEGERP (c) && !SYMBOLP (c) && !CONSP (c))
+       error ("Key sequence contains invalid event");
+
       cmd = access_keymap (keymap, c, t_ok, 0, 1);
       if (idx == length)
        RETURN_UNGCPRO (cmd);
@@ -3370,6 +3382,15 @@ syms_of_keymap ()
   Fset (intern ("ctl-x-map"), control_x_map);
   Ffset (intern ("Control-X-prefix"), control_x_map);
 
+  exclude_keys
+    = Fcons (Fcons (build_string ("DEL"), build_string ("\\d")),
+            Fcons (Fcons (build_string ("TAB"), build_string ("\\t")),
+                   Fcons (Fcons (build_string ("RET"), build_string ("\\r")),
+                          Fcons (Fcons (build_string ("ESC"), build_string ("\\e")),
+                                 Fcons (Fcons (build_string ("SPC"), build_string (" ")),
+                                        Qnil)))));
+  staticpro (&exclude_keys);
+
   DEFVAR_LISP ("define-key-rebound-commands", &Vdefine_key_rebound_commands,
               doc: /* List of commands given new key bindings recently.
 This is used for internal purposes during Emacs startup;