aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorStefan Monnier2003-05-04 00:13:06 +0000
committerStefan Monnier2003-05-04 00:13:06 +0000
commit9d3153eb8706b7b0bd9cac77ac0e72a7bd6bb661 (patch)
treebb4bc7b0f13059f6b3cdfdf26513094aa1785e4e /src/keymap.c
parentb41ea33eef40b72a09c6277517931915ad134204 (diff)
downloademacs-9d3153eb8706b7b0bd9cac77ac0e72a7bd6bb661.tar.gz
emacs-9d3153eb8706b7b0bd9cac77ac0e72a7bd6bb661.zip
(map_keymap_item, map_keymap_char_table_item, map_keymap)
(map_keymap_call, Fmap_keymap): New functions. (syms_of_keymap): Defsubr map-keymap.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/keymap.c b/src/keymap.c
index d1fee120414..97884223d8d 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -640,6 +640,102 @@ access_keymap (map, idx, t_ok, noinherit, autoload)
640 } 640 }
641} 641}
642 642
643static void
644map_keymap_item (fun, args, key, val, data)
645 map_keymap_function_t fun;
646 Lisp_Object args, key, val;
647 void *data;
648{
649 /* We should maybe try to detect bindings shadowed by previous
650 ones and things like that. */
651 if (EQ (val, Qt))
652 val = Qnil;
653 (*fun) (key, val, args, data);
654}
655
656static void
657map_keymap_char_table_item (args, key, val)
658 Lisp_Object args, key, val;
659{
660 if (!NILP (val))
661 {
662 map_keymap_function_t fun = XSAVE_VALUE (XCAR (args))->pointer;
663 args = XCDR (args);
664 map_keymap_item (fun, XCDR (args), key, val,
665 XSAVE_VALUE (XCAR (args))->pointer);
666 }
667}
668
669/* Call FUN for every binding in MAP.
670 FUN is called with 4 arguments: FUN (KEY, BINDING, ARGS, DATA). */
671void
672map_keymap (map, fun, args, data, autoload)
673 map_keymap_function_t fun;
674 Lisp_Object map, args;
675 void *data;
676 int autoload;
677{
678 struct gcpro gcpro1, gcpro2, gcpro3;
679 Lisp_Object tail;
680
681 GCPRO3 (map, args, tail);
682 map = get_keymap (map, 1, autoload);
683 for (tail = (CONSP (map) && EQ (Qkeymap, XCAR (map))) ? XCDR (map) : map;
684 CONSP (tail) || (tail = get_keymap (tail, 0, autoload), CONSP (tail));
685 tail = XCDR (tail))
686 {
687 Lisp_Object binding = XCAR (tail);
688
689 if (CONSP (binding))
690 map_keymap_item (fun, args, XCAR (binding), XCDR (binding), data);
691 else if (VECTORP (binding))
692 {
693 /* Loop over the char values represented in the vector. */
694 int len = ASIZE (binding);
695 int c;
696 abort();
697 for (c = 0; c < len; c++)
698 {
699 Lisp_Object character;
700 XSETFASTINT (character, c);
701 map_keymap_item (fun, args, character, AREF (binding, c), data);
702 }
703 }
704 else if (CHAR_TABLE_P (binding))
705 {
706 Lisp_Object indices[3];
707 map_char_table (map_keymap_char_table_item, Qnil, binding,
708 Fcons (make_save_value (fun, 0),
709 Fcons (make_save_value (data, 0),
710 args)),
711 0, indices);
712 }
713 }
714 UNGCPRO;
715}
716
717static void
718map_keymap_call (key, val, fun, dummy)
719 Lisp_Object key, val, fun;
720 void *dummy;
721{
722 call2 (fun, key, val);
723}
724
725DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 2, 0,
726 doc: /* Call FUNCTION for every binding in KEYMAP.
727FUNCTION is called with two arguments: the event and its binding. */)
728 (function, keymap)
729 Lisp_Object function, keymap;
730{
731 if (INTEGERP (function))
732 /* We have to stop integers early since map_keymap gives them special
733 significance. */
734 Fsignal (Qinvalid_function, Fcons (function, Qnil));
735 map_keymap (keymap, map_keymap_call, function, NULL, 1);
736 return Qnil;
737}
738
643/* Given OBJECT which was found in a slot in a keymap, 739/* Given OBJECT which was found in a slot in a keymap,
644 trace indirect definitions to get the actual definition of that slot. 740 trace indirect definitions to get the actual definition of that slot.
645 An indirect definition is a list of the form 741 An indirect definition is a list of the form
@@ -3653,6 +3749,7 @@ and applies even for keys that have ordinary bindings. */);
3653 defsubr (&Sset_keymap_parent); 3749 defsubr (&Sset_keymap_parent);
3654 defsubr (&Smake_keymap); 3750 defsubr (&Smake_keymap);
3655 defsubr (&Smake_sparse_keymap); 3751 defsubr (&Smake_sparse_keymap);
3752 defsubr (&Smap_keymap);
3656 defsubr (&Scopy_keymap); 3753 defsubr (&Scopy_keymap);
3657 defsubr (&Scommand_remapping); 3754 defsubr (&Scommand_remapping);
3658 defsubr (&Skey_binding); 3755 defsubr (&Skey_binding);