emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proposal: Bind backspace and delete like DEL in view-mode


From: Kim F. Storm
Subject: Re: Proposal: Bind backspace and delete like DEL in view-mode
Date: 27 Dec 2001 21:13:58 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

Richard Stallman <address@hidden> writes:

> It sounds like you are suggesting we define DEL as a sort of alias for
> "\d" for rebinding purposes.
>
Exactly!
 
> That might be reasonable, given that `DEL' as an input event is itself
> meaningless and probably always will be meaningless.  But I think it
> might be better to make this an error, and have the error message say
> you should bind "\d" instead.  That would get the same job done by
> telling people how to do this in the way that is, and always has been,
> preferred.
> 
> The same could be done for TAB, ESC, RET and SPC.
> 
>     Sure, but how does the novice user that TAB is "\t".
> 
> Currently, by reading the Emacs Manual.
> But adding that error would offer people another place to learn from.
> 

In general, I think it would be nice if define-key would issue an
error message when making a meaningless binding (i.e. for a symbol
which cannot occur as an event).  Unfortunately, I don't know how to
make such a test i general - and I don't see why DEL or TAB should
have special treatment here...

Basically, I still feel that when emacs prints a certain name for an
event, then it should be possible to use that same name when making a
binding for that event.

Below is a patch which add a new function event-convert-symbol which
interprets DEL, TAB, etc. as valid `aliases' for the corresponding key
codes; it also accepts the normal modifiers like M-DEL.

This function is then used in define-key and lookup-key as well as
single-key-description and event-convert-list (for completeness).

Except for the new function itself, the changes are very small.
Please consider this patch and let me know what you think.
++kfs

Index: keyboard.c
===================================================================
RCS file: /cvs/emacs/src/keyboard.c,v
retrieving revision 1.645
diff -u -r1.645 keyboard.c
--- keyboard.c  25 Dec 2001 23:38:23 -0000      1.645
+++ keyboard.c  27 Dec 2001 19:55:13 -0000
@@ -5914,6 +5914,94 @@
   return apply_modifiers (modifiers, value);
 }
 
+DEFUN ("event-convert-symbol", Fevent_convert_symbol, Sevent_convert_symbol, 
1, 1, 0,
+       doc: /* Return integer character of base event SYMBOL.
+The following symbols are recognized: DEL, TAB, RET, SPC, ESC.
+If SYMBOL is not recognized, return SYMBOL.  */)
+     (symbol)
+     Lisp_Object symbol;
+{
+  unsigned char *data;
+  struct Lisp_String *name;
+  int code, modifiers;
+
+  if (!SYMBOLP (symbol))
+    return symbol;
+
+  name = XSYMBOL (symbol)->name;
+  if (name->size < 3)
+    return symbol;
+  
+  data = name->data + name->size - 3;
+  if (name->size > 3 && data[-1] != '-')
+    return symbol;
+
+  code = 0;
+
+  switch (data[0])
+    {
+    case 'D':
+      if (data[1] == 'E' && data[2] == 'L')
+       code = 0177;
+       break;
+    case 'E':
+      if (data[1] == 'S' && data[2] == 'C')
+       code = 033;
+       break;
+    case 'R':
+      if (data[1] == 'E' && data[2] == 'T')
+       code = '\r';
+      break;
+    case 'S':
+      if (data[1] == 'P' && data[2] == 'C')
+       code = ' ';
+      break;
+    case 'T':
+      if (data[1] == 'A' && data[2] == 'B')
+       code = '\t';
+      break;
+    }
+  if (!code)
+    return symbol;
+
+  modifiers = 0;
+  if (name->size > 3) {
+    data = name->data;
+    while (data[1] == '-')
+      {
+       switch (data[0])
+         {
+         case 'M':
+           modifiers |= meta_modifier;
+           break;
+         case 'C':
+           modifiers |= ctrl_modifier;
+           break;
+         case 'S':
+           modifiers |= shift_modifier;
+           break;
+         case 'H':
+           modifiers |= hyper_modifier;
+           break;
+         case 's':
+           modifiers |= super_modifier;
+           break;
+         case 'A':
+           modifiers |= alt_modifier;
+           break;
+         default:
+           return symbol;
+         }
+       data += 2;
+      }
+    if (data != name->data + name->size - 3)
+      return symbol;
+    if ((unsigned)code < ' ')
+      modifiers &= ~ctrl_modifier;
+  }
+  return make_number(modifiers | code);
+}
+
 /* Convert a list that represents an event type,
    such as (ctrl meta backspace), into the usual representation of that
    event type as a number or a symbol.  */
@@ -5959,6 +6047,13 @@
   if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1)
     XSETINT (base, XSYMBOL (base)->name->data[0]);
 
+  if (SYMBOLP (base))
+    {
+      base = Fevent_convert_symbol (base);
+      if (SYMBOLP (base))
+       return apply_modifiers (modifiers, base);
+    }
+
   if (INTEGERP (base))
     {
       /* Turn (shift a) into A.  */
@@ -5976,8 +6071,6 @@
       else
        return make_number (modifiers | XINT (base));
     }
-  else if (SYMBOLP (base))
-    return apply_modifiers (modifiers, base);
   else
     {
       error ("Invalid base event");
@@ -10538,6 +10631,7 @@
   menu_bar_one_keymap_changed_items = Qnil;
   staticpro (&menu_bar_one_keymap_changed_items);
 
+  defsubr (&Sevent_convert_symbol);
   defsubr (&Sevent_convert_list);
   defsubr (&Sread_key_sequence);
   defsubr (&Sread_key_sequence_vector);
Index: keymap.c
===================================================================
RCS file: /cvs/emacs/src/keymap.c,v
retrieving revision 1.250
diff -u -r1.250 keymap.c
--- keymap.c    20 Dec 2001 18:26:10 -0000      1.250
+++ keymap.c    27 Dec 2001 19:55:14 -0000
@@ -1007,6 +1007,8 @@
 
       if (CONSP (c) && lucid_event_type_list_p (c))
        c = Fevent_convert_list (c);
+      else
+       c = Fevent_convert_symbol (c);
 
       if (INTEGERP (c)
          && (XINT (c) & meta_bit)
@@ -1093,6 +1095,8 @@
 
       if (CONSP (c) && lucid_event_type_list_p (c))
        c = Fevent_convert_list (c);
+      else
+       c = Fevent_convert_symbol (c);
 
       /* Turn the 8th bit of string chars into a meta modifier.  */
       if (XINT (c) & 0x80 && STRINGP (key))
@@ -1959,6 +1963,8 @@
 {
   if (CONSP (key) && lucid_event_type_list_p (key))
     key = Fevent_convert_list (key);
+  else
+    key = Fevent_convert_symbol (key);
 
   key = EVENT_HEAD (key);
 
Index: lisp.h
===================================================================
RCS file: /cvs/emacs/src/lisp.h,v
retrieving revision 1.403
diff -u -r1.403 lisp.h
--- lisp.h      22 Dec 2001 14:01:52 -0000      1.403
+++ lisp.h      27 Dec 2001 19:55:15 -0000
@@ -2744,6 +2744,7 @@
 extern Lisp_Object Qvertical_scroll_bar;
 extern void discard_mouse_events P_ ((void));
 EXFUN (Fevent_convert_list, 1);
+EXFUN (Fevent_convert_symbol, 1);
 EXFUN (Fread_key_sequence, 5);
 EXFUN (Fset_input_mode, 4);
 extern int detect_input_pending P_ ((void));
Index: w32fns.c
===================================================================
RCS file: /cvs/emacs/src/w32fns.c,v
retrieving revision 1.145
diff -u -r1.145 w32fns.c
--- w32fns.c    13 Dec 2001 09:58:12 -0000      1.145
+++ w32fns.c    27 Dec 2001 19:55:19 -0000
@@ -13975,6 +13975,8 @@
 
   if (CONSP (c) && lucid_event_type_list_p (c))
     c = Fevent_convert_list (c);
+  else
+    c = Fevent_convert_symbol (c);
 
   UNGCPRO;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]