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:09:56 +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="646"; 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:11:14 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 1rt9ZQ-000AUM-Ib for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Apr 2024 19:11:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rt9ZB-0006et-AB; Sat, 06 Apr 2024 13:10:57 -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 1rt9ZA-0006e4-4W for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:10: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 1rt9Z9-0002E2-Rt for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:10:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rt9ZG-00013l-3q for bug-gnu-emacs@gnu.org; Sat, 06 Apr 2024 13:11: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:11: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.17124234163941 (code B ref 70139); Sat, 06 Apr 2024 17:11:02 +0000 Original-Received: (at 70139) by debbugs.gnu.org; 6 Apr 2024 17:10:16 +0000 Original-Received: from localhost ([127.0.0.1]:40896 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rt9YV-00011V-K7 for submit@debbugs.gnu.org; Sat, 06 Apr 2024 13:10:16 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:42027) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rt9YS-00010Y-3v for 70139@debbugs.gnu.org; Sat, 06 Apr 2024 13:10:13 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 40510240103 for <70139@debbugs.gnu.org>; Sat, 6 Apr 2024 19:09:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712423399; bh=ikTTudsVgGHovxpKmsZuDZae23wUu8iFFOf5FhCstXo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=GS7QSkM+yd2TQVEDmTz++8hvcmWrcel4prkGsZKfGdNreBZ8lRtXN8aI5u2PEtU6y mfeNJenhIqIiJ+lJfg8rMxWE6hxr448oXEb7TDj7zM2vkKQrDJfpdGt+txGb7hNNx9 Fy+8tfTmJKjKNp5KvVQ2JoiNHdVDd1xfC2d8ZOo5yjK33hgRDKDvil5rjHGpfzs1fg ruKFoDhzWit3/Bx2AtlX582vFimxYm0ant2L9ibinQYmJYV2NgnuWxsCWwlYKgSPO7 CvRhh/MrSGVXZd3NxdN8InPeENWJgS9Pz5CYiGRkl2HmbolEJk8I26kL16lhiR3bBg nsE4Q9gg/5RGQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VBhgB2BW5z9rxG; Sat, 6 Apr 2024 19:09:58 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Thu, 04 Apr 2024 17:53:33 -0400") 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:282810 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-key-translate-to-support-removing-translatio.patch Content-Description: patch >From 34a045b66ecc4e7428952c6a1f8ce4b7c7dfd7ce 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/keymap.el b/lisp/keymap.el index 4bdf65d39fa..94dcb592305 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el @@ -382,17 +382,19 @@ 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) + (when to + (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))) + (and to (aref (key-parse to) 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) --=-=-= Content-Type: text/plain -- Charalampos --=-=-=--