help-gnu-emacs
[Top][All Lists]
Advanced

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

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


From: Kevin Rodgers
Subject: Re: Alt as meta, except for certain keys, how?
Date: Mon, 11 Aug 2003 14:29:18 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Jussi Piitulainen wrote:

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.


From the "Translating Input Events" node of the Emacs Lisp manual:

|  - Variable: key-translation-map
|      This variable is another keymap used just like `function-key-map'
|      to translate input events into other events.  It differs from
|      `function-key-map' in two ways:
|
|         * `key-translation-map' goes to work after `function-key-map' is
|           finished; it receives the results of translation by
|           `function-key-map'.
|
|         * `key-translation-map' overrides actual key bindings.  For
|           example, if `C-x f' has a binding in `key-translation-map',
|           that translation takes effect even though `C-x f' also has a
|           key binding in the global map.


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.


From the "Character Type" node of the Emacs Lisp manual:


|    A "meta character" is a character typed with the <META> modifier
| key.  The integer that represents such a character has the 2**27 bit
| set (which on most machines makes it a negative number).  We use high
| bits for this and other modifiers to make possible a wide range of
| basic character codes.
| | In a string, the 2**7 bit attached to an ASCII character indicates a
| meta character; thus, the meta characters that can fit in a string have
| codes in the range from 128 to 255, and are the meta versions of the
| ordinary ASCII characters.  (In Emacs versions 18 and older, this
| convention was used for characters outside of strings as well.)


So you need to use the vector notation for keys containing meta-modified
non-ASCII characters:

(define-key key-translation-map [?\M- ...] ...)


...


I don't know if function-key-map is somehow simpler or more obvious
than key-translation-map.


As the manual explains, it is applied first, and does not override bindings
in the normal keymaps.


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.


If I understand it, all characters have a corresponding meta-modified
character that can be represented as ?\M-...  But not all keyboard events
can be meta-modified, and not all meta-modified characters are valid
string elements.

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 don't understand your question.


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


Correct.


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.


Right, key-translation-map is a sparse keymap; keyboard-translate-table
is a char-table.

Use (define-key KEYMAP KEY nil) to unset a key in a map other than the
current global or local keymap.


...


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 think that should be:

(or key-translation-map
   (setq key-translation-map (make-sparse-keymap)))


--
Kevin Rodgers



reply via email to

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