changeset 5746:b8c2808b33d4

Document #'events-to-keys some more, use it less. lisp/ChangeLog addition: 2013-07-10 Aidan Kehoe <kehoea@parhasard.net> * minibuf.el (get-user-response): * cmdloop.el (y-or-n-p-minibuf): No need to call #'events-to-keys in these two functions, #'lookup-key accepts events directly. * keymap.el: * keymap.el (events-to-keys): Document this function some more. Stop passing strings through unexamined, treat them as vectors of characters. Event keys are never integers, remove some code that only ran if (integerp (event-key ce)). Event keys are never numbers, don't check for that. Don't create (menu-selection call-interactively function-name) keystrokes for menu choices, #'character-to-event doesn't understand that syntax, so nothing uses it. Don't ever accept mouse events, #'character-to-event doesn't accept our synthesising of them. src/ChangeLog addition: 2013-07-10 Aidan Kehoe <kehoea@parhasard.net> * keymap.c: * keymap.c (key_desc_list_to_event): Drop the allow_menu_events argument. Don't accept lists starting with Qmenu_selection as describing keys, nothing generates them in a way this function understands. The intention is reasonable but the implementation was never documented and never finished. * keymap.c (syms_of_keymap): Drop Qmenu_selection. * events.c (Fcharacter_to_event): * keymap.h: Drop the allow_menu_events argument to key_desc_list_to_event.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 10 Jul 2013 14:14:30 +0100
parents 9c17f7be0b92
children 52b9fe8f44c0
files lisp/ChangeLog lisp/cmdloop.el lisp/keymap.el lisp/minibuf.el src/ChangeLog src/events.c src/keymap.c src/keymap.h
diffstat 8 files changed, 81 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Jun 25 15:31:58 2013 -0600
+++ b/lisp/ChangeLog	Wed Jul 10 14:14:30 2013 +0100
@@ -10,6 +10,26 @@
 	* paragraphs.el (sentence-end): Use octal, not Unicode, escapes.
 	* (sentence-end-base): Use non-ASCII only in Mule.
 
+2013-07-10  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* minibuf.el (get-user-response):
+	* cmdloop.el (y-or-n-p-minibuf):
+	No need to call #'events-to-keys in these two functions,
+	#'lookup-key accepts events directly.
+	* keymap.el:
+	* keymap.el (events-to-keys):
+	Document this function some more.
+	Stop passing strings through unexamined, treat them as vectors of
+	characters.
+	Event keys are never integers, remove some code that only ran if
+	(integerp (event-key ce)).
+	Event keys are never numbers, don't check for that.
+	Don't create (menu-selection call-interactively function-name)
+	keystrokes for menu choices, #'character-to-event doesn't
+	understand that syntax, so nothing uses it.
+	Don't ever accept mouse events, #'character-to-event doesn't
+	accept our synthesising of them.
+
 2013-06-17  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* process.el (process-synchronize-point): Moved to a label.
--- a/lisp/cmdloop.el	Tue Jun 25 15:31:58 2013 -0600
+++ b/lisp/cmdloop.el	Wed Jul 10 14:14:30 2013 +0100
@@ -450,8 +450,7 @@
               (message "%s%s%s%s" pre prompt yn (single-key-description event))
               (setq quit-flag nil)
               (signal 'quit '())))
-        (let* ((keys (events-to-keys (vector event)))
-	       (def (lookup-key query-replace-map keys)))
+        (let ((def (lookup-key query-replace-map (vector event))))
           (cond ((eq def 'skip)
                  (message "%s%sNo" prompt yn)
 		 (setq yn nil))
--- a/lisp/keymap.el	Tue Jun 25 15:31:58 2013 -0600
+++ b/lisp/keymap.el	Wed Jul 10 14:14:30 2013 +0100
@@ -305,52 +305,54 @@
 
 
 ;;; Converting vectors of events to a read-equivalent form.
-;;; This is used both by call-interactively (for the command history)
-;;; and by macros.el (for saving keyboard macros to a file).
+(defun events-to-keys (events &optional no-mice)
+ "Given a vector of event objects, return a vector of key descriptors.
+
+If all events can be represented unambiguously as characters, return a
+string.  Both the string and the vector will be equivalent to the events, if
+the elements are passed to `character-to-event'.
+
+If an event represents a key press of a printable ASCII character between ?@
+and ?_, with the control modifier and only the control modifier, it is
+returned as a character between ?\x00 and ?\x1f, inclusive. ?\\C-i, ?\\C-j,
+?\\C-m are returned as the symbols `tab', `linefeed' and `return',
+respectively.
 
-;; #### why does (events-to-keys [backspace]) return "\C-h"?
-;; BTW, this function is a mess, and macros.el does *not* use it, in
-;; spite of the above comment.  `format-kbd-macro' is used to save
-;; keyboard macros to a file.
-(defun events-to-keys (events &optional no-mice)
- "Given a vector of event objects, returns a vector of key descriptors,
-or a string (if they all fit in the ASCII range).
-Optional arg NO-MICE means that button events are not allowed."
+There is a similar equivalence between ASCII characters with the meta
+modifier and Latin 1 characters, but this function does not use that
+equivalence.
+
+Obsolete optional argument NO-MICE means that mouse events are not allowed.
+These are actually never allowed, since `character-to-event' never accepts
+them.
+
+EVENTS can be a string, and will be treated as a vector of the events
+corresponding to those characters."
+ ;; This is only used in packages. There were some contexts where it was
+ ;; used in core, but those dated from before #'lookup-key accepted events
+ ;; in KEYS; it conses less and is more accurate to use the events directly,
+ ;; rather than calling this function. It'd be nice to move this to
+ ;; xemacs-base and add an autoload, there's no need for it to be dumped.
  (if (and events (symbolp events)) (setq events (vector events)))
- (cond ((stringp events)
-        events)
-       ((not (vectorp events))
-        (signal 'wrong-type-argument (list 'vectorp events)))
-       ((let* ((length (length events))
+ (check-type events array)
+ (cond ((let* ((length (length events))
                (string (make-string length 0))
                c ce
                (i 0))
           (while (< i length)
             (setq ce (aref events i))
             (or (eventp ce) (setq ce (character-to-event ce)))
-            ;; Normalize `c' to `?c' and `(control k)' to `?\C-k'
-            ;; By passing t for the `allow-meta' arg we could get kbd macros
-            ;; with meta in them to translate to the string form instead of
-            ;; the list/symbol form; but I expect that would cause confusion,
-            ;; so let's use the list/symbol form whenever there's
-            ;; any ambiguity.
+            ;; Normalize `c' to `?c' and `(control k)' to `?\C-k' We don't
+            ;; "normalize" Latin 1 to the corresponding meta characters, or
+            ;; vice-versa.
             (setq c (event-to-character ce))
             (if (and c
                      (key-press-event-p ce))
-                (cond ((symbolp (event-key ce))
-                       (if (get (event-key ce) 'character-of-keysym)
-                           ;; Don't use a string for `backspace' and `tab' to
-                           ;;  avoid that unpleasant little ambiguity.
-                           (setq c nil)))
-                      ((and (= (event-modifier-bits ce) 1) ;control
-                            (integerp (event-key ce)))
-                       (let* ((te (character-to-event c)))
-                         (if (and (symbolp (event-key te))
-                                  (get (event-key te) 'character-of-keysym))
-                             ;; Don't "normalize" (control i) to tab
-                             ;;  to avoid the ambiguity in the other direction
-                             (setq c nil))
-                         (deallocate-event te)))))
+                (if (symbolp (event-key ce))
+                    (if (get (event-key ce) 'character-of-keysym)
+                        ;; Don't use a string `tab' to avoid that unpleasant
+                        ;; little ambiguity.
+                        (setq c nil))))
             (if c
                 (aset string i c)
                 (setq i length string nil))
@@ -358,33 +360,15 @@
           string))
        (t
         (let* ((length (length events))
-               (new (copy-sequence events))
+               (new (vconcat events nil))
                event mods key
                (i 0))
           (while (< i length)
             (setq event (aref events i))
+            (or (eventp event) (setq event (character-to-event event)))
             (cond ((key-press-event-p event)
                    (setq mods (event-modifiers event)
                          key (event-key event))
-                   (if (numberp key)
-                       (setq key (intern (make-string 1 key))))
-                   (aset new i (if mods
-                                   (nconc mods (cons key nil))
-                                   key)))
-                  ((misc-user-event-p event)
-                   (aset new i (list 'menu-selection
-                                     (event-function event)
-                                     (event-object event))))
-                  ((or (button-press-event-p event)
-                       (button-release-event-p event))
-                   (if no-mice
-                       (error
-                         "Mouse events can't be saved in keyboard macros."))
-                   (setq mods (event-modifiers event)
-                         key (intern (format "button%d%s"
-                                             (event-button event)
-                                             (if (button-release-event-p event)
-                                                 "up" ""))))
                    (aset new i (if mods
                                    (nconc mods (cons key nil))
                                    key)))
@@ -392,10 +376,10 @@
                        (and (consp event) (symbolp (car event))))
                    (aset new i event))
                   (t
-                   (signal 'wrong-type-argument (list 'eventp event))))
+                   (signal 'wrong-type-argument
+                           (list 'key-press-event-p event))))
             (setq i (1+ i)))
           new))))
-
 
 (defun next-key-event ()
   "Return the next available keyboard event."
--- a/lisp/minibuf.el	Tue Jun 25 15:31:58 2013 -0600
+++ b/lisp/minibuf.el	Wed Jul 10 14:14:30 2013 +0100
@@ -2268,15 +2268,8 @@
 				 (single-key-description event))
 			(setq quit-flag nil)
 			(signal 'quit '())))
-		  (let* ((keys (events-to-keys (vector event)))
-			 (def (lookup-key query-replace-map keys)))
+		  (let ((def (lookup-key query-replace-map (vector event))))
 		    (cond
-; 		     ((eq def 'skip)
-; 		      (message "%s%sNo" question possible)
-; 		      (return nil))
-; 		     ((eq def 'act)
-; 		      (message "%s%sYes" question possible)
-; 		      (return t))
 		     ((eq def 'recenter)
 		      (recenter))
 		     ((or (eq def 'quit) (eq def 'exit-prefix))
--- a/src/ChangeLog	Tue Jun 25 15:31:58 2013 -0600
+++ b/src/ChangeLog	Wed Jul 10 14:14:30 2013 +0100
@@ -10,6 +10,21 @@
 	* number-gmp.c (init_number_gmp): Add void param to silence GCC.
 	* number-mp.c (init_number_mp): Ditto.
 
+2013-07-10  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* keymap.c:
+	* keymap.c (key_desc_list_to_event):
+	Drop the allow_menu_events argument.
+	Don't accept lists starting with Qmenu_selection as describing
+	keys, nothing generates them in a way this function
+	understands. The intention is reasonable but the implementation
+	was never documented and never finished.
+	* keymap.c (syms_of_keymap):
+	Drop Qmenu_selection.
+	* events.c (Fcharacter_to_event):
+	* keymap.h:
+	Drop the allow_menu_events argument to key_desc_list_to_event.
+
 2013-06-17  Jerry James  <james@xemacs.org>
 
 	* alloc.c (make_bignum_un): New function.
--- a/src/events.c	Tue Jun 25 15:31:58 2013 -0600
+++ b/src/events.c	Wed Jul 10 14:14:30 2013 +0100
@@ -1441,7 +1441,7 @@
   else
     CHECK_LIVE_EVENT (event);
   if (CONSP (keystroke) || SYMBOLP (keystroke))
-    key_desc_list_to_event (keystroke, event, 1);
+    key_desc_list_to_event (keystroke, event);
   else
     {
       CHECK_CHAR_COERCE_INT (keystroke);
--- a/src/keymap.c	Tue Jun 25 15:31:58 2013 -0600
+++ b/src/keymap.c	Wed Jul 10 14:14:30 2013 +0100
@@ -223,8 +223,6 @@
 Lisp_Object Qbutton##num##up;
 #include "keymap-buttons.h"
 
-Lisp_Object Qmenu_selection;
-
 /* Emacs compatibility */
 #define FROB(num)				\
 Lisp_Object Qmouse_##num;			\
@@ -1520,31 +1518,10 @@
 
 /* Used by character-to-event */
 void
-key_desc_list_to_event (Lisp_Object list, Lisp_Object event,
-                        int allow_menu_events)
+key_desc_list_to_event (Lisp_Object list, Lisp_Object event)
 {
   Lisp_Key_Data raw_key;
 
-  if (allow_menu_events &&
-      CONSP (list) &&
-      /* #### where the hell does this come from? */
-      EQ (XCAR (list), Qmenu_selection))
-    {
-      Lisp_Object fn, arg;
-      if (! NILP (Fcdr (Fcdr (list))))
-	invalid_argument ("Invalid menu event desc", list);
-      arg = Fcar (Fcdr (list));
-      if (SYMBOLP (arg))
-	fn = Qcall_interactively;
-      else
-	fn = Qeval;
-      XSET_EVENT_TYPE (event, misc_user_event);
-      XSET_EVENT_CHANNEL (event, wrap_frame (selected_frame ()));
-      XSET_EVENT_MISC_USER_FUNCTION (event, fn);
-      XSET_EVENT_MISC_USER_OBJECT (event, arg);
-      return;
-    }
-
   define_key_parser (list, &raw_key);
 
   /* The first zero is needed for Apple's i686-apple-darwin8-g++-4.0.1,
@@ -4672,7 +4649,6 @@
   DEFSYMBOL (Qmouse_##num);			\
   DEFSYMBOL (Qdown_mouse_##num);
 #include "keymap-buttons.h"
-  DEFSYMBOL (Qmenu_selection);
   DEFSYMBOL (QLFD);
   DEFSYMBOL (QTAB);
   DEFSYMBOL (QRET);
--- a/src/keymap.h	Tue Jun 25 15:31:58 2013 -0600
+++ b/src/keymap.h	Wed Jul 10 14:14:30 2013 +0100
@@ -56,8 +56,7 @@
 			Lisp_Object shadow, Lisp_Object prefix,
 			int mice_only_p, Lisp_Object buffer);
 
-void key_desc_list_to_event (Lisp_Object list, Lisp_Object event,
-			     int allow_menu_events);
+void key_desc_list_to_event (Lisp_Object list, Lisp_Object event);
 
 int event_matches_key_specifier_p (Lisp_Object event,
 				   Lisp_Object key_specifier);