aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorStefan Monnier2008-03-25 20:12:54 +0000
committerStefan Monnier2008-03-25 20:12:54 +0000
commit12270607dee03bbbbffad8a2416e55dc8bb38ecf (patch)
treec0401c94fd8d92a446d95794fb6f6df71ee99a7c /src/keymap.c
parenta10cca6c90b3366f3000b06ce1fa226277da0ea4 (diff)
downloademacs-12270607dee03bbbbffad8a2416e55dc8bb38ecf.tar.gz
emacs-12270607dee03bbbbffad8a2416e55dc8bb38ecf.zip
(map_keymap_internal): New fun.
(map_keymap): Use it. (Fmap_keymap_internal): New fun. (Fmap_keymap): Remove left-out test from before make_save_value.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c72
1 files changed, 49 insertions, 23 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 310b46b23bf..9ed1e92c84b 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -660,25 +660,20 @@ map_keymap_char_table_item (args, key, val)
660 } 660 }
661} 661}
662 662
663/* Call FUN for every binding in MAP. 663/* Call FUN for every binding in MAP and stop at (and return) the parent.
664 FUN is called with 4 arguments: FUN (KEY, BINDING, ARGS, DATA). 664 FUN is called with 4 arguments: FUN (KEY, BINDING, ARGS, DATA). */
665 AUTOLOAD if non-zero means that we can autoload keymaps if necessary. */ 665Lisp_Object
666void 666map_keymap_internal (Lisp_Object map,
667map_keymap (map, fun, args, data, autoload) 667 map_keymap_function_t fun,
668 map_keymap_function_t fun; 668 Lisp_Object args,
669 Lisp_Object map, args; 669 void *data)
670 void *data;
671 int autoload;
672{ 670{
673 struct gcpro gcpro1, gcpro2, gcpro3; 671 struct gcpro gcpro1, gcpro2, gcpro3;
674 Lisp_Object tail; 672 Lisp_Object tail
673 = (CONSP (map) && EQ (Qkeymap, XCAR (map))) ? XCDR (map) : map;
675 674
676 tail = Qnil;
677 GCPRO3 (map, args, tail); 675 GCPRO3 (map, args, tail);
678 map = get_keymap (map, 1, autoload); 676 for (; CONSP (tail) && !EQ (Qkeymap, XCAR (tail)); tail = XCDR (tail))
679 for (tail = (CONSP (map) && EQ (Qkeymap, XCAR (map))) ? XCDR (map) : map;
680 CONSP (tail) || (tail = get_keymap (tail, 0, autoload), CONSP (tail));
681 tail = XCDR (tail))
682 { 677 {
683 Lisp_Object binding = XCAR (tail); 678 Lisp_Object binding = XCAR (tail);
684 679
@@ -705,6 +700,7 @@ map_keymap (map, fun, args, data, autoload)
705 } 700 }
706 } 701 }
707 UNGCPRO; 702 UNGCPRO;
703 return tail;
708} 704}
709 705
710static void 706static void
@@ -715,13 +711,46 @@ map_keymap_call (key, val, fun, dummy)
715 call2 (fun, key, val); 711 call2 (fun, key, val);
716} 712}
717 713
714/* Same as map_keymap_internal, but doesn't traverses parent keymaps as well.
715 A non-zero AUTOLOAD indicates that autoloaded keymaps should be loaded. */
716void
717map_keymap (map, fun, args, data, autoload)
718 map_keymap_function_t fun;
719 Lisp_Object map, args;
720 void *data;
721 int autoload;
722{
723 struct gcpro gcpro1;
724 GCPRO1 (args);
725 map = get_keymap (map, 1, autoload);
726 while (CONSP (map))
727 {
728 map = map_keymap_internal (map, fun, args, data);
729 map = get_keymap (map, 0, autoload);
730 }
731 UNGCPRO;
732}
733
734DEFUN ("map-keymap-internal", Fmap_keymap_internal, Smap_keymap_internal, 2, 2, 0,
735 doc: /* Call FUNCTION once for each event binding in KEYMAP.
736FUNCTION is called with two arguments: the event that is bound, and
737the definition it is bound to. The event may be a character range.
738If KEYMAP has a parent, this function returns it without processing it. */)
739 (function, keymap)
740 Lisp_Object function, keymap;
741{
742 struct gcpro gcpro1;
743 GCPRO1 (function);
744 keymap = get_keymap (keymap, 1, 1);
745 keymap = map_keymap_internal (keymap, map_keymap_call, function, NULL);
746 UNGCPRO;
747 return keymap;
748}
749
718DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 3, 0, 750DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 3, 0,
719 doc: /* Call FUNCTION once for each event binding in KEYMAP. 751 doc: /* Call FUNCTION once for each event binding in KEYMAP.
720FUNCTION is called with two arguments: the event that is bound, and 752FUNCTION is called with two arguments: the event that is bound, and
721the definition it is bound to. If the event is an integer, it may be 753the definition it is bound to. The event may be a character range.
722a generic character (see Info node `(elisp)Splitting Characters'), and
723that means that all actual character events belonging to that generic
724character are bound to the definition.
725 754
726If KEYMAP has a parent, the parent's bindings are included as well. 755If KEYMAP has a parent, the parent's bindings are included as well.
727This works recursively: if the parent has itself a parent, then the 756This works recursively: if the parent has itself a parent, then the
@@ -730,10 +759,6 @@ usage: (map-keymap FUNCTION KEYMAP) */)
730 (function, keymap, sort_first) 759 (function, keymap, sort_first)
731 Lisp_Object function, keymap, sort_first; 760 Lisp_Object function, keymap, sort_first;
732{ 761{
733 if (INTEGERP (function))
734 /* We have to stop integers early since map_keymap gives them special
735 significance. */
736 xsignal1 (Qinvalid_function, function);
737 if (! NILP (sort_first)) 762 if (! NILP (sort_first))
738 return call2 (intern ("map-keymap-sorted"), function, keymap); 763 return call2 (intern ("map-keymap-sorted"), function, keymap);
739 764
@@ -3967,6 +3992,7 @@ the same way. The "active" keymaps in each alist are used before
3967 defsubr (&Sset_keymap_parent); 3992 defsubr (&Sset_keymap_parent);
3968 defsubr (&Smake_keymap); 3993 defsubr (&Smake_keymap);
3969 defsubr (&Smake_sparse_keymap); 3994 defsubr (&Smake_sparse_keymap);
3995 defsubr (&Smap_keymap_internal);
3970 defsubr (&Smap_keymap); 3996 defsubr (&Smap_keymap);
3971 defsubr (&Scopy_keymap); 3997 defsubr (&Scopy_keymap);
3972 defsubr (&Scommand_remapping); 3998 defsubr (&Scommand_remapping);