diff options
| author | Jim Blandy | 1991-12-20 07:15:37 +0000 |
|---|---|---|
| committer | Jim Blandy | 1991-12-20 07:15:37 +0000 |
| commit | cc0a8174baf4c25d69545fe5cd6cabddba6b1d2c (patch) | |
| tree | 571d3cff4372149149e4ddd84e484f97e3ab846f /src/keymap.c | |
| parent | 6367dc09a13bb1944db02f9f76ab25e4ccb159d6 (diff) | |
| download | emacs-cc0a8174baf4c25d69545fe5cd6cabddba6b1d2c.tar.gz emacs-cc0a8174baf4c25d69545fe5cd6cabddba6b1d2c.zip | |
*** empty log message ***
Diffstat (limited to 'src/keymap.c')
| -rw-r--r-- | src/keymap.c | 199 |
1 files changed, 182 insertions, 17 deletions
diff --git a/src/keymap.c b/src/keymap.c index 344b600a6be..d55c369356d 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -64,6 +64,9 @@ Lisp_Object Vminibuffer_local_completion_map; | |||
| 64 | /* was MinibufLocalMustMatchMap */ | 64 | /* was MinibufLocalMustMatchMap */ |
| 65 | Lisp_Object Vminibuffer_local_must_match_map; | 65 | Lisp_Object Vminibuffer_local_must_match_map; |
| 66 | 66 | ||
| 67 | /* Alist of minor mode variables and keymaps. */ | ||
| 68 | Lisp_Object Vminor_mode_map_alist; | ||
| 69 | |||
| 67 | Lisp_Object Qkeymapp, Qkeymap; | 70 | Lisp_Object Qkeymapp, Qkeymap; |
| 68 | 71 | ||
| 69 | /* A char over 0200 in a key sequence | 72 | /* A char over 0200 in a key sequence |
| @@ -77,6 +80,8 @@ static void describe_command (); | |||
| 77 | static void describe_map (); | 80 | static void describe_map (); |
| 78 | static void describe_alist (); | 81 | static void describe_alist (); |
| 79 | 82 | ||
| 83 | /* Keymap object support - constructors and predicates. */ | ||
| 84 | |||
| 80 | DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 0, 0, | 85 | DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 0, 0, |
| 81 | "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\ | 86 | "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\ |
| 82 | VECTOR is a 128-element vector which holds the bindings for the ASCII\n\ | 87 | VECTOR is a 128-element vector which holds the bindings for the ASCII\n\ |
| @@ -173,7 +178,8 @@ get_keymap_1 (object, error) | |||
| 173 | return tem; | 178 | return tem; |
| 174 | if (error) | 179 | if (error) |
| 175 | wrong_type_argument (Qkeymapp, object); | 180 | wrong_type_argument (Qkeymapp, object); |
| 176 | else return Qnil; | 181 | else |
| 182 | return Qnil; | ||
| 177 | } | 183 | } |
| 178 | 184 | ||
| 179 | Lisp_Object | 185 | Lisp_Object |
| @@ -387,6 +393,8 @@ is not copied.") | |||
| 387 | return copy; | 393 | return copy; |
| 388 | } | 394 | } |
| 389 | 395 | ||
| 396 | /* Simple Keymap mutators and accessors. */ | ||
| 397 | |||
| 390 | DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, | 398 | DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, |
| 391 | "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\ | 399 | "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\ |
| 392 | KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\ | 400 | KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\ |
| @@ -558,6 +566,75 @@ append_key (key_sequence, key) | |||
| 558 | } | 566 | } |
| 559 | 567 | ||
| 560 | 568 | ||
| 569 | /* Global, local, and minor mode keymap stuff. */ | ||
| 570 | |||
| 571 | /* Store a pointer to an array of the keymaps of the currently active | ||
| 572 | minor modes in *buf, and return the number of maps it contains. | ||
| 573 | |||
| 574 | This function always returns a pointer to the same buffer, and may | ||
| 575 | free or reallocate it, so if you want to keep it for a long time or | ||
| 576 | hand it out to lisp code, copy it. This procedure will be called | ||
| 577 | for every key sequence read, so the nice lispy approach (return a | ||
| 578 | new assoclist, list, what have you) for each invocation would | ||
| 579 | result in a lot of consing over time. | ||
| 580 | |||
| 581 | If we used xrealloc/xmalloc and ran out of memory, they would throw | ||
| 582 | back to the command loop, which would try to read a key sequence, | ||
| 583 | which would call this function again, resulting in an infinite | ||
| 584 | loop. Instead, we'll use realloc/malloc and silently truncate the | ||
| 585 | list, let the key sequence be read, and hope some other piece of | ||
| 586 | code signals the error. */ | ||
| 587 | int | ||
| 588 | current_minor_maps (modeptr, mapptr) | ||
| 589 | Lisp_Object **modeptr, **mapptr; | ||
| 590 | { | ||
| 591 | static Lisp_Object *modes, *maps; | ||
| 592 | static int size; | ||
| 593 | |||
| 594 | int i = 0; | ||
| 595 | Lisp_Object alist, assoc, var; | ||
| 596 | |||
| 597 | for (alist = Vminor_mode_map_alist; | ||
| 598 | CONSP (alist); | ||
| 599 | alist = XCONS (alist)->cdr) | ||
| 600 | if (CONSP (assoc = XCONS (alist)->car) | ||
| 601 | && XTYPE (var = XCONS (assoc)->car) == Lisp_Symbol | ||
| 602 | && ! NULL (Fboundp (var)) | ||
| 603 | && ! NULL (Fsymbol_value (var))) | ||
| 604 | { | ||
| 605 | if (i >= size) | ||
| 606 | { | ||
| 607 | Lisp_Object *newmodes, *newmaps; | ||
| 608 | |||
| 609 | if (maps) | ||
| 610 | { | ||
| 611 | newmodes = (Lisp_Object *) realloc (modes, size *= 2); | ||
| 612 | newmaps = (Lisp_Object *) realloc (maps, size); | ||
| 613 | } | ||
| 614 | else | ||
| 615 | { | ||
| 616 | newmodes = (Lisp_Object *) malloc (size = 30); | ||
| 617 | newmaps = (Lisp_Object *) malloc (size); | ||
| 618 | } | ||
| 619 | |||
| 620 | if (newmaps && newmodes) | ||
| 621 | { | ||
| 622 | modes = newmodes; | ||
| 623 | maps = newmaps; | ||
| 624 | } | ||
| 625 | else | ||
| 626 | break; | ||
| 627 | } | ||
| 628 | modes[i] = var; | ||
| 629 | maps [i] = XCONS (assoc)->cdr; | ||
| 630 | i++; | ||
| 631 | } | ||
| 632 | |||
| 633 | if (modeptr) *modeptr = modes; | ||
| 634 | if (mapptr) *mapptr = maps; | ||
| 635 | return i; | ||
| 636 | } | ||
| 637 | |||
| 561 | DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 1, 0, | 638 | DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 1, 0, |
| 562 | "Return the binding for command KEY in current keymaps.\n\ | 639 | "Return the binding for command KEY in current keymaps.\n\ |
| 563 | KEY is a string, a sequence of keystrokes.\n\ | 640 | KEY is a string, a sequence of keystrokes.\n\ |
| @@ -565,22 +642,30 @@ The binding is probably a symbol with a function definition.") | |||
| 565 | (key) | 642 | (key) |
| 566 | Lisp_Object key; | 643 | Lisp_Object key; |
| 567 | { | 644 | { |
| 568 | register Lisp_Object map, value, value1; | 645 | Lisp_Object *maps, value; |
| 569 | map = current_buffer->keymap; | 646 | int nmaps, i; |
| 570 | if (!NULL (map)) | 647 | |
| 648 | nmaps = current_minor_maps (0, &maps); | ||
| 649 | for (i = 0; i < nmaps; i++) | ||
| 650 | if (! NULL (maps[i])) | ||
| 651 | { | ||
| 652 | value = Flookup_key (maps[i], key); | ||
| 653 | if (! NULL (value) && XTYPE (value) != Lisp_Int) | ||
| 654 | return value; | ||
| 655 | } | ||
| 656 | |||
| 657 | if (! NULL (current_buffer->keymap)) | ||
| 571 | { | 658 | { |
| 572 | value = Flookup_key (map, key); | 659 | value = Flookup_key (current_buffer->keymap, key); |
| 573 | if (NULL (value)) | 660 | if (! NULL (value) && XTYPE (value) != Lisp_Int) |
| 574 | { | ||
| 575 | value1 = Flookup_key (current_global_map, key); | ||
| 576 | if (XTYPE (value1) == Lisp_Int) | ||
| 577 | return Qnil; | ||
| 578 | return value1; | ||
| 579 | } | ||
| 580 | else if (XTYPE (value) != Lisp_Int) | ||
| 581 | return value; | 661 | return value; |
| 582 | } | 662 | } |
| 583 | return Flookup_key (current_global_map, key); | 663 | |
| 664 | value = Flookup_key (current_global_map, key); | ||
| 665 | if (! NULL (value) && XTYPE (value) != Lisp_Int) | ||
| 666 | return value; | ||
| 667 | |||
| 668 | return Qnil; | ||
| 584 | } | 669 | } |
| 585 | 670 | ||
| 586 | DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 1, 0, | 671 | DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 1, 0, |
| @@ -607,6 +692,38 @@ The binding is probably a symbol with a function definition.") | |||
| 607 | return Flookup_key (current_global_map, keys); | 692 | return Flookup_key (current_global_map, keys); |
| 608 | } | 693 | } |
| 609 | 694 | ||
| 695 | DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 1, 0, | ||
| 696 | "Find the visible minor mode bindings of KEY.\n\ | ||
| 697 | Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\ | ||
| 698 | the symbol which names the minor mode binding KEY, and BINDING is\n\ | ||
| 699 | KEY's definition in that mode. In particular, if KEY has no\n\ | ||
| 700 | minor-mode bindings, return nil. If the first binding is a\n\ | ||
| 701 | non-prefix, all subsequent bindings will be omitted, since they would\n\ | ||
| 702 | be ignored. Similarly, the list doesn't include non-prefix bindings\n\ | ||
| 703 | that come after prefix bindings.") | ||
| 704 | (key) | ||
| 705 | { | ||
| 706 | Lisp_Object *modes, *maps; | ||
| 707 | int nmaps; | ||
| 708 | Lisp_Object binding; | ||
| 709 | int i, j; | ||
| 710 | |||
| 711 | nmaps = current_minor_maps (&modes, &maps); | ||
| 712 | |||
| 713 | for (i = j = 0; i < nmaps; i++) | ||
| 714 | if (! NULL (maps[i]) | ||
| 715 | && ! NULL (binding = Flookup_key (maps[i], key)) | ||
| 716 | && XTYPE (binding) != Lisp_Int) | ||
| 717 | { | ||
| 718 | if (! NULL (get_keymap_1 (binding, 0))) | ||
| 719 | maps[j++] = Fcons (modes[i], binding); | ||
| 720 | else if (j == 0) | ||
| 721 | return Fcons (Fcons (modes[i], binding), Qnil); | ||
| 722 | } | ||
| 723 | |||
| 724 | return Flist (j, maps); | ||
| 725 | } | ||
| 726 | |||
| 610 | DEFUN ("global-set-key", Fglobal_set_key, Sglobal_set_key, 2, 2, | 727 | DEFUN ("global-set-key", Fglobal_set_key, Sglobal_set_key, 2, 2, |
| 611 | "kSet key globally: \nCSet key %s to command: ", | 728 | "kSet key globally: \nCSet key %s to command: ", |
| 612 | "Give KEY a global binding as COMMAND.\n\ | 729 | "Give KEY a global binding as COMMAND.\n\ |
| @@ -729,7 +846,19 @@ DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0, | |||
| 729 | { | 846 | { |
| 730 | return current_global_map; | 847 | return current_global_map; |
| 731 | } | 848 | } |
| 849 | |||
| 850 | DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps, Scurrent_minor_mode_maps, 0, 0, 0, | ||
| 851 | "Return a list of keymaps for the minor modes of the current buffer.") | ||
| 852 | () | ||
| 853 | { | ||
| 854 | Lisp_Object *maps; | ||
| 855 | int nmaps = current_minor_maps (0, &maps); | ||
| 856 | |||
| 857 | return Flist (nmaps, maps); | ||
| 858 | } | ||
| 732 | 859 | ||
| 860 | /* Help functions for describing and documenting keymaps. */ | ||
| 861 | |||
| 733 | DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, | 862 | DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, |
| 734 | 1, 1, 0, | 863 | 1, 1, 0, |
| 735 | "Find all keymaps accessible via prefix characters from KEYMAP.\n\ | 864 | "Find all keymaps accessible via prefix characters from KEYMAP.\n\ |
| @@ -1021,6 +1150,8 @@ Control characters turn into \"^char\", etc.") | |||
| 1021 | return build_string (tem); | 1150 | return build_string (tem); |
| 1022 | } | 1151 | } |
| 1023 | 1152 | ||
| 1153 | /* where-is - finding a command in a set of keymaps. */ | ||
| 1154 | |||
| 1024 | DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, | 1155 | DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, |
| 1025 | "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\ | 1156 | "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\ |
| 1026 | If KEYMAP is nil, search only KEYMAP1.\n\ | 1157 | If KEYMAP is nil, search only KEYMAP1.\n\ |
| @@ -1212,6 +1343,8 @@ Argument is a command definition, usually a symbol with a function definition.") | |||
| 1212 | return Qnil; | 1343 | return Qnil; |
| 1213 | } | 1344 | } |
| 1214 | 1345 | ||
| 1346 | /* describe-bindings - summarizing all the bindings in a set of keymaps. */ | ||
| 1347 | |||
| 1215 | DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "", | 1348 | DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "", |
| 1216 | "Show a list of all defined keys, and their definitions.\n\ | 1349 | "Show a list of all defined keys, and their definitions.\n\ |
| 1217 | The list is put in a buffer, which is displayed.") | 1350 | The list is put in a buffer, which is displayed.") |
| @@ -1236,19 +1369,41 @@ describe_buffer_bindings (descbuf) | |||
| 1236 | 1369 | ||
| 1237 | Fset_buffer (Vstandard_output); | 1370 | Fset_buffer (Vstandard_output); |
| 1238 | 1371 | ||
| 1372 | { | ||
| 1373 | int i, nmaps; | ||
| 1374 | Lisp_Object *modes, *maps; | ||
| 1375 | |||
| 1376 | nmaps = current_minor_maps (&modes, &maps); | ||
| 1377 | for (i = 0; i < nmaps; i++) | ||
| 1378 | { | ||
| 1379 | if (XTYPE (modes[i]) == Lisp_Symbol) | ||
| 1380 | { | ||
| 1381 | insert_char ('`'); | ||
| 1382 | insert_string (XSYMBOL (modes[i])->name->data); | ||
| 1383 | insert_char ('\''); | ||
| 1384 | } | ||
| 1385 | else | ||
| 1386 | insert_string ("Strangely Named"); | ||
| 1387 | insert_string (" Minor Mode Bindings:\n"); | ||
| 1388 | insert_string (heading); | ||
| 1389 | describe_map_tree (maps[i], 0, Qnil); | ||
| 1390 | insert_char ('\n'); | ||
| 1391 | } | ||
| 1392 | } | ||
| 1393 | |||
| 1239 | start1 = XBUFFER (descbuf)->keymap; | 1394 | start1 = XBUFFER (descbuf)->keymap; |
| 1240 | if (!NULL (start1)) | 1395 | if (!NULL (start1)) |
| 1241 | { | 1396 | { |
| 1242 | insert_string ("Local Bindings:\n"); | 1397 | insert_string ("Local Bindings:\n"); |
| 1243 | insert_string (heading); | 1398 | insert_string (heading); |
| 1244 | describe_map_tree (start1, 0, Qnil, Qnil); | 1399 | describe_map_tree (start1, 0, Qnil); |
| 1245 | insert_string ("\n"); | 1400 | insert_string ("\n"); |
| 1246 | } | 1401 | } |
| 1247 | 1402 | ||
| 1248 | insert_string ("Global Bindings:\n"); | 1403 | insert_string ("Global Bindings:\n"); |
| 1249 | insert_string (heading); | 1404 | insert_string (heading); |
| 1250 | 1405 | ||
| 1251 | describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap, Qnil); | 1406 | describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap); |
| 1252 | 1407 | ||
| 1253 | Fset_buffer (descbuf); | 1408 | Fset_buffer (descbuf); |
| 1254 | return Qnil; | 1409 | return Qnil; |
| @@ -1563,7 +1718,7 @@ describe_vector (vector, elt_prefix, elt_describer, partial, shadow) | |||
| 1563 | UNGCPRO; | 1718 | UNGCPRO; |
| 1564 | } | 1719 | } |
| 1565 | 1720 | ||
| 1566 | /* Apropos */ | 1721 | /* Apropos - finding all symbols whose names match a regexp. */ |
| 1567 | Lisp_Object apropos_predicate; | 1722 | Lisp_Object apropos_predicate; |
| 1568 | Lisp_Object apropos_accumulate; | 1723 | Lisp_Object apropos_accumulate; |
| 1569 | 1724 | ||
| @@ -1639,6 +1794,14 @@ syms_of_keymap () | |||
| 1639 | 1794 | ||
| 1640 | current_global_map = global_map; | 1795 | current_global_map = global_map; |
| 1641 | 1796 | ||
| 1797 | DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, | ||
| 1798 | "Alist of keymaps to use for minor modes.\n\ | ||
| 1799 | Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\ | ||
| 1800 | key sequences and look up bindings iff VARIABLE's value is non-nil.\n\ | ||
| 1801 | If two active keymaps bind the same key, the keymap appearing earlier\n\ | ||
| 1802 | in the list takes precedence."); | ||
| 1803 | Vminor_mode_map_alist = Qnil; | ||
| 1804 | |||
| 1642 | Qsingle_key_description = intern ("single-key-description"); | 1805 | Qsingle_key_description = intern ("single-key-description"); |
| 1643 | staticpro (&Qsingle_key_description); | 1806 | staticpro (&Qsingle_key_description); |
| 1644 | 1807 | ||
| @@ -1655,6 +1818,7 @@ syms_of_keymap () | |||
| 1655 | defsubr (&Skey_binding); | 1818 | defsubr (&Skey_binding); |
| 1656 | defsubr (&Slocal_key_binding); | 1819 | defsubr (&Slocal_key_binding); |
| 1657 | defsubr (&Sglobal_key_binding); | 1820 | defsubr (&Sglobal_key_binding); |
| 1821 | defsubr (&Sminor_mode_key_binding); | ||
| 1658 | defsubr (&Sglobal_set_key); | 1822 | defsubr (&Sglobal_set_key); |
| 1659 | defsubr (&Slocal_set_key); | 1823 | defsubr (&Slocal_set_key); |
| 1660 | defsubr (&Sdefine_key); | 1824 | defsubr (&Sdefine_key); |
| @@ -1666,6 +1830,7 @@ syms_of_keymap () | |||
| 1666 | defsubr (&Suse_local_map); | 1830 | defsubr (&Suse_local_map); |
| 1667 | defsubr (&Scurrent_local_map); | 1831 | defsubr (&Scurrent_local_map); |
| 1668 | defsubr (&Scurrent_global_map); | 1832 | defsubr (&Scurrent_global_map); |
| 1833 | defsubr (&Scurrent_minor_mode_maps); | ||
| 1669 | defsubr (&Saccessible_keymaps); | 1834 | defsubr (&Saccessible_keymaps); |
| 1670 | defsubr (&Skey_description); | 1835 | defsubr (&Skey_description); |
| 1671 | defsubr (&Sdescribe_vector); | 1836 | defsubr (&Sdescribe_vector); |