From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Charalampos Mitrodimas Newsgroups: gmane.emacs.bugs Subject: bug#70139: [PATCH] Improve key-translate to support removing translations Date: Sat, 06 Apr 2024 17:18:29 +0000 Message-ID: References: <87v850t7nz.fsf@gmail.com> <20240402190246.1824023-1-charmitro@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="387"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70139@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 06 19:19:15 2024 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 1rt9hD-000APl-I9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Apr 2024 19:19:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rt9gw-0007eN-G8; Sat, 06 Apr 2024 13:18:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rt9gu-0007do-B4 for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:18:56 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rt9gu-0003L1-1o for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:18:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rt9h0-0001di-9L for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Charalampos Mitrodimas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Apr 2024 17:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70139 X-GNU-PR-Package: emacs Original-Received: via spool by 70139-submit@debbugs.gnu.org id=B70139.17124239286212 (code B ref 70139); Sat, 06 Apr 2024 17:19:02 +0000 Original-Received: (at 70139) by debbugs.gnu.org; 6 Apr 2024 17:18:48 +0000 Original-Received: from localhost ([127.0.0.1]:40900 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rt9gl-0001c7-QO for submit@debbugs.gnu.org; Sat, 06 Apr 2024 13:18:48 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38325) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rt9gh-0001bE-TQ for 70139@debbugs.gnu.org; Sat, 06 Apr 2024 13:18:46 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 61D96240027 for <70139@debbugs.gnu.org>; Sat, 6 Apr 2024 19:18:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712423911; bh=Rhv1eQLrozNU0rDbfT84yuhOIVSrtAbtP9iKxighN7Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=P0T4OOe11jjlw4lrHpHdF94hjo8wf7bqGUBpbToYmnYCIRHNT1dkhwdc1Nc/fBuFw XvHoinLVHrhXQfWThHEpKUYD+ql3cmD3d5vpuNV9Y0rTlIf4ImHOSeB6JCz7EPhfmv ymwWrv9cmDBORRWKTQRDvwPV4yAy+KNFTYTff5YVoDp1X7xC5Zht4dSBcegXrT25k7 HwILLzBjHtU/chlWkP8j6WsEv/g9JacD5SkFD7l5IRkM1O8YoTog4uUUQJnHqfXlnj Pj7sQDOVte9J0b9awupCfQvBjfA+z/VCRa5cxdh0tqsHm+pRrQiNBHzpaVAWTicP/r KArhboG3w/fyA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VBhs24t6jz9rxG; Sat, 6 Apr 2024 19:18:30 +0200 (CEST) In-Reply-To: (Charalampos Mitrodimas's message of "Sat, 06 Apr 2024 17:09:56 +0000") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:282811 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Charalampos Mitrodimas writes: > Stefan Monnier writes: > >>> Just to clarify, are you referring to something like this? >>> >>> =C2=A0=C2=A0=C2=A0 (key-translate "C-x" "C-z" "C-a") >> >> No, rather (key-translate "C-a C-z" "C-x b") >> >> >> Stefan > > Thanks for clarifying this! Updated patch attached. > > [2. patch --- text/x-patch; 0001-Improve-key-translate-to-support-removin= g-translatio.patch]... Apologies, wrong patch. Attaching the correct one :-) -- Charalampos --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-key-translate-to-support-removing-translatio.patch Content-Description: patch >From 45fd8a776bd51117e9c14d5ce096b2121383795b Mon Sep 17 00:00:00 2001 From: Charalampos Mitrodimas Date: Tue, 2 Apr 2024 19:02:46 +0000 Subject: [PATCH] Improve key-translate to support removing translations This patch enhances the key-translate function to allow removing keyboard translations by passing nil as the second argument (TO). If TO is nil, any existing translation for the FROM key will be removed. The compiler macro is updated to only check TO when it is non-nil. This change makes key-translate more consistent with the behavior of keyboard-translate, providing a way to remove translations without having to specify the same key for both FROM and TO. The documentation string is updated to reflect the new behavior. * lisp/keymap.el (key-translate): support removing translations by passing nil as the second argument (TO). Also throw error if multiple items passed. (Bug#70139) --- lisp/keymap.el | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lisp/keymap.el b/lisp/keymap.el index 4bdf65d39fa..acff41a3786 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el @@ -382,17 +382,25 @@ key-translate This function creates a `keyboard-translate-table' if necessary and then modifies one entry in it. -Both FROM and TO should be specified by strings that satisfy `key-valid-p'." +Both FROM and TO should be specified by strings that satisfy `key-valid-p'. +If TO is nil, remove any existing translation for FROM." (declare (compiler-macro - (lambda (form) (keymap--compile-check from to) form))) + (lambda (form) (keymap--compile-check from (and to to)) form))) (keymap--check from) - (keymap--check to) - (or (char-table-p keyboard-translate-table) - (setq keyboard-translate-table - (make-char-table 'keyboard-translate-table nil))) - (aset keyboard-translate-table - (aref (key-parse from) 0) - (aref (key-parse to) 0))) + (when to + (keymap--check to)) + (let ((from-key (key-parse from)) + (to-key (and to (key-parse to)))) + (when (> (length from-key) 1) + (error "FROM key %s is not a single key" from)) + (when (and to (> (length to-key) 1)) + (error "TO key %s is not a single key" to)) + (or (char-table-p keyboard-translate-table) + (setq keyboard-translate-table + (make-char-table 'keyboard-translate-table nil))) + (aset keyboard-translate-table + (aref from-key 0) + (and to (aref to-key 0))))) (defun keymap-lookup (keymap key &optional accept-default no-remap position) "Return the binding for command KEY in KEYMAP. -- 2.39.3 (Apple Git-146) --=-=-=--