From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: master f3aa648: Make `lookup-key' understand the new key sequence syntax Date: Tue, 19 Oct 2021 08:45:37 -0400 Message-ID: References: <20211019030801.23534.79581@vcs0.savannah.gnu.org> <20211019030802.83DE621120@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17384"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 19 14:48:25 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mcoXY-0004ME-9T for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Oct 2021 14:48:24 +0200 Original-Received: from localhost ([::1]:58366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcoXW-0000pG-RD for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Oct 2021 08:48:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcoV8-0006ym-8V for emacs-devel@gnu.org; Tue, 19 Oct 2021 08:45:54 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:21006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcoV3-0003Gi-Ev for emacs-devel@gnu.org; Tue, 19 Oct 2021 08:45:52 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D1F688065D; Tue, 19 Oct 2021 08:45:46 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 9022C80300; Tue, 19 Oct 2021 08:45:38 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1634647538; bh=A3n6eZ3TIbwNuzKD91ew8O3rUnVF3HBDaVnKbgQcwqA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=n31kTB5ywwGePv8FIrS4ioXYFcj2IiHSqCELYM+QLqD1YY/0Sn2Rl4fH8999oJgNZ 1Nug5t9ShLSpEsHf89c29Cxxp7VVWLVUCOtcgLJug7abZ9SMzc8hXE8SG8U2upj2dd 9HnhfmBlvZehmqNrRI5JSOqj6IzcZzcreTVALo/NtSE659zUKs0uJxNQ7DTPE2TMLM anJIOFILRdXBFwVvkUzrHMGft5pV38PvmXejDXvlgs8/Q7sxiSTIJd1FRRgGcdWT+H PW3vmbtX37LRGzEadS4xt+BqzUt/RztjZ0XSm4WyUqLJsYMyMVA2lh93vZBbZ3RBEt bzfbq9qlay9gA== Original-Received: from pastel (unknown [45.72.241.23]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 54ED2120340; Tue, 19 Oct 2021 08:45:38 -0400 (EDT) In-Reply-To: <20211019030802.83DE621120@vcs0.savannah.gnu.org> (Lars Ingebrigtsen's message of "Mon, 18 Oct 2021 23:08:02 -0400 (EDT)") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:277354 Archived-At: I think your `possibly_translate_key_sequence` should be extended to cover the XEmacs format as well, And it should be exported to ELisp. And I'd argue it should also convert strings to vectors. Oh and also convert [M-C-next] to [C-M-next]. WDYT? Stefan > +static Lisp_Object > +possibly_translate_key_sequence (Lisp_Object key, ptrdiff_t *length) > +{ > + if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0))) > + { > + /* KEY is on the ["C-c"] format, so translate to internal > + format. */ > + if (NILP (Ffboundp (Qkbd_valid_p))) > + xsignal2 (Qerror, > + build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"), > + key); > + if (NILP (call1 (Qkbd_valid_p, AREF (key, 0)))) > + xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); > + key = call1 (Qkbd, AREF (key, 0)); > + *length = CHECK_VECTOR_OR_STRING (key); > + if (*length == 0) > + xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); > + } > + > + return key; > +} > + > /* GC is possible in this function if it autoloads a keymap. */ > > DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, > @@ -1084,21 +1106,7 @@ binding KEY to DEF is added at the front of KEYMAP. */) > def = tmp; > } > > - if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0))) > - { > - /* KEY is on the ["C-c"] format, so translate to internal > - format. */ > - if (NILP (Ffboundp (Qkbd_valid_p))) > - xsignal2 (Qerror, > - build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"), > - key); > - if (NILP (call1 (Qkbd_valid_p, AREF (key, 0)))) > - xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); > - key = call1 (Qkbd, AREF (key, 0)); > - length = CHECK_VECTOR_OR_STRING (key); > - if (length == 0) > - xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); > - } > + key = possibly_translate_key_sequence (key, &length); > > ptrdiff_t idx = 0; > while (1) > @@ -1229,6 +1237,8 @@ recognize the default bindings, just as `read-key-sequence' does. */) > if (length == 0) > return keymap; > > + key = possibly_translate_key_sequence (key, &length); > + > ptrdiff_t idx = 0; > while (1) > { > diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el > index 68b42c3..13f47b4 100644 > --- a/test/src/keymap-tests.el > +++ b/test/src/keymap-tests.el > @@ -317,6 +317,13 @@ g .. h foo > (should (equal (single-key-description 'C-s-home) > "C-s-"))) > > +(ert-deftest keymap-test-lookups () > + (should (eq (lookup-key (current-global-map) "\C-x\C-f") 'find-file)) > + (should (eq (lookup-key (current-global-map) [(control x) (control f)]) > + 'find-file)) > + (should (eq (lookup-key (current-global-map) ["C-x C-f"]) 'find-file)) > + (should (eq (lookup-key (current-global-map) [?\C-x ?\C-f]) 'find-file))) > + > (provide 'keymap-tests) > > ;;; keymap-tests.el ends here