[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alt as meta, except for certain keys, how?

From: Jussi Piitulainen
Subject: Re: Alt as meta, except for certain keys, how?
Date: 11 Aug 2003 21:10:38 +0300
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Ehud Karni writes:
> Kevin Rodgers wrote:
>> Ehud Karni wrote:
>>> Kevin Rodgers wrote:

and originally I wrote. Thousand thanks to both of you. Your help was
crucial, and I have implemented my keyboard mappings both ways now. I
think I have the whole numeric row more or less in shape, both with
Alt and with Alt-Shift, while elsewhere Alt is Meta.

I wish I knew what works differently with function-key-map and
key-translation-map. I have tried C-s and C-h v, at least I think I
have - the bootstrapping nature of this enterprise is confusing at
times, and I was doing two implementations in parallel.

There were a couple of obscure keys I failed to map as function keys:
letters outside ASCII used with Meta. The numeric codes worked for
them, but when I tried the obvious ?\M-letter syntax, nothing seemed
to happen.

>>>> (keyboard-translate ?\M-7 ?|) doesn't work, because
>>>> keyboard-translate-table is a char-table, which only handles
>>>> unmodified characters.

>>> You can find the character value of any key by the following
>>> function:
>>> (defun get-char-value () "get decimal value of any key"
>>>   (interactive)
>>>        (let (char [...]

Thanks. I worked this down to

   (defun insert-key-description ()
      (let ((event (read-event "Press the key combination")))
         (insert (condition-case ()
                     (text-char-description event)
                   (error (prin1-to-string event t))))))

which I used with point between the brackets in

    (define-key key-translation-map [] "").

It took the error branch in every case, but those numbers worked.

>> Overkill.
> It is not an overkill - see below.

Cannot judge this. Both solutions work for the whole numeric row, but
I don't know if function-key-map is somehow simpler or more obvious
than key-translation-map.

Those numeric codes are rather obscure, while the ?\M- syntax is more
transparent. On the other hand, not all keys seem to have a ?\M-
syntax. Maybe I'm mistaken here. Is there a way to turn every valid
key code into an Escape-Meta-Alt-Control-Shift-something? Or can I use
a numeric key code with function-key-map?

I have to try (define-key key-translation-map [?\M-7] "|"). That would
be an improvement.

>> Just evaluate ?\M-7.  On my system, it is -134217673, which is the
>> crux of the problem: meta-modified characters may have a negative
>> character code, and thus may not be a valid index into a
>> char-table.

That code works. I deduce that key-translation-map is not a
char-table. Indeed it appears to look very much like a tagged
association list. C-h v says it overrides ordinary bindings, which
must be why I don't global-unset-key for it to work.

> I did evaluate ?\M-7 and I get the same result (-134217673) as you.
> It is NOT what my function returns (4194359) !!!

I get -134217673 when I press Alt-7 while Alt is Meta. When Command is
Meta, I get something else (I think just the ASCII code for |).

Also, I think the numbers I saw in the actual key-translation-map were
again different. Smallish positive numbers. I'm on a different machine
now and cannot check it easily.

>>> Because key-translation-map may not exist, you better protect
>>> yourself by adding the following (before the define-key command):
>>>   (if (not key-translation-map)
>>>       (make-sparse-keymap key-translation-map))

I don't see how that could work if the map did not exist. If I ask
(not foo), I get an error because foo is not bound at all. But that
map exists all right. It handles C-x 8.

> I don't know which Emacs are you using, I checked it on 21.2,
> 21.3. and 21.3.50 (CVS HEAD version).

My Macs have, and at least on the iBook it works as you say.
Probably on this eMac, too, as it is the same binary distribution.

> On all the documentation for ` key-translation-map' says:
>   Keymap of key translations that can override keymaps.
>   This keymap works like `function-key-map', but comes after that,
>   and applies even for keys that have ordinary bindings.
> I think you confuse it with `keyboard-translate-table' which is
> used/created by the `keyboard-translate' command.

That must be it; keyboard-translate was one of my original failed
attempts, and it uses a char table. But C-h v was the only place where
I found documentation for key-translation-map. It doesn't seem to
appear in the C-h i manuals for Emacs or Emacs Lisp. There is a lot of
low level translation and mapping going on, and apparently no one
place to explain it all.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]