* Alt as meta, except for certain keys, how? @ 2003-08-07 17:33 Jussi Piitulainen 2003-08-07 18:38 ` Kevin Rodgers 0 siblings, 1 reply; 14+ messages in thread From: Jussi Piitulainen @ 2003-08-07 17:33 UTC (permalink / raw) Hello, I'm tearing my hair off. I want to use Alt as a Meta key, with the exception that certain keys should be interpreted as ordinary unmodified characters: Alt-7 should produce vertical bar |, Shift-Alt-7 alias Alt-/ should produce backslash \, and there are a few others, all in ASCII. I have managed to (global-set-key "\M-7" "|"). That works for writing but is not a real solution. At least in an incremental search Alt-7 has already been interpreted as two keys: the escape terminates the search and 7 is inserted in the buffer. I could not work out how to use keyboard-translate to turn Alt-7 into vertical bar. If this is possible, could someone please show me the concrete command? Or any other way to achieve my goal? Emacs is 21.3.50.6 from 2002-11-27, a binary distribution for Mac OS X, the keyboards are Apple's - Finnish layout - Alt is sometimes called Option. I know I lose a couple of command bindings; I can produce all accented letters with dead keys. Thanks for any help, -- Jussi ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 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> 0 siblings, 2 replies; 14+ messages in thread From: Kevin Rodgers @ 2003-08-07 18:38 UTC (permalink / raw) Jussi Piitulainen wrote: > I want to use Alt as a Meta key, with the exception that certain keys > should be interpreted as ordinary unmodified characters: Alt-7 should > produce vertical bar |, Shift-Alt-7 alias Alt-/ should produce > backslash \, and there are a few others, all in ASCII. > > I have managed to (global-set-key "\M-7" "|"). That works for writing > but is not a real solution. At least in an incremental search Alt-7 > has already been interpreted as two keys: the escape terminates the > search and 7 is inserted in the buffer. Try setting search-exit-option to nil. > I could not work out how to use keyboard-translate to turn Alt-7 into > vertical bar. If this is possible, could someone please show me the > concrete command? Or any other way to achieve my goal? (keyboard-translate ?\M-7 ?|) doesn't work, because keyboard-translate-table is a char-table, which only handles unmodified characters. So perhaps you can use (abuse?) function-key-map: (define-key function-key-map "\M-7" [?|]) That only takes effect if you also remove its default binding: (global-unset-key "\M-7") > Emacs is 21.3.50.6 from 2002-11-27, a binary distribution for Mac OS > X, the keyboards are Apple's - Finnish layout - Alt is sometimes > called Option. I know I lose a couple of command bindings; I can > produce all accented letters with dead keys. -- Kevin Rodgers ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 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> 1 sibling, 0 replies; 14+ messages in thread From: Ehud Karni @ 2003-08-08 7:05 UTC (permalink / raw) Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 07 Aug 2003 12:38:54 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: > > Jussi Piitulainen wrote: > > > I want to use Alt as a Meta key, with the exception that certain keys > > should be interpreted as ordinary unmodified characters: Alt-7 should > > produce vertical bar |, Shift-Alt-7 alias Alt-/ should produce > > backslash \, and there are a few others, all in ASCII. > > > > I have managed to (global-set-key "\M-7" "|"). That works for writing > > but is not a real solution. At least in an incremental search Alt-7 > > has already been interpreted as two keys: the escape terminates the > > search and 7 is inserted in the buffer. > > > Try setting search-exit-option to nil. > > > > I could not work out how to use keyboard-translate to turn Alt-7 into > > vertical bar. If this is possible, could someone please show me the > > concrete command? Or any other way to achieve my goal? > > > (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 desc) (message "Type any char - " ) (setq char (read-event)) (if (not char) (message "Non char event - no value") (condition-case () (setq desc (text-char-description char)) (error (setq desc "(No description)"))) (if (numberp char) (message "Character typed is %s, (octal=%03o, decimal=%d, hexa=%02x)" desc char char char) (message "Input typed is %s, not a number" (prin1-to-string char t)))))) On my system it shows for Alt-7: Character typed is "7", (octal=20000067, decimal=4194359, hexa=400037) So if you do: (define-key key-translation-map [4194359] "|") It will do what you want (in all modes and maps - including isearch). 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)) Ehud. - -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ mailto:ehud@unix.mvs.co.il Better Safe Than Sorry -----BEGIN PGP SIGNATURE----- Comment: use http://www.keyserver.net/ to get my key (and others) iD8DBQE/M0vLLFvTvpjqOY0RAhX+AJ9LHeuuOApGdN3Bm7w4JQyZHjlrUACfSxfp GuDiPrO+dSD2WK1otk5mPAY= =KJMF -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.222.1060326618.29551.help-gnu-emacs@gnu.org>]
* Re: Alt as meta, except for certain keys, how? [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> 0 siblings, 2 replies; 14+ messages in thread From: Kevin Rodgers @ 2003-08-08 18:51 UTC (permalink / raw) Ehud Karni wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thu, 07 Aug 2003 12:38:54 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: >>(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 > desc) > (message "Type any char - " ) > (setq char (read-event)) > (if (not char) > (message "Non char event - no value") > (condition-case () > (setq desc (text-char-description char)) > (error > (setq desc "(No description)"))) > (if (numberp char) > (message "Character typed is %s, (octal=%03o, decimal=%d, hexa=%02x)" > desc char char char) > (message "Input typed is %s, not a number" (prin1-to-string char t)))))) Overkill. > On my system it shows for Alt-7: > Character typed is "7", (octal=20000067, decimal=4194359, hexa=400037) 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. > So if you do: > (define-key key-translation-map [4194359] "|") key-translation-map takes character arguments, not (vector or string) keys: wrong-type-argument integerp [-134217673] > It will do what you want (in all modes and maps - including isearch). But on my system, that signals an args-out-of-range error: args-out-of-range #^[t nil nil nil ...] -134217673 > 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)) key-translation-map is now a char-table, not a keymap (see the Translating Input node of the Emacs Lisp manual). -- Kevin Rodgers ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 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> 1 sibling, 0 replies; 14+ messages in thread From: Ehud Karni @ 2003-08-08 21:26 UTC (permalink / raw) Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, 08 Aug 2003 12:51:59 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: > > Ehud Karni wrote: > > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On Thu, 07 Aug 2003 12:38:54 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: > >>(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 > > desc) > > (message "Type any char - " ) > > (setq char (read-event)) > > (if (not char) > > (message "Non char event - no value") > > (condition-case () > > (setq desc (text-char-description char)) > > (error > > (setq desc "(No description)"))) > > (if (numberp char) > > (message "Character typed is %s, (octal=%03o, decimal=%d, hexa=%02x)" > > desc char char char) > > (message "Input typed is %s, not a number" (prin1-to-string char t)))))) > > > Overkill. It is not an overkill - see below. > > On my system it shows for Alt-7: > > Character typed is "7", (octal=20000067, decimal=4194359, hexa=400037) > > > 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. I did evaluate ?\M-7 and I get the same result (-134217673) as you. It is NOT what my function returns (4194359) !!! > > So if you do: > > (define-key key-translation-map [4194359] "|") > > > key-translation-map takes character arguments, not (vector or string) keys: Not true, see below. > wrong-type-argument integerp [-134217673] On Cygwin Emacs (21.2) my function give the this number (dec=-134217673 hexa=f8000037) and when I do : (define-key key-translation-map [-134217673] "|") it works just fine (no error) and it does what's needed. > > It will do what you want (in all modes and maps - including isearch). > > But on my system, that signals an args-out-of-range error: > > args-out-of-range #^[t nil nil nil ...] -134217673 Did you use my function ? Did you check that key-translation-map exists ? I suggest you try my recipe exactly as it is given. I have tried it and it works (even with negative number). > > 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)) > > key-translation-map is now a char-table, not a keymap (see the Translating Input > node of the Emacs Lisp manual). I don't know which Emacs are you using, I checked it on 21.2, 21.3. and 21.3.50 (CVS HEAD version). 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. Ehud. - -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ mailto:ehud@unix.mvs.co.il Better Safe Than Sorry -----BEGIN PGP SIGNATURE----- Comment: use http://www.keyserver.net/ to get my key (and others) iD8DBQE/NBV6LFvTvpjqOY0RAtrdAJ9Ug/ADrgre76kS0G5SdE3jW9aGNACfVuJp GQA+SnMsgMpUnIruhcNLwYs= =UT// -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.235.1060378027.29551.help-gnu-emacs@gnu.org>]
* Re: Alt as meta, except for certain keys, how? [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 2003-08-11 19:54 ` Kevin Rodgers 1 sibling, 1 reply; 14+ messages in thread From: Jussi Piitulainen @ 2003-08-11 18:10 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 2003-08-11 18:10 ` Jussi Piitulainen @ 2003-08-11 20:29 ` Kevin Rodgers 2003-08-12 8:26 ` Jussi Piitulainen 2003-08-15 13:05 ` Kai Großjohann 0 siblings, 2 replies; 14+ messages in thread From: Kevin Rodgers @ 2003-08-11 20:29 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 2003-08-11 20:29 ` Kevin Rodgers @ 2003-08-12 8:26 ` Jussi Piitulainen 2003-08-12 17:14 ` Kevin Rodgers 2003-08-15 13:05 ` Kai Großjohann 1 sibling, 1 reply; 14+ messages in thread From: Jussi Piitulainen @ 2003-08-12 8:26 UTC (permalink / raw) Kevin Rodgers writes: > So you need to use the vector notation for keys containing > meta-modified non-ASCII characters: > > (define-key key-translation-map [?\M- ...] ...) M-space? Anyway, that did not seem to work when I tried it. The key remained unbound. >> 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'm sorry. A concrete instance of the first question is this. I'll write "letter" for the non-ASCII letters. The following works: (define-key key-translation-map [-134217482] "o") I would like to find out a more transparent syntax for that number; text-char-description does not do it. Things like [?\M-letter] and [?\M- ?letter] and [(meta ?letter)] do not seem to work. For the second question I know the answer now: the following works. (global-unset-key [-134217500]) (define-key function-key-map [-134217500] "a") I got these numbers by pressing the key I want to bind: Alt-letter, where Alt is Meta and letter is outside ASCII. However, ?\M-letter evaluates to -134215434 rather than -134217482. If I omit to set mac-keyboard-text-encoding to Latin-1, ?\M-letter evaluates to -134217574, which is again something else (and the key in question cannot be used to produce the letter any more). "\M-letter" evaluates to a string that contains just the letter. I think I'll use the numbers for these few keys. -- Jussi ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 2003-08-12 8:26 ` Jussi Piitulainen @ 2003-08-12 17:14 ` Kevin Rodgers 2003-08-13 5:14 ` Jussi Piitulainen 0 siblings, 1 reply; 14+ messages in thread From: Kevin Rodgers @ 2003-08-12 17:14 UTC (permalink / raw) Jussi Piitulainen wrote: > Kevin Rodgers writes: >>So you need to use the vector notation for keys containing >>meta-modified non-ASCII characters: >> >>(define-key key-translation-map [?\M- ...] ...) > > M-space? Anyway, that did not seem to work when I tried it. The key > remained unbound. Sorry, I was trying to show a general form via ellipses. A concrete example would be (define-key key-translation-map [?\M-7] "|") >>>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'm sorry. A concrete instance of the first question is this. I'll > write "letter" for the non-ASCII letters. The following works: > > (define-key key-translation-map [-134217482] "o") > > I would like to find out a more transparent syntax for that number; > text-char-description does not do it. Things like [?\M-letter] and > [?\M- ?letter] and [(meta ?letter)] do not seem to work. I don't know why those wouldn't work (except that the extra space and question mark between ?M- and letter in the first form are wrong), unless there are keyboard/buffer/file coding issues. You might want to use the octal encoding instead: [?\M-\241] ; meta inverted exclamation point > For the second question I know the answer now: the following works. > > (global-unset-key [-134217500]) > (define-key function-key-map [-134217500] "a") > > I got these numbers by pressing the key I want to bind: Alt-letter, > where Alt is Meta and letter is outside ASCII. However, ?\M-letter > evaluates to -134215434 rather than -134217482. If I omit to set > mac-keyboard-text-encoding to Latin-1, ?\M-letter evaluates to > -134217574, which is again something else (and the key in question > cannot be used to produce the letter any more). I don't understand Emacs' encoding scheme at all, nor do I want to. > "\M-letter" evaluates to a string that contains just the letter. The only meta characters that can be included in a string are the meta- modified ASCII characters: | 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. That's why you have to use the vector notation. > I think I'll use the numbers for these few keys. The "Character Type" node of the Emacs Lisp manual strongly discourages that: | Since characters are really integers, the printed representation of a | character is a decimal number. This is also a possible read syntax for | a character, but writing characters that way in Lisp programs is a very | bad idea. You should _always_ use the special read syntax formats that | Emacs Lisp provides for characters. These syntax formats start with a | question mark. -- Kevin Rodgers ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 2003-08-12 17:14 ` Kevin Rodgers @ 2003-08-13 5:14 ` Jussi Piitulainen 0 siblings, 0 replies; 14+ messages in thread From: Jussi Piitulainen @ 2003-08-13 5:14 UTC (permalink / raw) Kevin Rodgers writes: > Sorry, I was trying to show a general form via ellipses. A concrete > example would be > > (define-key key-translation-map [?\M-7] "|") Ah. That works all right, but when 7 is replaced with a letter outside ASCII, it does not work. > I don't know why those wouldn't work [] unless there are > keyboard/buffer/file coding issues. You might want to use the octal > encoding instead: > > [?\M-\241] ; meta inverted exclamation point That's again an interesting suggestion. I notice that ?\M-{inv excl} and ?\M-\241 have different values, and C-x = shows an {inv excl} in the buffer as octal 4241, not just 241. A coding issue, then, maybe, and yes, the following indeed seems to do the trick: (define-key key-translation-map [?\M-\366] "*") Octal 366 is Latin-1 for one of the letters I have a key for, the letters shows as octal 4366 in the buffer, ?\M-{letter itself} does not identify it for binding purposes, but ?\M-\366 seems to work. Thank you. > I don't understand Emacs' encoding scheme at all, nor do I want to. Heh. >> I think I'll use the numbers for these few keys. > > The "Character Type" node of the Emacs Lisp manual strongly > discourages that: Of course, and I agree, but I was failing to find any other way to make it work. That octal syntax seems to do it, and all in standard Latin-1, too, so I will change to use that instead. -- Jussi ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 2003-08-11 20:29 ` Kevin Rodgers 2003-08-12 8:26 ` Jussi Piitulainen @ 2003-08-15 13:05 ` Kai Großjohann 1 sibling, 0 replies; 14+ messages in thread From: Kai Großjohann @ 2003-08-15 13:05 UTC (permalink / raw) Kevin Rodgers <ihs_4664@yahoo.com> writes: > So you need to use the vector notation for keys containing meta-modified > non-ASCII characters: > > (define-key key-translation-map [?\M- ...] ...) I prefer the kbd syntax. You write (kbd "...") instead of [?\M-...] or suchlike. The advantage of the kbd syntax is that it is like the output of C-h c, C-h k, C-h l and friends. IMHO this is a very strong advantage. I'm sorry if I'm tiring you with this advertisement. -- Two cafe au lait please, but without milk. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? [not found] ` <mailman.235.1060378027.29551.help-gnu-emacs@gnu.org> 2003-08-11 18:10 ` Jussi Piitulainen @ 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> 1 sibling, 2 replies; 14+ messages in thread From: Kevin Rodgers @ 2003-08-11 19:54 UTC (permalink / raw) Ehud Karni wrote: >On Fri, 08 Aug 2003 12:51:59 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: >>Ehud Karni wrote: >>>On my system it shows for Alt-7: >>> Character typed is "7", (octal=20000067, decimal=4194359, hexa=400037) >> >>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. >> > > I did evaluate ?\M-7 and I get the same result (-134217673) as you. > It is NOT what my function returns (4194359) !!! Hmmm, here's what I get: Character typed is (No description), (octal=37000000067, decimal=-134217673, hexa=f8000037) >>>So if you do: >>> (define-key key-translation-map [4194359] "|") >> >>key-translation-map takes character arguments, not (vector or string) keys: > > Not true, see below. ... >>>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)) >>> >>key-translation-map is now a char-table, not a keymap (see the Translating Input >>node of the Emacs Lisp manual). > > I don't know which Emacs are you using, I checked it on 21.2, 21.3. and > 21.3.50 (CVS HEAD version). 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. Ah, you're correct of course! Sorry about that. But the manual says that "The intent of `key-translation-map' is for users to map one character set to another", so doesn't this count as abuse (rather than use) of that feature? It seems odd to me -- backwards, even -- that keyboard-translate-table can't handle all the events (such as meta-modified characters) that the keyboard can generate, but that key-translation-map can (even though it is intended to map only characters). -- Kevin Rodgers ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Alt as meta, except for certain keys, how? 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> 1 sibling, 0 replies; 14+ messages in thread From: Ehud Karni @ 2003-08-12 11:13 UTC (permalink / raw) Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 11 Aug 2003 13:54:09 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote: > > But the manual says that "The intent of `key-translation-map' is for > users to map one character set to another", so doesn't this count as > abuse (rather than use) of that feature? It seems odd to me -- > backwards, even -- that keyboard-translate-table can't handle all the > events (such as meta-modified characters) that the keyboard can > generate, but that key-translation-map can (even though it is intended > to map only characters). I don't think this is "abuse" of `key-translation-map' because the original poster is working on a "foreign" keyboard (finish). He has dead keys and wants a work around for these. He has devised his own way to do this, I just helped him with the map to use. I think this map can be used by "users" as well as "developers" (packages). Ehud. - -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ mailto:ehud@unix.mvs.co.il Better Safe Than Sorry -----BEGIN PGP SIGNATURE----- Comment: use http://www.keyserver.net/ to get my key (and others) iD8DBQE/OMvwLFvTvpjqOY0RAtxeAJ4wpNSNCq4kwj7y3SnLHyN9dc23oQCeNj8a PcFhBkvM0UUvFVGtvJflCqM= =Kra5 -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.336.1060687053.29551.help-gnu-emacs@gnu.org>]
* Re: Alt as meta, except for certain keys, how? [not found] ` <mailman.336.1060687053.29551.help-gnu-emacs@gnu.org> @ 2003-08-12 18:16 ` Jussi Piitulainen 0 siblings, 0 replies; 14+ messages in thread From: Jussi Piitulainen @ 2003-08-12 18:16 UTC (permalink / raw) (I think I said R when I meant to say F. At least I don't see my latest followup here.) I have usable implementations now, both ways. I made them available at <http://homepage.mac.com/jpiitula/emacs/index.html>. There is nothing else there and the whole URL seems needed. They are initialization files that set a certain Carbon Emacs binary, version 21.3.50.6, for Finnish Apple keyboards with Alt as Meta except for the numeric row and a couple of letters, with the Mac OS X Monaco font for Latin-1. May or may not work, with or without modifications. -- Jussi ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2003-08-15 13:05 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).