unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How does the Meta/Alt-Key work behind the scenes?
@ 2012-10-31  8:44 Thorsten Jolitz
  0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2012-10-31  8:44 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

I'm trying to emulate the (most basic) Emacs keybindings for the
commandline of another Lisp dialect. Most of the functionality is
already there, I only have to adopt the keybindings. This works fine
with the 'Control' prefix, e.g. 'C-f' or 'C-b' (I can write them down as
^f and ^b). I can even emulate key-chords by waiting for the second key,
e.g. 'C-x', wait 500, if next key is 'u' -> undo (C-x u).

But I would like to have 'M-f', 'M-b', 'M-d' etc. as well, and maybe
even 'C-M-f' and 'C-M-b'. 

Now, I'm writing this in Emacs/GNUS in a TMUX managed console session, and I
can use my ALT keys for all the 'M-<x>' keybindings given in the last
paragraph, and of course it works in an X11 session too. Even bindings
like 'M-S-5' ('M-%') work on the console. 

However, I was told to hardcode the Meta/Alt-Keybindings as ESC-key
sequences, e.g. '^[', wait 500, then 'f', so that they can either be
used as 'ALT-f' or as 'ESC f'. But only the latter (very uncomfortable)
option works for me, and any keybindings that include the SHIFT key
don't work at all.

How did they do it in Emacs to make the 'M' and 'S' bindings work even
on the console? My keyboard seems to send the right signals, how would
Emacs recognize the keys otherwise - but why do 'M' and 'S' seem to be
dead in my own implementation?

Thanks for any hints. 

-- 
cheers,
Thorsten





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

* Re: How does the Meta/Alt-Key work behind the scenes?
       [not found] <mailman.12043.1351673061.855.help-gnu-emacs@gnu.org>
@ 2012-10-31 15:02 ` Stefan Monnier
  2012-10-31 16:24   ` Thorsten Jolitz
       [not found]   ` <mailman.12074.1351700673.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2012-10-31 15:02 UTC (permalink / raw)
  To: help-gnu-emacs

> However, I was told to hardcode the Meta/Alt-Keybindings as ESC-key
> sequences, e.g. '^[', wait 500, then 'f', so that they can either be
> used as 'ALT-f' or as 'ESC f'. But only the latter (very uncomfortable)
> option works for me, and any keybindings that include the SHIFT key
> don't work at all.

What does "don't work" mean?


        Stefan


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

* Re: How does the Meta/Alt-Key work behind the scenes?
  2012-10-31 15:02 ` How does the Meta/Alt-Key work behind the scenes? Stefan Monnier
@ 2012-10-31 16:24   ` Thorsten Jolitz
       [not found]   ` <mailman.12074.1351700673.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2012-10-31 16:24 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> However, I was told to hardcode the Meta/Alt-Keybindings as ESC-key
>> sequences, e.g. '^[', wait 500, then 'f', so that they can either be
>> used as 'ALT-f' or as 'ESC f'. But only the latter (very uncomfortable)
>> option works for me, and any keybindings that include the SHIFT key
>> don't work at all.
>
> What does "don't work" mean?

Maybe I asked to early since further testing revealed that it is not a
general problem but a problem of some keys only: 

When I use 'C-%' (^% = C-S-5 on my keyboard) which should execute the
command 'go to next parenthesis' then in xterm '%' is (self)inserted, on
the console nothing happens. But 'C-_' (^_ = C-S-- on my keyboard)
executes 'undo' as expected in xterm and on the console. 

So I would like to withdraw my question for now - sorry for the noise.  

-- 
cheers,
Thorsten




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

* Re: How does the Meta/Alt-Key work behind the scenes?
       [not found]   ` <mailman.12074.1351700673.855.help-gnu-emacs@gnu.org>
@ 2012-10-31 16:51     ` William Gardella
  2012-10-31 17:43       ` Thorsten Jolitz
  2012-10-31 18:00     ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: William Gardella @ 2012-10-31 16:51 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Thorsten,

Thorsten Jolitz <tjolitz@googlemail.com> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> However, I was told to hardcode the Meta/Alt-Keybindings as ESC-key
>>> sequences, e.g. '^[', wait 500, then 'f', so that they can either be
>>> used as 'ALT-f' or as 'ESC f'. But only the latter (very uncomfortable)
>>> option works for me, and any keybindings that include the SHIFT key
>>> don't work at all.
>>
>> What does "don't work" mean?
>
> Maybe I asked to early since further testing revealed that it is not a
> general problem but a problem of some keys only: 
>
> When I use 'C-%' (^% = C-S-5 on my keyboard) which should execute the
> command 'go to next parenthesis' then in xterm '%' is (self)inserted, on
> the console nothing happens. But 'C-_' (^_ = C-S-- on my keyboard)
> executes 'undo' as expected in xterm and on the console. 
>
> So I would like to withdraw my question for now - sorry for the noise.  

TTY keys are complicated, and really limit the ability of an application
like Emacs to use its bucky bits.  Some chords that are valid in a
window system are not valid in a console (or in a terminal emulator
under normal circumstances, which acts like a console).  See
e.g. http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters and
http://en.wikipedia.org/wiki/ANSI_escape_code to get a feel for what is
possible and what is missing.

-WGG

-- 
I use grml (http://grml.org/)


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

* Re: How does the Meta/Alt-Key work behind the scenes?
  2012-10-31 16:51     ` William Gardella
@ 2012-10-31 17:43       ` Thorsten Jolitz
  0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2012-10-31 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

William Gardella <gardellawg@gmail.com> writes:

Hi William,

> TTY keys are complicated, and really limit the ability of an application
> like Emacs to use its bucky bits.  Some chords that are valid in a
> window system are not valid in a console (or in a terminal emulator
> under normal circumstances, which acts like a console).  See
> e.g. http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters and
> http://en.wikipedia.org/wiki/ANSI_escape_code to get a feel for what is
> possible and what is missing.

thanks for the links, nice background info, its really not as simple as
it looks at first sight. 

-- 
cheers,
Thorsten




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

* Re: How does the Meta/Alt-Key work behind the scenes?
       [not found]   ` <mailman.12074.1351700673.855.help-gnu-emacs@gnu.org>
  2012-10-31 16:51     ` William Gardella
@ 2012-10-31 18:00     ` Stefan Monnier
  2012-10-31 19:32       ` Thorsten Jolitz
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2012-10-31 18:00 UTC (permalink / raw)
  To: help-gnu-emacs

> Maybe I asked to early since further testing revealed that it is not a
> general problem but a problem of some keys only:

Some control combinations exist in ASCII others don't.
Those that don't either don't work or need to be turned by your terminal
emulator into some kind of byte sequence, usually using some kind of
escaping mechanism.

Try: "emacs -nw -Q" and then "C-% C-% C-h l"
In the *Help* buffer you'll then see the bytes received by Emacs and
you'll notice that C-% is not there.  They've been replaced by escape
sequences (in my case it looks like "ESC [ 2 7 ; 6 ; 3 7 ~" is the
sequence sent by my terminal emulator for C-%).

Emacs handles this via the `input-decode-map' to convert this sequence
back into its more meaningful "C-%".  This map is mostly initialized
from the terminfo database (and completed by lisp/term/$TERM.el).


        Stefan


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

* Re: How does the Meta/Alt-Key work behind the scenes?
  2012-10-31 18:00     ` Stefan Monnier
@ 2012-10-31 19:32       ` Thorsten Jolitz
  0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2012-10-31 19:32 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Try: "emacs -nw -Q" and then "C-% C-% C-h l"
> In the *Help* buffer you'll then see the bytes received by Emacs and
> you'll notice that C-% is not there.  

Yes, I see. 

> Emacs handles this via the `input-decode-map' to convert this sequence
> back into its more meaningful "C-%".  This map is mostly initialized
> from the terminfo database (and completed by lisp/term/$TERM.el).

How much work there is involved just to enable a few apparently
inoffensive key combinations...

Thank you, the /term/xterm.el file is a great source of information for
me. And its nice to find out a bit about how Emacs works under the hood.

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2012-10-31 19:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.12043.1351673061.855.help-gnu-emacs@gnu.org>
2012-10-31 15:02 ` How does the Meta/Alt-Key work behind the scenes? Stefan Monnier
2012-10-31 16:24   ` Thorsten Jolitz
     [not found]   ` <mailman.12074.1351700673.855.help-gnu-emacs@gnu.org>
2012-10-31 16:51     ` William Gardella
2012-10-31 17:43       ` Thorsten Jolitz
2012-10-31 18:00     ` Stefan Monnier
2012-10-31 19:32       ` Thorsten Jolitz
2012-10-31  8:44 Thorsten Jolitz

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).