diff options
| author | Stefan Monnier | 2003-03-18 19:34:31 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-03-18 19:34:31 +0000 |
| commit | 73a4675c84917e2829000188125a57357df1cff1 (patch) | |
| tree | 694d46d12770eaa1d493330dcef5cde006d8c8ce /src/keymap.c | |
| parent | 19536747baeb7cf048302f53f2800ee788161594 (diff) | |
| download | emacs-73a4675c84917e2829000188125a57357df1cff1.tar.gz emacs-73a4675c84917e2829000188125a57357df1cff1.zip | |
(accessible_keymaps_1): Break cycles but without preventing
multiple occurrences of the same keymap under different prefixes.
(Faccessible_keymaps): Remove code redundant since 1994-08-03T07:39:00Z!rms@gnu.org.
Diffstat (limited to 'src/keymap.c')
| -rw-r--r-- | src/keymap.c | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/src/keymap.c b/src/keymap.c index 4215ec5bd77..d92b386c4e7 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -1659,43 +1659,54 @@ accessible_keymaps_1 (key, cmd, maps, tail, thisseq, is_metized) | |||
| 1659 | { | 1659 | { |
| 1660 | Lisp_Object tem; | 1660 | Lisp_Object tem; |
| 1661 | 1661 | ||
| 1662 | cmd = get_keyelt (cmd, 0); | 1662 | cmd = get_keymap (get_keyelt (cmd, 0), 0, 0); |
| 1663 | if (NILP (cmd)) | 1663 | if (NILP (cmd)) |
| 1664 | return; | 1664 | return; |
| 1665 | 1665 | ||
| 1666 | tem = get_keymap (cmd, 0, 0); | 1666 | /* Look for and break cycles. */ |
| 1667 | if (CONSP (tem)) | 1667 | while (!NILP (tem = Frassq (cmd, maps))) |
| 1668 | { | 1668 | { |
| 1669 | cmd = tem; | 1669 | Lisp_Object prefix = XCAR (tem); |
| 1670 | /* Ignore keymaps that are already added to maps. */ | 1670 | int lim = XINT (Flength (XCAR (tem))); |
| 1671 | tem = Frassq (cmd, maps); | 1671 | if (lim <= XINT (Flength (thisseq))) |
| 1672 | if (NILP (tem)) | 1672 | { /* This keymap was already seen with a smaller prefix. */ |
| 1673 | { | 1673 | int i = 0; |
| 1674 | /* If the last key in thisseq is meta-prefix-char, | 1674 | while (i < lim && EQ (Faref (prefix, make_number (i)), |
| 1675 | turn it into a meta-ized keystroke. We know | 1675 | Faref (thisseq, make_number (i)))) |
| 1676 | that the event we're about to append is an | 1676 | i++; |
| 1677 | ascii keystroke since we're processing a | 1677 | if (i >= lim) |
| 1678 | keymap table. */ | 1678 | /* `prefix' is a prefix of `thisseq' => there's a cycle. */ |
| 1679 | if (is_metized) | 1679 | return; |
| 1680 | { | ||
| 1681 | int meta_bit = meta_modifier; | ||
| 1682 | Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | ||
| 1683 | tem = Fcopy_sequence (thisseq); | ||
| 1684 | |||
| 1685 | Faset (tem, last, make_number (XINT (key) | meta_bit)); | ||
| 1686 | |||
| 1687 | /* This new sequence is the same length as | ||
| 1688 | thisseq, so stick it in the list right | ||
| 1689 | after this one. */ | ||
| 1690 | XSETCDR (tail, | ||
| 1691 | Fcons (Fcons (tem, cmd), XCDR (tail))); | ||
| 1692 | } | ||
| 1693 | else | ||
| 1694 | { | ||
| 1695 | tem = append_key (thisseq, key); | ||
| 1696 | nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | ||
| 1697 | } | ||
| 1698 | } | 1680 | } |
| 1681 | /* This occurrence of `cmd' in `maps' does not correspond to a cycle, | ||
| 1682 | but maybe `cmd' occurs again further down in `maps', so keep | ||
| 1683 | looking. */ | ||
| 1684 | maps = XCDR (Fmemq (tem, maps)); | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | /* If the last key in thisseq is meta-prefix-char, | ||
| 1688 | turn it into a meta-ized keystroke. We know | ||
| 1689 | that the event we're about to append is an | ||
| 1690 | ascii keystroke since we're processing a | ||
| 1691 | keymap table. */ | ||
| 1692 | if (is_metized) | ||
| 1693 | { | ||
| 1694 | int meta_bit = meta_modifier; | ||
| 1695 | Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | ||
| 1696 | tem = Fcopy_sequence (thisseq); | ||
| 1697 | |||
| 1698 | Faset (tem, last, make_number (XINT (key) | meta_bit)); | ||
| 1699 | |||
| 1700 | /* This new sequence is the same length as | ||
| 1701 | thisseq, so stick it in the list right | ||
| 1702 | after this one. */ | ||
| 1703 | XSETCDR (tail, | ||
| 1704 | Fcons (Fcons (tem, cmd), XCDR (tail))); | ||
| 1705 | } | ||
| 1706 | else | ||
| 1707 | { | ||
| 1708 | tem = append_key (thisseq, key); | ||
| 1709 | nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | ||
| 1699 | } | 1710 | } |
| 1700 | } | 1711 | } |
| 1701 | 1712 | ||
| @@ -1829,35 +1840,7 @@ then the value includes only maps for prefixes that start with PREFIX. */) | |||
| 1829 | } | 1840 | } |
| 1830 | } | 1841 | } |
| 1831 | 1842 | ||
| 1832 | if (NILP (prefix)) | 1843 | return maps; |
| 1833 | return maps; | ||
| 1834 | |||
| 1835 | /* Now find just the maps whose access prefixes start with PREFIX. */ | ||
| 1836 | |||
| 1837 | good_maps = Qnil; | ||
| 1838 | for (; CONSP (maps); maps = XCDR (maps)) | ||
| 1839 | { | ||
| 1840 | Lisp_Object elt, thisseq; | ||
| 1841 | elt = XCAR (maps); | ||
| 1842 | thisseq = XCAR (elt); | ||
| 1843 | /* The access prefix must be at least as long as PREFIX, | ||
| 1844 | and the first elements must match those of PREFIX. */ | ||
| 1845 | if (XINT (Flength (thisseq)) >= prefixlen) | ||
| 1846 | { | ||
| 1847 | int i; | ||
| 1848 | for (i = 0; i < prefixlen; i++) | ||
| 1849 | { | ||
| 1850 | Lisp_Object i1; | ||
| 1851 | XSETFASTINT (i1, i); | ||
| 1852 | if (!EQ (Faref (thisseq, i1), Faref (prefix, i1))) | ||
| 1853 | break; | ||
| 1854 | } | ||
| 1855 | if (i == prefixlen) | ||
| 1856 | good_maps = Fcons (elt, good_maps); | ||
| 1857 | } | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | return Fnreverse (good_maps); | ||
| 1861 | } | 1844 | } |
| 1862 | 1845 | ||
| 1863 | Lisp_Object Qsingle_key_description, Qkey_description; | 1846 | Lisp_Object Qsingle_key_description, Qkey_description; |