From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: bug/feature - emacs doesn't tell you about keys with multiple prefixes Date: Mon, 17 Mar 2003 11:35:28 -0500 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200303171635.h2HGZSJw013765@rum.cs.yale.edu> References: <15932.56789.564317.739477@hkn.eecs.berkeley.edu> <200303161014.h2GAE90Q009917@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1047919015 11077 80.91.224.249 (17 Mar 2003 16:36:55 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 17 Mar 2003 16:36:55 +0000 (UTC) Cc: Stefan Monnier Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Mar 17 17:36:52 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18uxbY-0002sE-00 for ; Mon, 17 Mar 2003 17:36:52 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18uy1H-0002D5-00 for ; Mon, 17 Mar 2003 18:03:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18uxbv-0006lf-07 for emacs-devel@quimby.gnus.org; Mon, 17 Mar 2003 11:37:15 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18uxay-0006EJ-00 for emacs-devel@gnu.org; Mon, 17 Mar 2003 11:36:16 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18uxas-00068D-00 for emacs-devel@gnu.org; Mon, 17 Mar 2003 11:36:11 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18uxaH-0005kO-00; Mon, 17 Mar 2003 11:35:33 -0500 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h2HGZTPe013767; Mon, 17 Mar 2003 11:35:29 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h2HGZSJw013765; Mon, 17 Mar 2003 11:35:28 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Richard Stallman Original-cc: quarl@hkn.eecs.berkeley.edu Original-cc: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12408 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12408 > In accessible-keymaps (used by where-is-internal), there is an explicit check > to remove any duplicate keymaps (i.e. the same keymap appearing under another > prefix). > > I don't remember the reason for this. Perhaps the idea was that it is > supposed to tell you all the keymaps, not all the prefixes. > Preventing cycles is also necessary. > > There could be an optional 3rd arg ALLOW-DUPLICATES which, if non-nil, > means that it only rejects actual cycles (where the prefix already > recorded for the same keymap is an initial segment of the new prefix). Grepping through Emacs' code I discovered that accessible-keymap is never called from elisp and that it's only ever called from where-is-internal, so I think we can safely change its behavior without adding a new argument. How about the patch below ? Stefan Index: src/keymap.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keymap.c,v retrieving revision 1.277 diff -c -b -r1.277 keymap.c *** src/keymap.c 16 Mar 2003 00:06:59 -0000 1.277 --- src/keymap.c 17 Mar 2003 16:32:29 -0000 *************** *** 1659,1676 **** { Lisp_Object tem; ! cmd = get_keyelt (cmd, 0); if (NILP (cmd)) return; ! tem = get_keymap (cmd, 0, 0); ! if (CONSP (tem)) ! { ! cmd = tem; ! /* Ignore keymaps that are already added to maps. */ ! tem = Frassq (cmd, maps); ! if (NILP (tem)) { /* If the last key in thisseq is meta-prefix-char, turn it into a meta-ized keystroke. We know that the event we're about to append is an --- 1659,1689 ---- { Lisp_Object tem; ! cmd = get_keymap (get_keyelt (cmd, 0), 0, 0); if (NILP (cmd)) return; ! /* Look for and break cycles. */ ! while (!NILP (tem = Frassq (cmd, maps))) { + Lisp_Object prefix = XCAR (tem); + int lim = XINT (Flength (XCAR (tem))); + if (lim <= XINT (Flength (thisseq))) + { /* This keymap was already seen with a smaller prefix. */ + int i = 0; + while (i < lim && EQ (Faref (prefix, make_number (i)), + Faref (thisseq, make_number (i)))) + i++; + if (i >= lim) + /* `prefix' is a prefix of `thisseq' => there's a cycle. */ + return; + } + /* This occurrence of `cmd' in `maps' does not correspond to a cycle, + but maybe `cmd' occurs again further down in `maps', so keep + looking. */ + maps = XCDR (Fmemq (tem, maps)); + } + /* If the last key in thisseq is meta-prefix-char, turn it into a meta-ized keystroke. We know that the event we're about to append is an *************** *** 1694,1701 **** { tem = append_key (thisseq, key); nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); - } - } } } --- 1707,1712 ----