* confusion with defining keys
@ 2014-06-11 5:05 lee
2014-06-11 8:21 ` kastian
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: lee @ 2014-06-11 5:05 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
how come that sometimes keys cannot be defined (for X11 frames)? I'm
trying to define something for 'undo, like:
(global-set-key "\C-ä" 'undo)
This doesn't define the key binding. Same goes for C-#. Using 'kbd
doesn't work, either.
What might be the problem with this, and how can I define such keys?
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 5:05 confusion with defining keys lee
@ 2014-06-11 8:21 ` kastian
2014-06-11 11:30 ` Nicolas Richard
` (2 subsequent siblings)
3 siblings, 0 replies; 15+ messages in thread
From: kastian @ 2014-06-11 8:21 UTC (permalink / raw)
To: help-gnu-emacs
Hello
On Wed, Jun 11, 2014 at 07:05:07AM +0200, lee wrote:
> Hi,
> how come that sometimes keys cannot be defined (for X11 frames)? I'm
> trying to define something for 'undo, like:
> (global-set-key "\C-ä" 'undo)
> This doesn't define the key binding. Same goes for C-#. Using 'kbd
> doesn't work, either.
> What might be the problem with this, and how can I define such keys?
I've similar problem with russian letters, but
(global-set-key [?\M-й] 'function)
works well.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 5:05 confusion with defining keys lee
2014-06-11 8:21 ` kastian
@ 2014-06-11 11:30 ` Nicolas Richard
2014-06-12 5:28 ` lee
2014-06-11 11:53 ` Stefan Monnier
[not found] ` <mailman.3403.1402487643.1147.help-gnu-emacs@gnu.org>
3 siblings, 1 reply; 15+ messages in thread
From: Nicolas Richard @ 2014-06-11 11:30 UTC (permalink / raw)
To: help-gnu-emacs
lee <lee@yun.yagibdah.de> writes:
> (global-set-key "\C-ä" 'undo)
>
>
> This doesn't define the key binding. Same goes for C-#. Using 'kbd
> doesn't work, either.
(global-set-key (kbd "C-ä") 'undo) works for me.
--
Nico.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 5:05 confusion with defining keys lee
2014-06-11 8:21 ` kastian
2014-06-11 11:30 ` Nicolas Richard
@ 2014-06-11 11:53 ` Stefan Monnier
2014-06-12 5:40 ` lee
[not found] ` <mailman.3403.1402487643.1147.help-gnu-emacs@gnu.org>
3 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2014-06-11 11:53 UTC (permalink / raw)
To: help-gnu-emacs
> (global-set-key "\C-ä" 'undo)
This should ideally signal an error, because "\C-ä" is an invalid string
(a string can only contains chars and C-ä is not a char but
a "char combined with a modifier"). For historical reasons this doesn't
signal an error, but it doesn't do what you want. Use either (kbd
"C-ä") or [?\C-ä].
In general, I recommend never to use the plain "..." notation for key
sequences: it made sense back in the Emacs-18 days when it was
introduced, but it's been a "legacy" since Emacs-19.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
[not found] ` <mailman.3403.1402487643.1147.help-gnu-emacs@gnu.org>
@ 2014-06-11 14:32 ` Emanuel Berg
2014-06-12 0:56 ` Stefan Monnier
[not found] ` <mailman.3459.1402534627.1147.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-11 14:32 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> In general, I recommend never to use the plain "..."
> notation for key sequences: it made sense back in the
> Emacs-18 days when it was introduced, but it's been a
> "legacy" since Emacs-19.
Really? Why is that?
I happen use "..." all the time except for - let's
see... - keys that I defined myself, as for example:
(define-key input-decode-map [?\u010F] [C-semi-colon])
(global-set-key (kbd "<C-semi-colon>") 'string-to-cmd)
The reason I do "..." is simply it is easier to
type. So if there is some gain switching I'll do that,
of course.
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 14:32 ` Emanuel Berg
@ 2014-06-12 0:56 ` Stefan Monnier
[not found] ` <mailman.3459.1402534627.1147.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2014-06-12 0:56 UTC (permalink / raw)
To: help-gnu-emacs
> The reason I do "..." is simply it is easier to type. So if there is
> some gain switching I'll do that, of course.
Using [...] or (kbd "...") gains you the fact that these work for *any*
key, whereas "..." only works in some cases.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
[not found] ` <mailman.3459.1402534627.1147.help-gnu-emacs@gnu.org>
@ 2014-06-12 1:39 ` Emanuel Berg
2014-06-12 1:49 ` Emanuel Berg
` (2 more replies)
0 siblings, 3 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-12 1:39 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> The reason I do "..." is simply it is easier to
>> type. So if there is some gain switching I'll do
>> that, of course.
>
> Using [...] or (kbd "...") gains you the fact that
> these work for *any* key, whereas "..." only works in
> some cases.
It would seem there are some exceptions to that rule!
Check out the below experimentation:
(global-set-key (kbd "RET") 'newline-and-indent) ; works
(global-set-key "\r" 'newline-and-indent) ; works
(global-set-key [RET] 'newline-and-indent) ; (error "To bind the key RET, use \"\\r\", not [RET]")
(global-set-key (kbd "M-SPC") 'eat-space) ; works
(global-set-key "\M- " 'eat-space) ; works
(global-set-key [M-SPC] 'eat-space) ; (error "To bind the key M-SPC, use \"\\M- \", not [M-SPC]")
Also, with the [...], it seems you shouldn't include
the <...> for custom keys - which is good, because you
don't define them that way, so it is only confusing
having to use that later:
(define-key input-decode-map [?\u010F] [C-semi-colon])
(global-set-key [C-semi-colon] 'string-to-cmd)
(global-unset-key (kbd "<C-semi-colon>")) ; everything works
A (minor) drawback with [...] is less readability as
the keys don't get the font-lock-string-face -
customizable, of course (but watch out I guess so not
lots of [stuff] get affected).
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-12 1:39 ` Emanuel Berg
@ 2014-06-12 1:49 ` Emanuel Berg
2014-06-12 2:48 ` Stefan Monnier
[not found] ` <mailman.3470.1402541342.1147.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-12 1:49 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg <embe8573@student.uu.se> writes:
> Check out the below experimentation:
>
> (global-set-key (kbd "RET") 'newline-and-indent) ;
> works (global-set-key "\r" 'newline-and-indent) ; works
> (global-set-key [RET] 'newline-and-indent) ; (error "To
> bind the key RET, use \"\\r\", not [RET]")
>
> (global-set-key (kbd "M-SPC") 'eat-space) ; works
> (global-set-key "\M- " 'eat-space) ; works
> (global-set-key [M-SPC] 'eat-space) ; (error "To bind
> the key M-SPC, use \"\\M- \", not [M-SPC]")
TAB also behaves like that (should be "\t") as well as
different combinations, e.g., "\M-\r" instead of
[M-R**] (but (kbd "M-RET") is fine).
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-12 1:39 ` Emanuel Berg
2014-06-12 1:49 ` Emanuel Berg
@ 2014-06-12 2:48 ` Stefan Monnier
[not found] ` <mailman.3470.1402541342.1147.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2014-06-12 2:48 UTC (permalink / raw)
To: help-gnu-emacs
> It would seem there are some exceptions to that rule!
Nope, you just misunderstood the rule.
> (global-set-key [RET] 'newline-and-indent) ; (error "To bind the key
> RET, use \"\\r\", not [RET]")
What you write between [...] does not use the same syntax as what's
written in "..." (and neither is the same as what's written in (kbd
"...")).
E.g. instead of the above, you want
(global-set-key [?\r] 'newline-and-indent)
Similarly [M-SPC] should be [?\M-\s]
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 11:30 ` Nicolas Richard
@ 2014-06-12 5:28 ` lee
0 siblings, 0 replies; 15+ messages in thread
From: lee @ 2014-06-12 5:28 UTC (permalink / raw)
To: help-gnu-emacs
Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:
> lee <lee@yun.yagibdah.de> writes:
>> (global-set-key "\C-ä" 'undo)
>>
>>
>> This doesn't define the key binding. Same goes for C-#. Using 'kbd
>> doesn't work, either.
>
> (global-set-key (kbd "C-ä") 'undo) works for me.
Yay, that works here, too, thanks :)
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-11 11:53 ` Stefan Monnier
@ 2014-06-12 5:40 ` lee
0 siblings, 0 replies; 15+ messages in thread
From: lee @ 2014-06-12 5:40 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (global-set-key "\C-ä" 'undo)
>
> This should ideally signal an error, because "\C-ä" is an invalid string
> (a string can only contains chars and C-ä is not a char but
> a "char combined with a modifier"). For historical reasons this doesn't
> signal an error, but it doesn't do what you want. Use either (kbd
> "C-ä") or [?\C-ä].
> In general, I recommend never to use the plain "..." notation for key
> sequences: it made sense back in the Emacs-18 days when it was
> introduced, but it's been a "legacy" since Emacs-19.
Hm, I think I tried (kbd "<C-ä>"), which didn't work. How is one
supposed to know what to use? I'd never think of [?\C-ä] ...
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
[not found] ` <mailman.3470.1402541342.1147.help-gnu-emacs@gnu.org>
@ 2014-06-12 13:59 ` Emanuel Berg
2014-06-12 14:17 ` Emanuel Berg
1 sibling, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-12 13:59 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> What you write between [...] does not use the same
> syntax as what's written in "..." (and neither is the
> same as what's written in (kbd "...")).
OK!
In a way it makes sense for three different syntaxes as
otherwise why have three different ways of delimiting
it?
But in another way why does it make sense to have three
different syntaxes to begin with?
Is this something that happened along the way?
I guess the (kbd "...") is the most Lispic but I like
compact syntax - and [...] makes it look like a button
at that! Only you have to add a font-lock rule to get a
highlight...
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
[not found] ` <mailman.3470.1402541342.1147.help-gnu-emacs@gnu.org>
2014-06-12 13:59 ` Emanuel Berg
@ 2014-06-12 14:17 ` Emanuel Berg
2014-06-12 14:52 ` Stefan Monnier
[not found] ` <mailman.3498.1402584764.1147.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-12 14:17 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> What you write between [...] does not use the same
> syntax as what's written in "..." (and neither is the
> same as what's written in (kbd "...")).
All of those seem to work:
(global-set-key (kbd "M-RET") 'find-file-at-line) ; 1
(global-set-key "\M-\r" 'find-file-at-line) ; 2
(global-set-key [?\M-\r] 'find-file-at-line) ; 3
But another thing, when you do
(global-set-key [M-RET] 'find-file-at-line)
it says
(error "To bind the key M-RET, use \"\\M-\\r\", not [M-RET]")
- that should indicate "\M-\r", right? (example 2)
So why does the [...] syntax recommend the "..."
syntax, if the "..." is the one outdated/incomplete and
[...] the one modern/universal?
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
2014-06-12 14:17 ` Emanuel Berg
@ 2014-06-12 14:52 ` Stefan Monnier
[not found] ` <mailman.3498.1402584764.1147.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2014-06-12 14:52 UTC (permalink / raw)
To: help-gnu-emacs
> So why does the [...] syntax recommend the "..."
> syntax, if the "..." is the one outdated/incomplete and
> [...] the one modern/universal?
That's just a bug.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: confusion with defining keys
[not found] ` <mailman.3498.1402584764.1147.help-gnu-emacs@gnu.org>
@ 2014-06-12 22:57 ` Emanuel Berg
0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2014-06-12 22:57 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> So why does the [...] syntax recommend the "..."
>> syntax, if the "..." is the one outdated/incomplete
>> and [...] the one modern/universal?
>
> That's just a bug.
OK, I reported it: #17766.
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-06-12 22:57 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-11 5:05 confusion with defining keys lee
2014-06-11 8:21 ` kastian
2014-06-11 11:30 ` Nicolas Richard
2014-06-12 5:28 ` lee
2014-06-11 11:53 ` Stefan Monnier
2014-06-12 5:40 ` lee
[not found] ` <mailman.3403.1402487643.1147.help-gnu-emacs@gnu.org>
2014-06-11 14:32 ` Emanuel Berg
2014-06-12 0:56 ` Stefan Monnier
[not found] ` <mailman.3459.1402534627.1147.help-gnu-emacs@gnu.org>
2014-06-12 1:39 ` Emanuel Berg
2014-06-12 1:49 ` Emanuel Berg
2014-06-12 2:48 ` Stefan Monnier
[not found] ` <mailman.3470.1402541342.1147.help-gnu-emacs@gnu.org>
2014-06-12 13:59 ` Emanuel Berg
2014-06-12 14:17 ` Emanuel Berg
2014-06-12 14:52 ` Stefan Monnier
[not found] ` <mailman.3498.1402584764.1147.help-gnu-emacs@gnu.org>
2014-06-12 22:57 ` Emanuel Berg
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).