ESC vs Meta for shifted keys

classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

ESC vs Meta for shifted keys

Robert Pluim
So Iʼve (finally) got an actual Meta key configured on my
keyboard. Iʼve always believed that Esc-as-prefix and Meta were
interchangable, but that doesnʼt seem to be the case:

C-h k ESC SHIFT <left>
=> ESC <left> (translated from <escape> <S-left>) runs the command
backward-word
C-h k ESC <left>
=> ESC <left> (translated from <escape> <left>) runs the command
backward-word
C-h k M-S-<left>
=>
<M-left> (translated from <M-S-left>) runs the command left-word

So this looks like emacs is not taking into account the SHIFT modifier
here? Or is there some default keyboard translation going on that I
need to disable?

Robert


Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Stefan Monnier
> So Iʼve (finally) got an actual Meta key configured on my
> keyboard. Iʼve always believed that Esc-as-prefix and Meta were
> interchangable, but that doesnʼt seem to be the case:

The ESC <-> Meta equivalence only holds for characters, not for
"special keys" such as `left`, indeed.  Not sure why.

> So this looks like Emacs is not taking into account the SHIFT modifier
> here?

What makes you think so?  The "translated from" clearly shows that Emacs
saw the shift just fine.

> Or is there some default keyboard translation going on that I
> need to disable?

Why would you need to disable it?
IOW which part of "running left-word when I hit M-S-<left>" annoys you?


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Robert Pluim
Stefan Monnier <[hidden email]> writes:

>> So Iʼve (finally) got an actual Meta key configured on my
>> keyboard. Iʼve always believed that Esc-as-prefix and Meta were
>> interchangable, but that doesnʼt seem to be the case:
>
> The ESC <-> Meta equivalence only holds for characters, not for
> "special keys" such as `left`, indeed.  Not sure why.

OK.

>> So this looks like Emacs is not taking into account the SHIFT modifier
>> here?
>
> What makes you think so?  The "translated from" clearly shows that Emacs
> saw the shift just fine.

You're right, I misinterpreted the results. It looks like emacs
ignores the shift if thereʼs no separate binding for the shifted
version, and runs whatever's bound to the unshifted version.

>> Or is there some default keyboard translation going on that I
>> need to disable?
>
> Why would you need to disable it?
> IOW which part of "running left-word when I hit M-S-<left>" annoys you?

This came up when running org, inside a table, where M-S-<left> and
M-<left> do different things, and neither are the same as
ESC-S-<left>. If the Esc <-> Meta were true here they would be easier
for me to type, although I can always rebind the ESC versions (or
retrain my fingers)

Robert

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Emanuel Berg-4
In reply to this post by Robert Pluim
Does anyone use the actual ESC key instead of
Meta ("Alt" or whatever the keyboard
manufacturer puts on the key) these days?

I've heard, and seen picture of how the
keyboards once looked, and then it made more
sense to use it.

Perhaps those keyboards didn't have the arrow
keys, and that's why it doesn't work :)

Monnier knows what to Google Image to find such
a keyboard image. If he does, I promise not to
lose it :$

--
underground experts united
http://user.it.uu.se/~embe8573
Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Bob Proulx
In reply to this post by Stefan Monnier
Stefan Monnier wrote:
> The ESC <-> Meta equivalence only holds for characters, not for
> "special keys" such as `left`, indeed.  Not sure why.

It seems to work for me.  Using C-h c to describe keys in both a
terminal and a graphical emacs shows:

  ESC <left> (translated from ESC M-O D) runs the command backward-word
  <M-left> runs the command left-word

left-word      <M-left>, <C-left>
   Move point N words to the left (to the right if N is negative).
backward-word      ESC <left>, M-b
   Move backward until encountering the beginning of a word.

I presume this is to support:

    11.6 Shift Selection
    ====================

    If you hold down the shift key while typing a cursor motion command,
    this sets the mark before moving point, so that the region extends from
    the original position of point to its new position.  This feature is
    referred to as "shift-selection".  It is similar to the way text is
    selected in other editors.
    ...

I imagine that the keybinding ESC <left> mapping to backward-word
instead of left-word is the root cause of the difference.  WDYT?

Bob

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Bob Proulx
In reply to this post by Emanuel Berg-4
Emanuel Berg wrote:
> Does anyone use the actual ESC key instead of
> Meta ("Alt" or whatever the keyboard
> manufacturer puts on the key) these days?

I use both interchangeably all of the time.  And so does anyone using
an XTerm with "Meta sends ESC" configured even if they never hit the
ESC key themselves.  Because there is no character sent for a meta key
event, just escape sequences for the subsequent key.  Therefore Meta
with that setting on XTerm sends ESC and it all works mostly seemlessly.

> I've heard, and seen picture of how the
> keyboards once looked, and then it made more
> sense to use it.

I think you mean more sense to use meta-key using such keyboards?
Because it certainly makes sense to use Alt-f for example for M-f
forward-word and the rest of the meta characters.  Current popular
keyboards all have an Alt key.

> Perhaps those keyboards didn't have the arrow
> keys, and that's why it doesn't work :)

The symbolics keyboard actually had a *different* arrow set than has
become standard.  The current "standard" comes from the ADM-3a.

  https://deskthority.net/keyboards-f2/lear-siegler-adm3a-terminal-keyboard-t11780.html

Compare the arrow keys on the h, j, k, l on the ADM-3a to the
Symbolics Space Cadet keyboard and you can see that the ADM-3a is the
one that set the standard and the space cadet keyboard has been
forgotten.

> Monnier knows what to Google Image to find such
> a keyboard image. If he does, I promise not to
> lose it :$

How about this one?

  https://en.wikipedia.org/wiki/Space-cadet_keyboard

Bob

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Bob Proulx
Bob Proulx wrote:
>   https://deskthority.net/keyboards-f2/lear-siegler-adm3a-terminal-keyboard-t11780.html
>
> Compare the arrow keys on the h, j, k, l on the ADM-3a to the ...

I will also add to this to look at the position of the control key.
That is the position where I got used to it being.  When IBM came out
with their keyboard and put capslock there it was a tragedy!  This is
why I remap capslock to control and find it hard to use control in any
other position.  I am rather happy with the other changes such as
Return and so forth though.  (shrug)

In the ADM-3a one also sees the relationship between HOME and ~ too.
It was really quite the trend setter. :-)

  https://jbcrawford.us/history/computers/adm3a

Bob

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Stefan Monnier
In reply to this post by Bob Proulx
>> The ESC <-> Meta equivalence only holds for characters, not for
>> "special keys" such as `left`, indeed.  Not sure why.
> It seems to work for me.  Using C-h c to describe keys in both a
> terminal and a graphical emacs shows:
>
>   ESC <left> (translated from ESC M-O D) runs the command backward-word
>   <M-left> runs the command left-word

In which sense does it work for you?  The above shows clearly that
`M-left` and `ESC left` aren't treated identically.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Bob Proulx
Stefan Monnier wrote:

> >> The ESC <-> Meta equivalence only holds for characters, not for
> >> "special keys" such as `left`, indeed.  Not sure why.
>
> > It seems to work for me.  Using C-h c to describe keys in both a
> > terminal and a graphical emacs shows:
> >
> >   ESC <left> (translated from ESC M-O D) runs the command backward-word
> >   <M-left> runs the command left-word
>
> In which sense does it work for you?  The above shows clearly that
> `M-left` and `ESC left` aren't treated identically.

It works for me because they perform the same result.  M-left and ESC
left both move the point left a word.  M-right and ESC right both move
the point right a word.  I also pointed out that they were bound to
different function but I think I adequately explained why they were
bound to slightly different functions.  That is in order to support
Shift Selection.  (A feature that I never use by the way...)

Bob

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Stefan Monnier
> It works for me because they perform the same result.  M-left and ESC
> left both move the point left a word.  M-right and ESC right both move
> the point right a word.

Try them in a R2L paragraph to see if you still think they "perform the
same result".

> I also pointed out that they were bound to different function but
> I think I adequately explained why they were bound to slightly
> different functions.  That is in order to support Shift Selection.
> (A feature that I never use by the way...)

I don't see what shift-selection has to do with it.
I think it's just a bug: when left-word and right-word were introduced
only one pair of bindings was updated and not the other.


        Stefan


Reply | Threaded
Open this post in threaded view
|

RE: ESC vs Meta for shifted keys

Drew Adams
> I think it's just a bug: when left-word and right-word were introduced
> only one pair of bindings was updated and not the other.

I'm not sure it's a bug.  My guess is that it was by design
(for whatever reason).  Perhaps Eli or someone else can
enlighten us.

I kinda doubt it was an oversight.  All of those bindings
are together, and the person who changed the Meta bindings
likely searched for `forward-word', not "[M-right]" or
"(kbd "M-<right>")"...

In `bindings.el':

 (global-set-key [M-right]  'right-word)
 (define-key esc-map [right] 'forward-word)
 (global-set-key [M-left]   'left-word)
 (define-key esc-map [left] 'backward-word)

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Robert Pluim
Drew Adams <[hidden email]> writes:

>> I think it's just a bug: when left-word and right-word were introduced
>> only one pair of bindings was updated and not the other.
>
> I'm not sure it's a bug.  My guess is that it was by design
> (for whatever reason).  Perhaps Eli or someone else can
> enlighten us.
>
> I kinda doubt it was an oversight.  All of those bindings
> are together, and the person who changed the Meta bindings
> likely searched for `forward-word', not "[M-right]" or
> "(kbd "M-<right>")"...
>
> In `bindings.el':
>
>  (global-set-key [M-right]  'right-word)
>  (define-key esc-map [right] 'forward-word)
>  (global-set-key [M-left]   'left-word)
>  (define-key esc-map [left] 'backward-word)

They both used to be bound to {forward,backward}-word, and were
updated at the same time. They're only different in R2L text.

Robert

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Eli Zaretskii
In reply to this post by Drew Adams
> Date: Wed, 11 Apr 2018 14:58:23 -0700 (PDT)
> From: Drew Adams <[hidden email]>
>
> > I think it's just a bug: when left-word and right-word were introduced
> > only one pair of bindings was updated and not the other.
>
> I'm not sure it's a bug.  My guess is that it was by design
> (for whatever reason).  Perhaps Eli or someone else can
> enlighten us.
>
> I kinda doubt it was an oversight.  All of those bindings
> are together, and the person who changed the Meta bindings
> likely searched for `forward-word', not "[M-right]" or
> "(kbd "M-<right>")"...

I don't remember why I bypassed ESC <right> etc.  Maybe I wanted to
change as few bindings as possible.  Maybe I thought users of R2L
script are unlikely to invoke these commands via ESC.  Maybe I just
made a mistake.

If someone is annoyed by the difference (which should only be visible
in bidirectional text), feel free to make ESC do the same as Meta in
this case.

Reply | Threaded
Open this post in threaded view
|

RE: ESC vs Meta for shifted keys

Drew Adams
In reply to this post by Robert Pluim
> >> I think it's just a bug: when left-word and right-word were introduced
> >> only one pair of bindings was updated and not the other.
> >
> > I'm not sure it's a bug.  My guess is that it was by design
> > (for whatever reason).  Perhaps Eli or someone else can
> > enlighten us.
> >
> > I kinda doubt it was an oversight.  All of those bindings
> > are together, and the person who changed the Meta bindings
> > likely searched for `forward-word', not "[M-right]" or
> > "(kbd "M-<right>")"...
> >
> > In `bindings.el':
> >  (global-set-key [M-right]  'right-word)
> >  (define-key esc-map [right] 'forward-word)
> >  (global-set-key [M-left]   'left-word)
> >  (define-key esc-map [left] 'backward-word)
>
> They both used to be bound to {forward,backward}-word, and were
> updated at the same time. They're only different in R2L text.

The question raised was whether the apparent
non-update of the esc-map bindings was deliberate
or an oversight.

When you say "they" were bound ... and "they" were
updated at the same time, is it the same "they"?
Does "they" refer to the global and esc-map keys
for the update, as well as for the old bindings?

Are you saying that the esc-map bindings used to
be bound to (forward|backward)-*, and they were
"updated" (at the same time as the global-map
keys) to the same keys: (forward|backward)-*?

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Robert Pluim
Drew Adams <[hidden email]> writes:

>> >> I think it's just a bug: when left-word and right-word were introduced
>> >> only one pair of bindings was updated and not the other.
>> >
>> > I'm not sure it's a bug.  My guess is that it was by design
>> > (for whatever reason).  Perhaps Eli or someone else can
>> > enlighten us.
>> >
>> > I kinda doubt it was an oversight.  All of those bindings
>> > are together, and the person who changed the Meta bindings
>> > likely searched for `forward-word', not "[M-right]" or
>> > "(kbd "M-<right>")"...
>> >
>> > In `bindings.el':
>> >  (global-set-key [M-right]  'right-word)
>> >  (define-key esc-map [right] 'forward-word)
>> >  (global-set-key [M-left]   'left-word)
>> >  (define-key esc-map [left] 'backward-word)
>>
>> They both used to be bound to {forward,backward}-word, and were
>> updated at the same time. They're only different in R2L text.
>
> The question raised was whether the apparent
> non-update of the esc-map bindings was deliberate
> or an oversight.

It looks deliberate to me (and sensible).

> When you say "they" were bound ... and "they" were
> updated at the same time, is it the same "they"?
> Does "they" refer to the global and esc-map keys
> for the update, as well as for the old bindings?
>
> Are you saying that the esc-map bindings used to
> be bound to (forward|backward)-*, and they were
> "updated" (at the same time as the global-map
> keys) to the same keys: (forward|backward)-*?

Only the global bindings were changed:

--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1103,9 +1103,9 @@ mode-specific-map
   "Keymap for characters following C-c.")
 (define-key global-map "\C-c" 'mode-specific-command-prefix)
 
-(global-set-key [M-right]  'forward-word)
+(global-set-key [M-right]  'right-word)
 (define-key esc-map [right] 'forward-word)
-(global-set-key [M-left]   'backward-word)
+(global-set-key [M-left]   'left-word)
 (define-key esc-map [left] 'backward-word)
 ;; [hidden email] says these bindings are standard on PC editors.
 (global-set-key [C-right]  'right-word)

Reply | Threaded
Open this post in threaded view
|

RE: ESC vs Meta for shifted keys

Drew Adams
> It looks deliberate to me (and sensible).
> Only the global bindings were changed:
>  
> -(global-set-key [M-right]  'forward-word)
> +(global-set-key [M-right]  'right-word)
>  (define-key esc-map [right] 'forward-word)
> -(global-set-key [M-left]   'backward-word)
> +(global-set-key [M-left]   'left-word)
>  (define-key esc-map [left] 'backward-word)

Right, and that's I expected too.

And Eli basically confirms that it was deliberate,
but doesn't recall just why it was done.  (Depending
on what "mistake" might mean, he perhaps also allowed
for it to have just been an oversight.)

The bottom line is that it's not clear why it
was done, and it's not clear what the right
behavior/choice would be now.

These are only default bindings, so whatever
choice is made it's not the end of the world.

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Robert Pluim
Drew Adams <[hidden email]> writes:

>> It looks deliberate to me (and sensible).
>> Only the global bindings were changed:
>>  
>> -(global-set-key [M-right]  'forward-word)
>> +(global-set-key [M-right]  'right-word)
>>  (define-key esc-map [right] 'forward-word)
>> -(global-set-key [M-left]   'backward-word)
>> +(global-set-key [M-left]   'left-word)
>>  (define-key esc-map [left] 'backward-word)
>
> Right, and that's I expected too.
>
> And Eli basically confirms that it was deliberate,
> but doesn't recall just why it was done.  (Depending
> on what "mistake" might mean, he perhaps also allowed
> for it to have just been an oversight.)
>
> The bottom line is that it's not clear why it
> was done, and it's not clear what the right
> behavior/choice would be now.

Itʼs pretty clear to me: the current situation allows users of R2L
text to choose visual or logical moving without impacting L2R users at
all, so I see no need to change anything.

> These are only default bindings, so whatever
> choice is made it's not the end of the world.

This is emacs, after all :-)

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Yuri Khan-2
On Thu, Apr 12, 2018 at 11:16 PM, Robert Pluim <[hidden email]> wrote:

> Itʼs pretty clear to me: the current situation allows users of R2L
> text to choose visual or logical moving without impacting L2R users at
> all, so I see no need to change anything.

On the other hand, the same choice is available with M-b and M-f for
logical order, M-left and M-right for visual order. And it makes
intuitive sense for direction keys to move point in their
corresponding directions.

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Eli Zaretskii
In reply to this post by Robert Pluim
> From: Robert Pluim <[hidden email]>
> Date: Thu, 12 Apr 2018 18:16:43 +0200
> Cc: [hidden email], Stefan Monnier <[hidden email]>
>
> the current situation allows users of R2L text to choose visual or
> logical moving

Nitpicking: both forward-word and right-word move in the logical order
by default, they just might move in opposite directions of buffer
positions.  If you want to have right-word move in visual order, you
need to set visual-order-cursor-movement to a non-nil value.

Reply | Threaded
Open this post in threaded view
|

Re: ESC vs Meta for shifted keys

Eli Zaretskii
In reply to this post by Yuri Khan-2
> From: Yuri Khan <[hidden email]>
> Date: Thu, 12 Apr 2018 23:35:31 +0700
> Cc: help-gnu-emacs <[hidden email]>,
> Stefan Monnier <[hidden email]>
>
> it makes intuitive sense for direction keys to move point in their
> corresponding directions.

Except that they don't, at least not always.  (Yes, bidirectional text
is tricky and confusing.)

12