changeset 4849:5ebf3eec091b

(read_key_sequence): Allow function in key-translation-map just as in function-key-map. (read_key_sequence): Allow function-key-map to have a function as the binding; call the function and use its value.
author Richard M. Stallman <rms@gnu.org>
date Wed, 13 Oct 1993 06:01:49 +0000
parents 511c83aee4ae
children 9cd4c610fa62
files src/keyboard.c
diffstat 1 files changed, 45 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/keyboard.c	Wed Oct 13 05:59:54 1993 +0000
+++ b/src/keyboard.c	Wed Oct 13 06:01:49 1993 +0000
@@ -4241,6 +4241,27 @@
 	      fkey_next
 		= get_keyelt (access_keymap (fkey_next, key, 1, 0));
 
+	      /* If the function key map gives a function, not an
+		 array, then call the function with no args and use
+		 its value instead.  */
+	      if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next))
+		  && fkey_end == t)
+		{
+		  struct gcpro gcpro1, gcpro2, gcpro3;
+		  Lisp_Object tem;
+		  tem = fkey_next;
+
+		  GCPRO3 (fkey_map, keytran_map, delayed_switch_frame);
+		  fkey_next = call0 (fkey_next);
+		  UNGCPRO;
+		  /* If the function returned something invalid,
+		     barf--don't ignore it.
+		     (To ignore it safely, we would need to gcpro a bunch of 
+		     other variables.)  */
+		  if (! (VECTORP (fkey_next) || STRINGP (fkey_next)))
+		    error ("Function in function-key-map returns invalid key sequence");
+		}
+
 	      /* If keybuf[fkey_start..fkey_end] is bound in the
 		 function key map and it's a suffix of the current
 		 sequence (i.e. fkey_end == t), replace it with
@@ -4263,8 +4284,8 @@
 		      int i;
 
 		      for (i = 0; i < len; i++)
-			XFASTINT (keybuf[fkey_start + i]) =
-			  XSTRING (fkey_next)->data[i];
+			XFASTINT (keybuf[fkey_start + i])
+			  = XSTRING (fkey_next)->data[i];
 		    }
 		  
 		  mock_input = t;
@@ -4313,8 +4334,29 @@
 	    keytran_next
 	      = get_keyelt (access_keymap (keytran_next, key, 1, 0));
 
+	    /* If the key translation map gives a function, not an
+	       array, then call the function with no args and use
+	       its value instead.  */
+	    if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))
+		&& keytran_end == t)
+	      {
+		struct gcpro gcpro1, gcpro2, gcpro3;
+		Lisp_Object tem;
+		tem = keytran_next;
+
+		GCPRO3 (keytran_map, keytran_map, delayed_switch_frame);
+		keytran_next = call0 (keytran_next);
+		UNGCPRO;
+		/* If the function returned something invalid,
+		   barf--don't ignore it.
+		   (To ignore it safely, we would need to gcpro a bunch of 
+		   other variables.)  */
+		if (! (VECTORP (keytran_next) || STRINGP (keytran_next)))
+		  error ("Function in function-key-map returns invalid key sequence");
+	      }
+
 	    /* If keybuf[keytran_start..keytran_end] is bound in the
-	       function key map and it's a suffix of the current
+	       key translation map and it's a suffix of the current
 	       sequence (i.e. keytran_end == t), replace it with
 	       the binding and restart with keytran_start at the end. */
 	    if ((VECTORP (keytran_next) || STRINGP (keytran_next))