Subject: Re: bug#4709: 23.1; keyboard-translate not working with emacs daemon

From: Stefan Monnier <[email-masked]>
Date: Thu, 15 Oct 2009 11:22:54 -0400

> All I can do is just to ask.  But, please google and
> you'll find that keyboard translation is often suggested
> as a solution to the "C-h" problem.

I know about that.  But this is usually not a problem of keyboard, but
a problem of configuration of the xterm (or whatever other terminal
emulator is used).  So the answer (to use keyboard-translation) is
actually a bad answer, simply carried over from the years long past
where people used real text terminals where it was the only answer.
Nowadays, the right answer is to fix the xterm's config so that DEL
(aka "backspace") is not confused with C-h.

IOW, these are not uses but misuses of keyboard-translate.

> When I raised this
> issue in gnu.emacs.help, there was another person who
> was suffering from the lack of a truly global keyboard
> translation.  I also found a posting on the net asking
> the same question as mine (why doesn't keyboard translation
> work with emacs daemon?).  For a user using a "strange"
> keyboard (see below), keyboard translation is the cleanest
> solution.

Usually the way key presses get presented to Emacs depends a lot on
whether they come straight from X11/w32/ns for GUI frames, or from some
terminal emulator.  This is especially true for delete and backspace
keys.  So global settings are usually not the right answer.

> | But do you really also want C-x C-h to invoke the command bound
> | to C-x C-?

> I've never been faced with such a situation.  But, if there is
> ever such a situation, my answer must be "Yes, I would want C-x
> C-h to invoke the command bound to C-x C-?".  Because the delete
> key does "not exist" to me!

Good, then global-set-key is not the right answer.

> 1) My delete key doesn't work in the first place.  I don't know
>   what's wrong but it doesn't do anything on the bash prompt,
>   for example, and it doesn't delete the character before the cursor
>   on emacs (A message "End of Buffer" appears in the message line).

That looks like a problem in itself which you may want to fix.
What does C-h k <your delete key here> say?

> 2) My delete key isn't easily accessible.  On my regular keyboards,
>   it's only accessible by pressing a "fn" key and "~`" key at the
>   same time; it's really awkward to type.

Hmm... you're mapping C-h to C-? which is called DEL but which is really
the "backspace" key, not the "delete" key (tho there's been a lot of
confusion around this over the years since the terms were not used
consistently between keyboard manufacturers).  I.e. it's the key that
normally sits at the extreme right of the row which has the numbers
(the "top" row, if you ignore F1, F2, ... and such things).

The "delete" key (which deletes forward rather than backward), is
often placed together with things like "home", "end", "insert", "page
up" and "page down".  On Macs, IIRC, the delete key is only accessible
via some Fn combination.

So which physical key do you mean here?

> 3) I can't press it on my other keyboard without looking for it.
>    It's too far from the home position.

Clearly, not a key you want to use, yes.

> These things have been fine with me because I've never needed
> the delete key.

I never use the delete key either, basically (C-d is a lot more
convenient to delete forward).  I do you use the backspace key
heavily, tho.

> The delete key exists as a physical entity but, considering the
> situation above, you'll agree that it's as good as non-existent
> to me.  So, if faced with a need for such a combination
> as "C-x C-?", I would choose to use "C-x C-h".

That's good, yes.  It means that some form of keyboard-translation is
the right answer.

> | > So, I think keyboard-translate is the cleanest,
> | > once-and-for-all solution, if it works globally.
> | Have you tried key-translation-map (which is global)?
> | I have never understand the existence of both key-translation-map
> | and keyboard-translate-table.
> I've never heard of it.  I'll investigate.  Thank you for the
> suggestion.

The invocation below:

   (define-key key-translation-map [?\C-h] [?\C-?])

should do the trick.

        Stefan