GNU bug report logs - #65735
[PATCH] key-translate should use the 1st key of a key sequence

Previous Next

Package: emacs;

Reported by: Shynur Xie <one.last.kiss <at> outlook.com>

Date: Mon, 4 Sep 2023 15:52:02 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 29.2

Done: Robert Pluim <rpluim <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 65735 in the body.
You can then email your comments to 65735 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Mon, 04 Sep 2023 15:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shynur Xie <one.last.kiss <at> outlook.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 04 Sep 2023 15:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Shynur Xie <one.last.kiss <at> outlook.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] key-translate should use the 1st key of a key sequence
Date: Mon, 4 Sep 2023 15:46:32 +0000
[Message part 1 (text/plain, inline)]
To make 

    (key-translate "C-x" "<control-x>")
    ;; this is an example in elisp manual 

work.
[0001-key-translate-uses-the-1st-key-of-a-key-sequence.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 07:55:03 GMT) Full text and rfc822 format available.

Message #8 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Shynur Xie <one.last.kiss <at> outlook.com>
Cc: 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a
 key sequence
Date: Thu, 07 Sep 2023 09:54:13 +0200
>>>>> On Mon, 4 Sep 2023 15:46:32 +0000, Shynur Xie <one.last.kiss <at> outlook.com> said:

    Shynur> To make 
    Shynur>     (key-translate "C-x" "<control-x>")
    Shynur>     ;; this is an example in elisp manual 

    Shynur> work.

Yes, oops. Perhaps we should also check that `from' and `to' specify
single keys, although that might be overkill.

I see commits from you both with and without
Copyright-paperwork-exempt, do you have a copyright assignment on
file?

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 08:17:01 GMT) Full text and rfc822 format available.

Message #11 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: one.last.kiss <at> outlook.com, 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a key
 sequence
Date: Thu, 07 Sep 2023 11:15:44 +0300
> Cc: 65735 <at> debbugs.gnu.org
> From: Robert Pluim <rpluim <at> gmail.com>
> Date: Thu, 07 Sep 2023 09:54:13 +0200
> 
> I see commits from you both with and without
> Copyright-paperwork-exempt, do you have a copyright assignment on
> file?

He does, now.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 11:58:02 GMT) Full text and rfc822 format available.

Message #14 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: one.last.kiss <at> outlook.com, 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a
 key sequence
Date: Thu, 07 Sep 2023 13:57:14 +0200
>>>>> On Thu, 07 Sep 2023 11:15:44 +0300, Eli Zaretskii <eliz <at> gnu.org> said:

    >> Cc: 65735 <at> debbugs.gnu.org
    >> From: Robert Pluim <rpluim <at> gmail.com>
    >> Date: Thu, 07 Sep 2023 09:54:13 +0200
    >> 
    >> I see commits from you both with and without
    >> Copyright-paperwork-exempt, do you have a copyright assignment on
    >> file?

    Eli> He does, now.

OK. Then Iʼll push it to emacs-29, since otherwise `key-translate' is
completely useless.

In the interests of, uhm, eating our own dogfood, how about the
following as well for master (or should I let sleeping dogs lie 😺)

diff --git i/lisp/simple.el w/lisp/simple.el
index 05a3c4b93d6..da9db1685c4 100644
--- i/lisp/simple.el
+++ w/lisp/simple.el
@@ -10658,10 +10658,10 @@ normal-erase-is-backspace-mode
 	  (t
 	   (if enabled
 	       (progn
-		 (keyboard-translate ?\C-h ?\C-?)
-		 (keyboard-translate ?\C-? ?\C-d))
-	     (keyboard-translate ?\C-h ?\C-h)
-	     (keyboard-translate ?\C-? ?\C-?))))
+		 (key-translate "C-h" "DEL")
+		 (key-translate "DEL" "C-d"))
+	     (key-translate "C-h" "C-h")
+	     (key-translate "DEL" "DEL"))))
 
     (if (called-interactively-p 'interactive)
 	(message "Delete key deletes %s"
diff --git i/lisp/term/bobcat.el w/lisp/term/bobcat.el
index 983c8cded2f..2f611953523 100644
--- i/lisp/term/bobcat.el
+++ w/lisp/term/bobcat.el
@@ -3,8 +3,8 @@
 (defun terminal-init-bobcat ()
   "Terminal initialization function for bobcat."
   ;; HP terminals usually encourage using ^H as the rubout character
-  (keyboard-translate ?\177 ?\^h)
-  (keyboard-translate ?\^h ?\177))
+  (key-translate "DEL "C-h")
+  (key-translate "C-h "DEL"))
 
 (provide 'term/bobcat)
 

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 13:11:01 GMT) Full text and rfc822 format available.

Message #17 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Robert Pluim <rpluim <at> gmail.com>,
 Stefan Kangas <stefankangas <at> gmail.com>
Cc: one.last.kiss <at> outlook.com, 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a
 key sequence
Date: Thu, 07 Sep 2023 16:09:27 +0300
> From: Robert Pluim <rpluim <at> gmail.com>
> Cc: one.last.kiss <at> outlook.com,  65735 <at> debbugs.gnu.org
> Date: Thu, 07 Sep 2023 13:57:14 +0200
> 
> >>>>> On Thu, 07 Sep 2023 11:15:44 +0300, Eli Zaretskii <eliz <at> gnu.org> said:
> 
>     >> Cc: 65735 <at> debbugs.gnu.org
>     >> From: Robert Pluim <rpluim <at> gmail.com>
>     >> Date: Thu, 07 Sep 2023 09:54:13 +0200
>     >> 
>     >> I see commits from you both with and without
>     >> Copyright-paperwork-exempt, do you have a copyright assignment on
>     >> file?
> 
>     Eli> He does, now.
> 
> OK. Then Iʼll push it to emacs-29, since otherwise `key-translate' is
> completely useless.

Yes, thanks.

> In the interests of, uhm, eating our own dogfood, how about the
> following as well for master (or should I let sleeping dogs lie 😺)

I'll let Stefan answer that, as, among the two of us, he is the
enthusiast of modernizing ;-)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 13:43:02 GMT) Full text and rfc822 format available.

Message #20 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Shynur Xie <one.last.kiss <at> outlook.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: "65735 <at> debbugs.gnu.org" <65735 <at> debbugs.gnu.org>
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a key
 sequence
Date: Thu, 7 Sep 2023 13:42:18 +0000
> Robert:
> Perhaps we should also check that `from' and `to' specify single
> keys, although that might be overkill.

Not necessary IMO.
As a regular Emacs user, I would read its docstring before using this
function; the docstring already explains how to use it very clearly.
Moreover, there're several examples in the elisp manual for reference:

   +----------------------------------------------------+
   | -- Function: key-translate from to                 |
   |     ... ...                                        |
   |   Here’s an example of ...                         |
   |     (key-translate "C-x" "<control-x>")            |
   |     (keymap-global-set "<control-x>" 'kill-region) |
   +----------------------------------------------------+

> Robert:
> do you have a copyright assignment on file?

Yes.

> Robert:
> --- i/lisp/simple.el
> +++ w/lisp/simple.el

> - (keyboard-translate ?\C-h ?\C-?)
> -	(keyboard-translate ?\C-? ?\C-d))
> -	(keyboard-translate ?\C-h ?\C-h)
> -	(keyboard-translate ?\C-? ?\C-?))))
> +	(key-translate "C-h" "DEL")
> +	(key-translate "DEL" "C-d"))
> +	(key-translate "C-h" "C-h")
> +	(key-translate "DEL" "DEL"))))

The docstring of `keyboard-translate' does suggest using
`key-translate'; similarly, `define-key' suggests using `keymap-set'.

FWIW, I noticed that there're also some `define-key' invocations in
the file "lisp/simple.el".



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 13:50:01 GMT) Full text and rfc822 format available.

Message #23 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Shynur Xie <one.last.kiss <at> outlook.com>
Cc: "65735 <at> debbugs.gnu.org" <65735 <at> debbugs.gnu.org>
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a
 key sequence
Date: Thu, 07 Sep 2023 15:49:26 +0200
>>>>> On Thu, 7 Sep 2023 13:42:18 +0000, Shynur Xie <one.last.kiss <at> outlook.com> said:

    >> Robert:
    >> Perhaps we should also check that `from' and `to' specify single
    >> keys, although that might be overkill.

    Shynur> Not necessary IMO.
    Shynur> As a regular Emacs user, I would read its docstring before using this
    Shynur> function; the docstring already explains how to use it very clearly.
    Shynur> Moreover, there're several examples in the elisp manual for reference:

OK, Iʼll leave that bit alone.

    Shynur> The docstring of `keyboard-translate' does suggest using
    Shynur> `key-translate'; similarly, `define-key' suggests using `keymap-set'.

Right. But the question is whether we should change Emacs to use the
new functions, or whether we call it 'unnecessary churn'.

    Shynur> FWIW, I noticed that there're also some `define-key' invocations in
    Shynur> the file "lisp/simple.el".

One function at a time :-)

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Thu, 07 Sep 2023 14:02:01 GMT) Full text and rfc822 format available.

Message #26 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Robert Pluim <rpluim <at> gmail.com>
Cc: one.last.kiss <at> outlook.com, 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a key
 sequence
Date: Thu, 7 Sep 2023 07:01:44 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

>> In the interests of, uhm, eating our own dogfood, how about the
>> following as well for master (or should I let sleeping dogs lie 😺)
>
> I'll let Stefan answer that, as, among the two of us, he is the
> enthusiast of modernizing ;-)

;-)

I have no objections to the patch, so please go ahead.

One benefit of using our "new" API's (a.k.a. dogfooding) is that it
gives us a chance to test them in practice.  For example, it helped me
find some issues in keymap.el that we were able to rectify before 29.1.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65735; Package emacs. (Mon, 18 Sep 2023 09:50:01 GMT) Full text and rfc822 format available.

Message #29 received at 65735 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, one.last.kiss <at> outlook.com,
 65735 <at> debbugs.gnu.org
Subject: Re: bug#65735: [PATCH] key-translate should use the 1st key of a
 key sequence
Date: Mon, 18 Sep 2023 11:49:02 +0200
tags 65735 fixed
close 65735 29.2
quit

>>>>> On Thu, 7 Sep 2023 07:01:44 -0700, Stefan Kangas <stefankangas <at> gmail.com> said:

    Stefan> Eli Zaretskii <eliz <at> gnu.org> writes:
    >>> In the interests of, uhm, eating our own dogfood, how about the
    >>> following as well for master (or should I let sleeping dogs lie 😺)
    >> 
    >> I'll let Stefan answer that, as, among the two of us, he is the
    >> enthusiast of modernizing ;-)

    Stefan> ;-)

    Stefan> I have no objections to the patch, so please go ahead.

    Stefan> One benefit of using our "new" API's (a.k.a. dogfooding) is that it
    Stefan> gives us a chance to test them in practice.  For example, it helped me
    Stefan> find some issues in keymap.el that we were able to rectify before 29.1.

Closing.
Committed as 93134bb9c2f

Iʼll push the change to master once emacs-29 has been merged there.

Robert
-- 




Added tag(s) fixed. Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 18 Sep 2023 09:50:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 29.2, send any further explanations to 65735 <at> debbugs.gnu.org and Shynur Xie <one.last.kiss <at> outlook.com> Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 18 Sep 2023 09:50:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 16 Oct 2023 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 207 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.