From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#50752: 28.0.50; easy-menu-define lowers the menu-bar key Date: Wed, 13 Oct 2021 14:59:03 +0300 Message-ID: <837dehp248.fsf@gnu.org> References: <87bl4jvudm.fsf@gnus.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2994"; mail-complaints-to="usenet@ciao.gmane.io" Cc: shuguang79@qq.com, larsi@gnus.org, 50752@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 13 14:00:24 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1macvn-0000Zb-Gl for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Oct 2021 14:00:23 +0200 Original-Received: from localhost ([::1]:57104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1macvm-0001NP-Da for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Oct 2021 08:00:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1macvU-0001Mi-F9 for bug-gnu-emacs@gnu.org; Wed, 13 Oct 2021 08:00:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1macvU-0007Jk-4Y for bug-gnu-emacs@gnu.org; Wed, 13 Oct 2021 08:00:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1macvT-00077Q-2u for bug-gnu-emacs@gnu.org; Wed, 13 Oct 2021 08:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Oct 2021 12:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50752 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50752-submit@debbugs.gnu.org id=B50752.163412636027261 (code B ref 50752); Wed, 13 Oct 2021 12:00:03 +0000 Original-Received: (at 50752) by debbugs.gnu.org; 13 Oct 2021 11:59:20 +0000 Original-Received: from localhost ([127.0.0.1]:58749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1macum-00075c-8B for submit@debbugs.gnu.org; Wed, 13 Oct 2021 07:59:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:33848) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1macuj-00075O-3c for 50752@debbugs.gnu.org; Wed, 13 Oct 2021 07:59:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:55426) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1macub-0005Zh-8S; Wed, 13 Oct 2021 07:59:09 -0400 Original-Received: from [87.69.77.57] (port=1473 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1macua-0005Dk-Ls; Wed, 13 Oct 2021 07:59:09 -0400 In-Reply-To: (message from Stefan Kangas on Tue, 12 Oct 2021 15:22:59 -0700) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:217108 Archived-At: > From: Stefan Kangas > Date: Tue, 12 Oct 2021 15:22:59 -0700 > Cc: Shuguang Sun , 50752@debbugs.gnu.org > > + for (int i = 0; i < key_len; i++) > + { > + Lisp_Object lc_key = Fdowncase (Fsymbol_name (AREF (key, i))); > + ASET (new_key, i, Fintern (lc_key, Qnil)); > + } Beware: downcase uses the current buffer's case-table. Is that something we want here, or could it be undesirable in some cases? > + found = lookup_key_1 (keymap, new_key, accept_default); > + > + if (!NILP (found) && !NUMBERP (found)) > + goto end; > + > + /* If we still don't have a match, let's convert any spaces in > + our lowercased string into dashes, e.g. "foo bar baz" to > + "foo-bar-baz". */ > + for (int i = 0; i < key_len; i++) > + { > + Lisp_Object lc_key = Fdowncase (Fsymbol_name (AREF (key, i))); Can't we reuse the results of the original downcasing, instead of doing that again? > + USE_SAFE_ALLOCA; > + ptrdiff_t size = SCHARS (lc_key), n; > + if (INT_MULTIPLY_WRAPV (size, MAX_MULTIBYTE_LENGTH, &n)) > + n = PTRDIFF_MAX; > + unsigned char *dst = SAFE_ALLOCA (n); > + unsigned char *o = dst; > + ptrdiff_t j = 0, j_byte = 0, chars = 0; > + > + while (j < SCHARS (lc_key)) > + { > + int ch = fetch_string_char_advance (lc_key, &j, &j_byte); > + if (ch == ' ') > + *o = '-'; > + else > + *o = ch; > + chars++; This will only work with plain-ASCII characters in lc_key (but then you don't need fetch_string_char_advance, you can access the bytes one by one). You need to use CHAR_STRING instead. > + int len; > + string_char_and_length (o, &len); > + o += len; This is overhead. You already know the length of the multibyte string, because fetch_string_char_advance reports it back to you via j_byte. So just use that. > diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el > index 68b42c346c..8f3dff2acb 100644 > --- a/test/src/keymap-tests.el > +++ b/test/src/keymap-tests.el > @@ -124,6 +124,17 @@ keymap-lookup-key/too-long > ;; (ert-deftest keymap-lookup-key/accept-default () > ;; ...) > > +(ert-deftest keymap-lookup-key/mixed-case () > + (let ((map (make-keymap))) > + (define-key map [menu-bar foo bar] 'foo) > + (should (eq (lookup-key map [menu-bar foo bar]) 'foo)) > + (should (eq (lookup-key map [menu-bar Foo Bar]) 'foo)))) > + > +(ert-deftest subr-test-lookup-keymap/with-spaces () > + (let ((map (make-keymap))) > + (define-key map [menu-bar foo-bar] 'foo) > + (should (eq (lookup-key map [menu-bar Foo\ Bar]) 'foo)))) > + > (ert-deftest describe-buffer-bindings/header-in-current-buffer () > "Header should be inserted into the current buffer. > https://debbugs.gnu.org/39149#31" Please add tests where the symbols use non-ASCII characters. Also, what about the existing calls to Flookup_key from C: do they all need to go through the added processing, or could some of them be satisfied by calling lookup_key_1? This change needs a NEWS entry. Thanks.