* Translating keys
@ 2005-10-16 19:58 Elena Garrulo
2005-10-16 20:18 ` Peter Dyballa
` (3 more replies)
0 siblings, 4 replies; 17+ messages in thread
From: Elena Garrulo @ 2005-10-16 19:58 UTC (permalink / raw)
Hello,
I'd like to translate some keys in a mode dependent way. For example, when in c-mode, the key which
prints "ò" should print "{"; when in text-mode should print the original character. Since the
translation should be mode dependent, keyboard-translate is not a viable option. I've tried:
(local-set-key "ò" (lambda () (interactive) (insert "{")))
but it doesn't work. It works with other keys, for example:
(local-set-key "a" (lambda () (interactive) (insert "{")))
I think I should know the code generated by the key. Is there a way?
Anyway, the "insert" function is not useful, because the generated character does not behave like
the original one (I've electric C enabled and the { generated by "insert" is not recognized as
electric; the original { is).
Any help?
Thanks.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-16 19:58 Translating keys Elena Garrulo
@ 2005-10-16 20:18 ` Peter Dyballa
[not found] ` <mailman.11540.1129493899.20277.help-gnu-emacs@gnu.org>
` (2 subsequent siblings)
3 siblings, 0 replies; 17+ messages in thread
From: Peter Dyballa @ 2005-10-16 20:18 UTC (permalink / raw)
Cc: help-gnu-emacs
Am 16.10.2005 um 21:58 schrieb Elena Garrulo:
> I'd like to translate some keys in a mode dependent way. For example,
> when in c-mode
Have you checked c-mode-map, 'a sparse keymap used by C mode?'
--
Greetings
Pete
"Email is a wonderful thing for people whose role in life is to be on
top of things. But not for me; my role is to be on the bottom of
things. What I do takes long hours of studying and uninterruptible
concentration." -Donald Knuth
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
[not found] ` <mailman.11540.1129493899.20277.help-gnu-emacs@gnu.org>
@ 2005-10-16 22:07 ` Elena Garrulo
2005-10-17 0:07 ` Peter Dyballa
0 siblings, 1 reply; 17+ messages in thread
From: Elena Garrulo @ 2005-10-16 22:07 UTC (permalink / raw)
Peter Dyballa wrote:
> Have you checked c-mode-map, 'a sparse keymap used by C mode?'
Thank you, now I have the "electric" behaviour. Still, I cannot remap
the extended ASCII "ò" character (225 octal). Neither this:
(define-key c-mode-map "ò" 'c-electric-brace)
nor this:
(define-key c-mode-map "\225" 'c-electric-brace)
work. Standard ASCII characters do work:
(define-key c-mode-map "k" 'c-electric-brace) ;; OK
(define-key c-mode-map "\153" 'c-electric-brace) ;; OK
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-16 22:07 ` Elena Garrulo
@ 2005-10-17 0:07 ` Peter Dyballa
0 siblings, 0 replies; 17+ messages in thread
From: Peter Dyballa @ 2005-10-17 0:07 UTC (permalink / raw)
Cc: help-gnu-emacs
Am 17.10.2005 um 00:07 schrieb Elena Garrulo:
> (define-key c-mode-map "ò" 'c-electric-brace)
>
> nor this:
>
> (define-key c-mode-map "\225" 'c-electric-brace)
>
> work. Standard ASCII characters do work:
>
From where do you know it's \225? Did you check this with C-u C-x = in
*scratch* buffer? Can you make GNU Emacs to do a read-event or
read-string? Could be there is a simple mismatch between what you think
is right and what the keyboard produces ...
--
Greetings
Pete
When in doubt, use brute force.
-- Ken Thompson
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-16 19:58 Translating keys Elena Garrulo
2005-10-16 20:18 ` Peter Dyballa
[not found] ` <mailman.11540.1129493899.20277.help-gnu-emacs@gnu.org>
@ 2005-10-17 2:10 ` Pascal Bourguignon
2005-10-17 10:48 ` Mounir AITTAHAR
2005-10-17 3:03 ` Translating keys Stefan Monnier
3 siblings, 1 reply; 17+ messages in thread
From: Pascal Bourguignon @ 2005-10-17 2:10 UTC (permalink / raw)
Elena Garrulo <egarrulo@muchomail.com> writes:
> Hello,
>
> I'd like to translate some keys in a mode dependent way. For
> example, when in c-mode, the key which prints "ò" should print "{";
> when in text-mode should print the original character. Since the
> translation should be mode dependent, keyboard-translate is not a
> viable option. I've tried:
>
> (local-set-key "ò" (lambda () (interactive) (insert "{")))
If you want to translate keys why do you use local-set-key?
Use: keyboard-translate !
Now, if what you really want is to bind a function to a key, then use
local-set-key: (local-set-key (kbd "A-o") ...) or whatever key
combination you use to get 'ò'.
A- = Alt
C- = Control
M- = Meta
S- = Shift
s- = Super
H- = Hyper
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-16 19:58 Translating keys Elena Garrulo
` (2 preceding siblings ...)
2005-10-17 2:10 ` Pascal Bourguignon
@ 2005-10-17 3:03 ` Stefan Monnier
3 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2005-10-17 3:03 UTC (permalink / raw)
> (local-set-key "ò" (lambda () (interactive) (insert "{")))
> but it doesn't work.
> I think I should know the code generated by the key. Is there a way?
There are many different ò. And the one sent by your keyboard's key is not
always the same depending on the version of Emacs, and the one read from
your .emacs is not always the same either depending on your locale, your
Emacs settings and maybe a -*- coding -*- cookie in the file.
Try M-: (read-event) RET and then hit your ò key. It'll return the code
Elisp receives in response to this key (e.g. 2290). You can then bind it
with (local-set-key [2290] "{").
> Anyway, the "insert" function is not useful, because the generated character
> does not behave like the original one (I've electric C enabled and the
> { generated by "insert" is not recognized as electric; the original { is).
Try (local-set-key "ò" "{"). The "{" part is a keyboard macro which tells
Emacs to behave as if you had typed the key sequence "{" (i.e. composed of
a single key).
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-17 2:10 ` Pascal Bourguignon
@ 2005-10-17 10:48 ` Mounir AITTAHAR
2005-10-17 13:27 ` Pascal Bourguignon
2005-10-19 23:09 ` Stefan Monnier
0 siblings, 2 replies; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-17 10:48 UTC (permalink / raw)
> Now, if what you really want is to bind a function to a key, then use
> local-set-key: (local-set-key (kbd "A-o") ...) or whatever key
> combination you use to get 'ò'.
Hi,
As told in another thread(1), (local-set-key (kbd "é") ...) seems not to
work if non-ASCII characters are entered by pressing one button, their
button. It looks like these kind of keys cannot be reached by a local or
global binding.
I allowed myself to tell the problem in this thread cause it is a
related subjetc and it seems you are a french user (and you may use a
french keyboard)
Do you know this problem and how to solve it ?
--
Mounir AITTAHAR
(1) /Non-ASCII characters Key binding (emacs 21.4)/
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-17 10:48 ` Mounir AITTAHAR
@ 2005-10-17 13:27 ` Pascal Bourguignon
2005-10-17 15:15 ` Mounir AITTAHAR
2005-10-19 23:09 ` Stefan Monnier
1 sibling, 1 reply; 17+ messages in thread
From: Pascal Bourguignon @ 2005-10-17 13:27 UTC (permalink / raw)
Mounir AITTAHAR <mounir.aittahar@fri.fr> writes:
>> Now, if what you really want is to bind a function to a key, then use
>> local-set-key: (local-set-key (kbd "A-o") ...) or whatever key
>> combination you use to get 'ò'.
>
> Hi,
>
> As told in another thread(1), (local-set-key (kbd "é") ...) seems not
> to work if non-ASCII characters are entered by pressing one button,
> their button. It looks like these kind of keys cannot be reached by a
> local or global binding.
At least in emacs-version "22.0.50.1", it works perfectly, as well for
a directly é typed on a MacOSX AZERTY, or using C-x 8 ' e
> I allowed myself to tell the problem in this thread cause it is a
> related subjetc and it seems you are a french user (and you may use a
> french keyboard)
I am, but I never use this AZERTY monstruosity.
> Do you know this problem and how to solve it ?
(local-set-key (kbd "é") (lambda()(interactive)(insert "\ngot e acute\n")))
--
__Pascal Bourguignon__ http://www.informatimago.com/
In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-17 13:27 ` Pascal Bourguignon
@ 2005-10-17 15:15 ` Mounir AITTAHAR
2005-10-18 14:52 ` Mounir AITTAHAR
0 siblings, 1 reply; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-17 15:15 UTC (permalink / raw)
>>As told in another thread(1), (local-set-key (kbd "é") ...) seems not
>>to work if non-ASCII characters are entered by pressing one button,
>>Do you know this problem and how to solve it ?
> (local-set-key (kbd "é") (lambda()(interactive)(insert "\ngot e acute\n")))
Nope, this line doesn't work : when I type "é", I don't get "got e
acute", but "é".
I've recently tried this bind on *true* console-mode emacs, it works. I
wonder if this not a graphical libraries problem.
Notice that in emacs 20.7 (with-xlib compiled version) non-ascii key
bindings worked.
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-17 15:15 ` Mounir AITTAHAR
@ 2005-10-18 14:52 ` Mounir AITTAHAR
2005-10-18 16:50 ` Pascal Bourguignon
0 siblings, 1 reply; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-18 14:52 UTC (permalink / raw)
Okay, emacs -nw (with "(set-keyboard-system latin-1)" + Xterm Meta
sends escape) and emacs/X11 have the same behaviour when type "é" in a
Azerty keyboard.
So this line :
(local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
Or this one :
(local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
don't insert e acute. :(
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-18 14:52 ` Mounir AITTAHAR
@ 2005-10-18 16:50 ` Pascal Bourguignon
2005-10-19 8:29 ` Mounir AITTAHAR
0 siblings, 1 reply; 17+ messages in thread
From: Pascal Bourguignon @ 2005-10-18 16:50 UTC (permalink / raw)
"Mounir AITTAHAR" <downwater@free.fr> writes:
> Okay, emacs -nw (with "(set-keyboard-system latin-1)" + Xterm Meta
> sends escape) and emacs/X11 have the same behaviour when type "é" in a
> Azerty keyboard.
>
> So this line :
> (local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
>
> Or this one :
> (local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
>
> don't insert e acute. :(
Of course not.
I don't see the difference between the two lines:
> (local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
> (local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
After:
(local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
Type: C-x C-e C-x 8 ' e
Or perhaps, if the mode you're using rebinds C-x C-e:
M-x eval-last-sexp RET C-x 8 ' e
--
"Debugging? Klingons do not debug! Our software does not coddle the
weak."
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-18 16:50 ` Pascal Bourguignon
@ 2005-10-19 8:29 ` Mounir AITTAHAR
0 siblings, 0 replies; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-19 8:29 UTC (permalink / raw)
> I don't see the difference between the two lines:
>>(local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
>>(local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
Whoops :-( Don't remember my thoughts when I wrote this
> (local-set-key (kbd "é") (lambda()(interactive)(insert "e acute")))
>
> Type: C-x C-e C-x 8 ' e
Yes, it works in that case. I suppose now that kbd translate "é" into
C-x C-e C-x 8 (bound to "keyboard macro" iso-transl-e-acute even if rebound)
Let's continue in /Non-ASCII characters Key binding (emacs 21.4)/
thread, which fit more for the way of resolution I might found.
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-17 10:48 ` Mounir AITTAHAR
2005-10-17 13:27 ` Pascal Bourguignon
@ 2005-10-19 23:09 ` Stefan Monnier
2005-10-20 8:22 ` Mounir AITTAHAR
2005-10-20 8:38 ` Mounir AITTAHAR
1 sibling, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2005-10-19 23:09 UTC (permalink / raw)
> As told in another thread(1), (local-set-key (kbd "é") ...) seems not to
> work if non-ASCII characters are entered by pressing one button, their
Check some of those threads that have been running these days.
I've recently posted an explanation of the problem along with solutions.
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-19 23:09 ` Stefan Monnier
@ 2005-10-20 8:22 ` Mounir AITTAHAR
2005-10-20 9:09 ` Mounir AITTAHAR
2005-10-20 8:38 ` Mounir AITTAHAR
1 sibling, 1 reply; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-20 8:22 UTC (permalink / raw)
> Check some of those threads that have been running these days.
> I've recently posted an explanation of the problem along with solutions.
Do you mean in "Non ascii key bindings ?" Yep, I've read. And answered :)
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-19 23:09 ` Stefan Monnier
2005-10-20 8:22 ` Mounir AITTAHAR
@ 2005-10-20 8:38 ` Mounir AITTAHAR
2005-10-21 8:37 ` Translating keys [solved] Mounir AITTAHAR
1 sibling, 1 reply; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-20 8:38 UTC (permalink / raw)
> Check some of those threads that have been running these days.
> I've recently posted an explanation of the problem along with solutions.
My server news is really rubbish.
By Google, I've read your message (hope this is this one you told about)_:
> Try M-: (read-event) RET and then hit your ò key. It'll return the code
> Elisp receives in response to this key (e.g. 2290). You can then bind it
> with (local-set-key [2290] "{").
Yep, it works (on my keyboard this is 3945 for "é"). I've found this
solution (cf "Non-ascii key binding..." thread) through
(read-key-sequence "").
Also I've remarked this :
(kbd "é") => 233
(multibyte-char-to-unibyte 3945) => 233
(unibyte-char-to-multibyte 233) => 2281
(- (unibyte-char-to-multibyte 233) (multibyte-char-to-unibyte 3945)) => 2048
I remember to have got 2048 with a lisp function which returns the value
to add to a unibyte to get the multibyte sequence... But what function ?
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys
2005-10-20 8:22 ` Mounir AITTAHAR
@ 2005-10-20 9:09 ` Mounir AITTAHAR
0 siblings, 0 replies; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-20 9:09 UTC (permalink / raw)
I'm fed up with this 9telecom news server.
> Check some of those threads that have been running these days.
> I've recently posted an explanation of the problem along with solutions.
My server news is really rubbish.
By Google, I've read your message (hope this is this one you told
about)_:
> Try M-: (read-event) RET and then hit your ò key. It'll return the code
> Elisp receives in response to this key (e.g. 2290). You can then bind it
> with (local-set-key [2290] "{").
Yep, it works (on my keyboard this is 3945 for "é"). I've found this
solution (cf "Non-ascii key binding..." thread) through
(read-key-sequence "").
Also I've remarked this :
(kbd "é") => 233
(multibyte-char-to-unibyte 3945) => 233
(unibyte-char-to-multibyte 233) => 2281
(- (unibyte-char-to-multibyte 233) (multibyte-char-to-unibyte 3945)) =>
2048
nonascii-insert-offset => 2048
Interesting... I have now what i need. Except the way to make a
difference between console and (X/Xterm) mode.
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Translating keys [solved]
2005-10-20 8:38 ` Mounir AITTAHAR
@ 2005-10-21 8:37 ` Mounir AITTAHAR
0 siblings, 0 replies; 17+ messages in thread
From: Mounir AITTAHAR @ 2005-10-21 8:37 UTC (permalink / raw)
> (read-event) or (read-key-sequence "") => typing "é" give 3945
> (kbd "é") => 233
> (multibyte-char-to-unibyte 3945) => 233
> (unibyte-char-to-multibyte 233) => 2281
But with :
(unify-8859-on-encoding-mode 1)
(unify-8859-on-decoding-mode 1)
> (read-event) or (read-key-sequence "") => typing "é" give 2281
> (kbd "é") => 233
> (multibyte-char-to-unibyte 3945) => 233
> (unibyte-char-to-multibyte 233) => 2281
Ok ! I think it was a problem of 8859 encoding unification. But don't
know definitely why : locale pb or emacs-related...
--
Mounir AITTAHAR
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2005-10-21 8:37 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-16 19:58 Translating keys Elena Garrulo
2005-10-16 20:18 ` Peter Dyballa
[not found] ` <mailman.11540.1129493899.20277.help-gnu-emacs@gnu.org>
2005-10-16 22:07 ` Elena Garrulo
2005-10-17 0:07 ` Peter Dyballa
2005-10-17 2:10 ` Pascal Bourguignon
2005-10-17 10:48 ` Mounir AITTAHAR
2005-10-17 13:27 ` Pascal Bourguignon
2005-10-17 15:15 ` Mounir AITTAHAR
2005-10-18 14:52 ` Mounir AITTAHAR
2005-10-18 16:50 ` Pascal Bourguignon
2005-10-19 8:29 ` Mounir AITTAHAR
2005-10-19 23:09 ` Stefan Monnier
2005-10-20 8:22 ` Mounir AITTAHAR
2005-10-20 9:09 ` Mounir AITTAHAR
2005-10-20 8:38 ` Mounir AITTAHAR
2005-10-21 8:37 ` Translating keys [solved] Mounir AITTAHAR
2005-10-17 3:03 ` Translating keys Stefan Monnier
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).