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: Tue, 2 Apr 2024 14:21:50 +0000 Message-ID: <20240402142150.1211286-1-charmitro@posteo.net> References: <87v850t7nz.fsf@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39325"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Charalampos Mitrodimas To: 70139@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 02 18:02:53 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 1rrgb6-0009yA-Io for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Apr 2024 18:02:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rrgaV-000893-JA; Tue, 02 Apr 2024 12:02:15 -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 1rrgaF-0007zi-JX for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 12:01:59 -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 1rrgaF-0004yQ-Bj for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 12:01:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rrgaJ-0005ov-0O for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 12:02:03 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87v850t7nz.fsf@gmail.com> Resent-From: Charalampos Mitrodimas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Apr 2024 16:02: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.171207370922294 (code B ref 70139); Tue, 02 Apr 2024 16:02:02 +0000 Original-Received: (at 70139) by debbugs.gnu.org; 2 Apr 2024 16:01:49 +0000 Original-Received: from localhost ([127.0.0.1]:55040 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rrga3-0005nK-RG for submit@debbugs.gnu.org; Tue, 02 Apr 2024 12:01:49 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38543) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rrf1a-0007zU-KN for 70139@debbugs.gnu.org; Tue, 02 Apr 2024 10:22:08 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 9778C240029 for <70139@debbugs.gnu.org>; Tue, 2 Apr 2024 16:21:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712067716; bh=+aXoAmFeoTHjo+B160StGHzU7rBGCuj05HiKu+fUSg4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=isnXJiCfauSBfuhhsj96pblQB8qf6VBKuPvKE7/b5skxGqHVSAGG/mDHPu/D3MtlZ T3LKgzeEzgBLta8OGjzrHPEK9zgWJ7B+zClgLzQak1RxH55eMWbMrO7TeWfeH8N/h+ m/8YzHTs6FERfzmB/7ChWybDmKuPShfanY9pRa5tq3zNe4/wK6KR3mkA3c+H9ocJP3 JE4Oa/TmgcJ0u+V4gTrqaThGjZ6aytYH63fFjQa3zoxV7QJM4xXAYJDJwxUiMehZTc kUzy/rbQSGRlrPVSNlmHrQWCGXSfQ/tGdcuJGoEOXoljhR75oa7jL5EDVpuoIPz6X2 UZXfvVhwLb8DA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4V89780zTzz6tm8; Tue, 2 Apr 2024 16:21:55 +0200 (CEST) X-Mailman-Approved-At: Tue, 02 Apr 2024 12:01:46 -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:282522 Archived-At: 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/keymap.el b/lisp/keymap.el index b2b475c7d71..1481f1fe72b 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.34.1