From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jussi Piitulainen Newsgroups: gmane.emacs.help Subject: Re: Alt as meta, except for certain keys, how? Date: 11 Aug 2003 21:10:38 +0300 Organization: University of Helsinki Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: 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 X-Trace: sea.gmane.org 1060625878 19452 80.91.224.253 (11 Aug 2003 18:17:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 11 Aug 2003 18:17:58 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 11 20:17:56 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 19mHEy-000179-00 for ; Mon, 11 Aug 2003 20:17:56 +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 19mHCx-0005Zx-MO for geh-help-gnu-emacs@m.gmane.org; Mon, 11 Aug 2003 14:15:51 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.media.kyoto-u.ac.jp!news.cc.tut.fi!news.helsinki.fi!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 114 Original-NNTP-Posting-Host: venus.ling.helsinki.fi Original-X-Trace: oravannahka.helsinki.fi 1060625438 26990 128.214.78.39 (11 Aug 2003 18:10:38 GMT) Original-X-Complaints-To: abuse@helsinki.fi Original-NNTP-Posting-Date: 11 Aug 2003 18:10:38 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Xref: shelby.stanford.edu gnu.emacs.help:115808 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:11726 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:11726 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 () (interactive) (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 21.3.50.6, 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. -- Jussi