From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Alt as meta, except for certain keys, how? Date: Mon, 11 Aug 2003 14:29:18 -0600 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <3F37FC9E.5000203@yahoo.com> References: <3F329CBE.8050706@yahoo.com> <3F33F14F.2060903@yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1060633934 1331 80.91.224.253 (11 Aug 2003 20:32:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 11 Aug 2003 20:32:14 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 11 22:32:12 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19mJKu-0007TZ-00 for ; Mon, 11 Aug 2003 22:32:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mJJe-00028U-4M for geh-help-gnu-emacs@m.gmane.org; Mon, 11 Aug 2003 16:30:54 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!130.133.1.3.MISMATCH!fu-berlin.de!uni-berlin.de!170.207.51.80!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 131 Original-NNTP-Posting-Host: 170.207.51.80 Original-X-Trace: news.uni-berlin.de 1060633758 33090930 170.207.51.80 (16 [82742]) User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 X-Accept-Language: en-us Original-Xref: shelby.stanford.edu gnu.emacs.help:115812 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:11730 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:11730 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 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