all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Difference between GUI/terminal when using "kbd" macro
@ 2013-02-18 16:49 Felix Crux
  2013-02-18 19:12 ` Jambunathan K
  2013-02-19 13:32 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Felix Crux @ 2013-02-18 16:49 UTC (permalink / raw
  To: help-gnu-emacs

Hello,

I recently ran across a perplexing problem that I can't find the answer
to in the documentation.

The following snippet in my init file works just as one would expect in
both graphical (GTK+) and terminal instances of Emacs:

  (global-set-key [?\C-x ?\e] 'save-buffers-kill-emacs)

However, this version, which I thought to be identical (but more readable),
only works in graphical sessions:

  (global-set-key (kbd "C-x <escape>") 'save-buffers-kill-emacs)

When attempting to use it in a terminal, the status line simply displays
"C-x ESC-", as though waiting for more input.

Invoking emacs-version gives me "GNU Emacs 23.4.1 (x86_64-pc-linux-gnu,
GTK+ Version 2.24.10) of 2012-09-08 on trouble, modified by Debian".

I'd be most grateful if someone would point me in the right direction to
understand this. Thank you,

Felix C.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Difference between GUI/terminal when using "kbd" macro
  2013-02-18 16:49 Difference between GUI/terminal when using "kbd" macro Felix Crux
@ 2013-02-18 19:12 ` Jambunathan K
  2013-02-18 19:33   ` Felix Crux
  2013-02-19 13:32 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Jambunathan K @ 2013-02-18 19:12 UTC (permalink / raw
  To: Felix Crux; +Cc: help-gnu-emacs


May be C-x ESC C-h will tell you what is behind the curtain.  Forgive
me, if it doesn't help, for I know not what I am talking.  Just a
suggestion.


Felix Crux <felixc@felixcrux.com> writes:

> Hello,
>
> I recently ran across a perplexing problem that I can't find the answer
> to in the documentation.
>
> The following snippet in my init file works just as one would expect in
> both graphical (GTK+) and terminal instances of Emacs:
>
>   (global-set-key [?\C-x ?\e] 'save-buffers-kill-emacs)
>
> However, this version, which I thought to be identical (but more readable),
> only works in graphical sessions:
>
>   (global-set-key (kbd "C-x <escape>") 'save-buffers-kill-emacs)
>
> When attempting to use it in a terminal, the status line simply displays
> "C-x ESC-", as though waiting for more input.
>
> Invoking emacs-version gives me "GNU Emacs 23.4.1 (x86_64-pc-linux-gnu,
> GTK+ Version 2.24.10) of 2012-09-08 on trouble, modified by Debian".
>
> I'd be most grateful if someone would point me in the right direction to
> understand this. Thank you,
>
> Felix C.
>
>

-- 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Difference between GUI/terminal when using "kbd" macro
  2013-02-18 19:12 ` Jambunathan K
@ 2013-02-18 19:33   ` Felix Crux
  2013-02-19 15:58     ` Kevin Rodgers
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Crux @ 2013-02-18 19:33 UTC (permalink / raw
  To: Jambunathan K; +Cc: help-gnu-emacs

Thanks for the suggestion; it actually led to an interesting discovery:

With the keybinding set to (kbd "C-x <escape>"), running "C-x <escape> C-h"
(in a terminal session, since in a GUI one it quits Emacs) shows the following:

  Global Bindings Starting With C-x ESC:
  key             binding
  ---             -------
  C-x ESC ESC     repeat-complex-command

This got me thinking about the fact that the help system is calling it "ESC",
not "<escape>", and wondering about whether that is significant.

I then tried changing the binding to (kbd "C-x ESC"), which actually works in
both graphical and terminal sessions!

In conclusion, it looks as though there is a difference between "ESC" and
"<escape>", at least as far as the "kbd" macro is concerned. I don't know
enough about the topic to be sure, but I would speculate that "<escape>" is
some sort of special meta-character being sent by the X window system, while
"ESC" is the lower-level key value.

Very interesting stuff; and it now lets me use the more readable form, too!
I'm still quite curious about the discrepancy, but at least the original
problem is solved. Thank you!

Felix C.

On Mon, Feb 18, 2013 at 2:12 PM, Jambunathan K <kjambunathan@gmail.com> wrote:
>
> May be C-x ESC C-h will tell you what is behind the curtain.  Forgive
> me, if it doesn't help, for I know not what I am talking.  Just a
> suggestion.
>
>
> Felix Crux <felixc@felixcrux.com> writes:
>
>> Hello,
>>
>> I recently ran across a perplexing problem that I can't find the answer
>> to in the documentation.
>>
>> The following snippet in my init file works just as one would expect in
>> both graphical (GTK+) and terminal instances of Emacs:
>>
>>   (global-set-key [?\C-x ?\e] 'save-buffers-kill-emacs)
>>
>> However, this version, which I thought to be identical (but more readable),
>> only works in graphical sessions:
>>
>>   (global-set-key (kbd "C-x <escape>") 'save-buffers-kill-emacs)
>>
>> When attempting to use it in a terminal, the status line simply displays
>> "C-x ESC-", as though waiting for more input.
>>
>> Invoking emacs-version gives me "GNU Emacs 23.4.1 (x86_64-pc-linux-gnu,
>> GTK+ Version 2.24.10) of 2012-09-08 on trouble, modified by Debian".
>>
>> I'd be most grateful if someone would point me in the right direction to
>> understand this. Thank you,
>>
>> Felix C.
>>
>>
>
> --



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Difference between GUI/terminal when using "kbd" macro
  2013-02-18 16:49 Difference between GUI/terminal when using "kbd" macro Felix Crux
  2013-02-18 19:12 ` Jambunathan K
@ 2013-02-19 13:32 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-02-19 13:32 UTC (permalink / raw
  To: help-gnu-emacs

>   (global-set-key [?\C-x ?\e] 'save-buffers-kill-emacs)
[...]
>   (global-set-key (kbd "C-x <escape>") 'save-buffers-kill-emacs)

The escape key usually is linked to the escape char, but the two
are different.  Under a tty, Emacs receives the exact same byte-sequence
from the terminal if you type the escape key or if you type C-[ (both
send the escape char).
Under a GUI, on the other hand, Emacs can distinguish the two, so under
a GUI, the escape key doesn't send `?\e' (aka ESC for kbd) but `escape'
(aka <escape> for kbd) which is usually turned into a ?\e via
function-key-map (i.e. only if there's no corresponding binding for the
key sequence with `escape').

Same thing happens with tab (i.e. TAB (aka C-i) vs tab) and return
(i.e. RET (aka C-m) vs return).


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Difference between GUI/terminal when using "kbd" macro
  2013-02-18 19:33   ` Felix Crux
@ 2013-02-19 15:58     ` Kevin Rodgers
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2013-02-19 15:58 UTC (permalink / raw
  To: help-gnu-emacs

On 2/18/13 12:33 PM, Felix Crux wrote:
> Thanks for the suggestion; it actually led to an interesting discovery:
>
> With the keybinding set to (kbd "C-x<escape>"), running "C-x<escape>  C-h"
> (in a terminal session, since in a GUI one it quits Emacs) shows the following:
>
>    Global Bindings Starting With C-x ESC:
>    key             binding
>    ---             -------
>    C-x ESC ESC     repeat-complex-command
>
> This got me thinking about the fact that the help system is calling it "ESC",
> not "<escape>", and wondering about whether that is significant.
>
> I then tried changing the binding to (kbd "C-x ESC"), which actually works in
> both graphical and terminal sessions!
>
> In conclusion, it looks as though there is a difference between "ESC" and
> "<escape>", at least as far as the "kbd" macro is concerned. I don't know
> enough about the topic to be sure, but I would speculate that "<escape>" is
> some sort of special meta-character being sent by the X window system, while
> "ESC" is the lower-level key value.
>
> Very interesting stuff; and it now lets me use the more readable form, too!
> I'm still quite curious about the discrepancy, but at least the original
> problem is solved. Thank you!

See the "Named ASCII Control Characters" node of the Emacs manual, and the
"Function Keys" node of the Emacs Lisp manual.

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-02-19 15:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-18 16:49 Difference between GUI/terminal when using "kbd" macro Felix Crux
2013-02-18 19:12 ` Jambunathan K
2013-02-18 19:33   ` Felix Crux
2013-02-19 15:58     ` Kevin Rodgers
2013-02-19 13:32 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.