From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Alt as meta, except for certain keys, how?
Date: Mon, 11 Aug 2003 14:29:18 -0600 [thread overview]
Message-ID: <3F37FC9E.5000203@yahoo.com> (raw)
In-Reply-To: qot4r0onjz5.fsf@venus.ling.helsinki.fi
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
next prev parent reply other threads:[~2003-08-11 20:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-07 17:33 Alt as meta, except for certain keys, how? Jussi Piitulainen
2003-08-07 18:38 ` Kevin Rodgers
2003-08-08 7:05 ` Ehud Karni
[not found] ` <mailman.222.1060326618.29551.help-gnu-emacs@gnu.org>
2003-08-08 18:51 ` Kevin Rodgers
2003-08-08 21:26 ` Ehud Karni
[not found] ` <mailman.235.1060378027.29551.help-gnu-emacs@gnu.org>
2003-08-11 18:10 ` Jussi Piitulainen
2003-08-11 20:29 ` Kevin Rodgers [this message]
2003-08-12 8:26 ` Jussi Piitulainen
2003-08-12 17:14 ` Kevin Rodgers
2003-08-13 5:14 ` Jussi Piitulainen
2003-08-15 13:05 ` Kai Großjohann
2003-08-11 19:54 ` Kevin Rodgers
2003-08-12 11:13 ` Ehud Karni
[not found] ` <mailman.336.1060687053.29551.help-gnu-emacs@gnu.org>
2003-08-12 18:16 ` Jussi Piitulainen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F37FC9E.5000203@yahoo.com \
--to=ihs_4664@yahoo.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).