From: Charalampos Mitrodimas <charmitro@posteo.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 70139@debbugs.gnu.org
Subject: bug#70139: [PATCH] Improve key-translate to support removing translations
Date: Sat, 06 Apr 2024 17:09:56 +0000 [thread overview]
Message-ID: <m27chamn8b.fsf@posteo.net> (raw)
In-Reply-To: <jwv34s0lrre.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 04 Apr 2024 17:53:33 -0400")
[-- Attachment #1: Type: text/plain, Size: 297 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Just to clarify, are you referring to something like this?
>>
>> (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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2202 bytes --]
From 34a045b66ecc4e7428952c6a1f8ce4b7c7dfd7ce Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas <charmitro@posteo.net>
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)
[-- Attachment #3: Type: text/plain, Size: 16 bytes --]
--
Charalampos
next prev parent reply other threads:[~2024-04-06 17:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 9:50 bug#70139: 29.3.50; key-translate does not support all keyboard-translate usages Robert Pluim
2024-04-02 14:21 ` bug#70139: [PATCH] Improve key-translate to support removing translations Charalampos Mitrodimas
2024-04-02 14:28 ` bug#70139: 29.3.50; key-translate does not support all keyboard-translate usages Charalampos Mitrodimas
2024-04-02 15:41 ` Robert Pluim
2024-04-02 19:02 ` bug#70139: [PATCH] Improve key-translate to support removing translations Charalampos Mitrodimas
2024-04-04 13:00 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-04 19:48 ` Charalampos Mitrodimas
2024-04-04 21:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-06 17:09 ` Charalampos Mitrodimas [this message]
2024-04-06 17:18 ` Charalampos Mitrodimas
2024-04-07 14:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-09 11:14 ` Charalampos Mitrodimas
2024-04-09 12:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-09 13:07 ` Charalampos Mitrodimas
2024-04-13 9:19 ` Eli Zaretskii
2024-04-13 12:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-13 16:02 ` Eli Zaretskii
2024-04-14 21:31 ` Charalampos Mitrodimas
2024-04-15 2:30 ` Eli Zaretskii
2024-05-20 20:39 ` Charalampos Mitrodimas
2024-05-23 13:25 ` Eli Zaretskii
2024-04-04 12:27 ` bug#70139: 29.3.50; key-translate does not support all keyboard-translate usages Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m27chamn8b.fsf@posteo.net \
--to=charmitro@posteo.net \
--cc=70139@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.