Re: Ctrl-[ ?

classic Classic list List threaded Threaded
44 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Jean-Christophe Helary-4
I found on Stackoverflow that C-[ was pretty much hard-coded as ESC. Why is that ?


Also, there is no mention about that at all in the manual.

On Jun 6, 2019, at 13:49, Jean-Christophe Helary <[hidden email]> wrote:

I'm finding that Ctrl-[ is associated to Esc but I have nothing like this in my init file.

Hitting Ctrl-[ in C-h k also gives Esc.

Why is that ?

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Andreas Schwab
On Jun 06 2019, Jean-Christophe Helary <[hidden email]> wrote:

> I found on Stackoverflow that C-[ was pretty much hard-coded as ESC. Why is that ?

Because ?\[ follows ?Z in ASCII, and ESC follows SUB.

(logand ?\[ #x3f) => 27

Andreas.

--
Andreas Schwab, SUSE Labs, [hidden email]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
In reply to this post by Jean-Christophe Helary-4
On June 6, 2019 10:26:28 AM GMT+03:00, Jean-Christophe Helary <[hidden email]> wrote:
> I found on Stackoverflow that C-[ was pretty much hard-coded as ESC.
> Why is that ?
>
> https://superuser.com/questions/173851/linux-remap-ctrl-key
>
> Also, there is no mention about that at all in the manual.


It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Jean-Christophe Helary-4


On Jun 6, 2019, at 19:12, Eli Zaretskii <[hidden email]> wrote:

On June 6, 2019 10:26:28 AM GMT+03:00, Jean-Christophe Helary <[hidden email]> wrote:
I found on Stackoverflow that C-[ was pretty much hard-coded as ESC.
Why is that ?

https://superuser.com/questions/173851/linux-remap-ctrl-key

Also, there is no mention about that at all in the manual.

It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.

Yes but, in my other applications I do have the ability to use Ctrl+[ in a way that is not ESC. Like assign C-[ as a shortcut similarly to C-].

Is there a way to do the same in emacs ?


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Mattias Engdegård-2
In reply to this post by Eli Zaretskii
6 juni 2019 kl. 12.12 skrev Eli Zaretskii <[hidden email]>:
>
> It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.

The above is true when Emacs is running in a terminal. Otherwise, Emacs has code to emulate that behaviour (make_ctrl_char), so that we can enjoy a whiff of early 1960s bit-paired keyboards. And this does appear to be hard-coded, in the sense that it cannot be disabled.

It's somewhat useful for certain expensive keyboards with dodgy escape keys.


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Stefan Monnier
In reply to this post by Jean-Christophe Helary-4
> I found on Stackoverflow that C-[ was pretty much hard-coded as
> ESC. Why is that ?

Under most terminals, `escape` and `C-[` send the same byte sequence,
i.e. a single byte 27 which corresponds to the ascii ESC character.

For this reason, when the GUI version of Emacs was introduced (where the
two keys are clearly distinguished), Emacs added `function-key-map`
entries to turn `escape` into ESC when there's no specific `escape`
binding (the mapping from `C-[` to ESC is done at a much lower level,
this one definitely counts as hardcoded).


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
In reply to this post by Mattias Engdegård-2
> From: Mattias Engdegård <[hidden email]>
> Date: Thu, 6 Jun 2019 14:44:31 +0200
> Cc: Emacs developers <[hidden email]>,
>         Jean-Christophe Helary <[hidden email]>
>
> 6 juni 2019 kl. 12.12 skrev Eli Zaretskii <[hidden email]>:
> >
> > It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.
>
> The above is true when Emacs is running in a terminal. Otherwise, Emacs has code to emulate that behaviour (make_ctrl_char), so that we can enjoy a whiff of early 1960s bit-paired keyboards. And this does appear to be hard-coded, in the sense that it cannot be disabled.

Why is it useful to have different behavior on GUI and TTY frames?

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
In reply to this post by Jean-Christophe Helary-4
> From: Jean-Christophe Helary <[hidden email]>
> Date: Thu, 6 Jun 2019 21:37:38 +0900
>
> Yes but, in my other applications I do have the ability to use Ctrl+[ in a way that is not ESC. Like assign C-[ as
> a shortcut similarly to C-].

Do those other applications also support text-mode terminals?

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Jean-Christophe Helary-4
In reply to this post by Eli Zaretskii


On Jun 6, 2019, at 22:01, Eli Zaretskii <[hidden email]> wrote:

From: Mattias Engdegård <[hidden email]>
Date: Thu, 6 Jun 2019 14:44:31 +0200
Cc: Emacs developers <[hidden email]>,
       Jean-Christophe Helary <[hidden email]>

6 juni 2019 kl. 12.12 skrev Eli Zaretskii <[hidden email]>:

It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.

The above is true when Emacs is running in a terminal. Otherwise, Emacs has code to emulate that behaviour (make_ctrl_char), so that we can enjoy a whiff of early 1960s bit-paired keyboards. And this does appear to be hard-coded, in the sense that it cannot be disabled.

Why is it useful to have different behavior on GUI and TTY frames?

Because expectations are different ?


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Clément Pit-Claudel
In reply to this post by Eli Zaretskii
On 2019-06-06 09:01, Eli Zaretskii wrote:

>> From: Mattias Engdegård <[hidden email]>
>> Date: Thu, 6 Jun 2019 14:44:31 +0200
>> Cc: Emacs developers <[hidden email]>,
>>         Jean-Christophe Helary <[hidden email]>
>>
>> 6 juni 2019 kl. 12.12 skrev Eli Zaretskii <[hidden email]>:
>>>
>>> It isn't hardcoded in Emacs, it' "hardcoded" in the way the OS produces character codes when you type keys on the keyboard.  C-[ produces ESC for the same reason C-i produces TAB and C-j produces RET: these keys emit the same codes as the corresponding Ctrl sequences.
>>
>> The above is true when Emacs is running in a terminal. Otherwise, Emacs has code to emulate that behaviour (make_ctrl_char), so that we can enjoy a whiff of early 1960s bit-paired keyboards. And this does appear to be hard-coded, in the sense that it cannot be disabled.
>
> Why is it useful to have different behavior on GUI and TTY frames?

It's not so much that it's useful to have different behavior; rather, there are limitations that only TTY frames suffer from, and if you mostly or always use GUI frames, it's nice not to suffer from these limitations.

For example in my day to day work I use variable-pitch faces, different font sizes, highlighting in ore colors than my terminal can display, svg support, and, most relevant to the discussion above, keybindings that gnome-terminal doesn't support, such as C-S-> and C-S-< (the location of these keys was convenient, and I knew I wouldn't need the corresponding functions often in TTY frames).

So I guess keeping a consistent experience in TTY and GUI frames isn't as important for me as improving the experience in GUI frames.

(I'm not claiming that Enacs' defaults should diverge between TTY and GUI; just that there are use cases for different behavior on GUI and TTY frames)

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Óscar Fuentes
In reply to this post by Eli Zaretskii
Eli Zaretskii <[hidden email]> writes:

> Why is it useful to have different behavior on GUI and TTY frames?

For those users who don't use Emacs on the terminal (not rare nowadays)
finding that those keys as special is confusing and limiting, as
demonstrated by this thread.

So while it is not useful to have different behavior on GUI and TTY
frames *by default*, it is not useful either to impose the limitations
of TTY frames on GUI frames.


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Jean-Christophe Helary-4
In reply to this post by Eli Zaretskii


On Jun 6, 2019, at 22:02, Eli Zaretskii <[hidden email]> wrote:

From: Jean-Christophe Helary <[hidden email]>
Date: Thu, 6 Jun 2019 21:37:38 +0900

Yes but, in my other applications I do have the ability to use Ctrl+[ in a way that is not ESC. Like assign C-[ as
a shortcut similarly to C-].

Do those other applications also support text-mode terminals?

No, and that's the point.

If I prefer to run Emacs in GUI mode it is because I don't want to be limited by a TTY emulation.
(for ex, the ability to display images/pdfs, etc.)


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Juanma Barranquero
In reply to this post by Clément Pit-Claudel
On Thu, Jun 6, 2019 at 3:28 PM Clément Pit-Claudel
<[hidden email]> wrote:

> So I guess keeping a consistent experience in TTY and GUI frames isn't as important for me as improving the experience in GUI frames.

Same here. I don't think I've used Emacs on TTY frames... well,
*ever*, except for testing framesets, or researching some bug.

> (I'm not claiming that Enacs' defaults should diverge between TTY and GUI; just that there are use cases for different behavior on GUI and TTY frames)

Agreed.

Reply | Threaded
Open this post in threaded view
|

RE: Ctrl-[ ?

Drew Adams
In reply to this post by Eli Zaretskii
> Why is it useful to have different behavior on GUI and TTY frames?

As others have said, it's about _being able_ to
have different behavior.  It's not about changing
the default of having the same behavior on both.

I agree with what everyone else (so far) has said
about this.

It is good to be able to use `C-[' to get `ESC'
behavior, just as it's good to be able to use
`ESC ESC' to get `M-x' behavior.  What's not so
good is to make it hard to get different behavior
for `C-[' and `ESC'.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
In reply to this post by Jean-Christophe Helary-4
> From: Jean-Christophe Helary <[hidden email]>
> Date: Thu, 6 Jun 2019 22:25:17 +0900
>
>  Why is it useful to have different behavior on GUI and TTY frames?
>
> Because expectations are different ?

Are they?  I don't think so.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
In reply to this post by Clément Pit-Claudel
> From: Clément Pit-Claudel <[hidden email]>
> Date: Thu, 6 Jun 2019 09:26:54 -0400
>
> > Why is it useful to have different behavior on GUI and TTY frames?
>
> It's not so much that it's useful to have different behavior; rather, there are limitations that only TTY frames suffer from, and if you mostly or always use GUI frames, it's nice not to suffer from these limitations.

That's not the same.  C-[ being the same as ESC is very basic, like
C-g, so having to remember that it might not work on GUI frames would
be a PITA at least for me.

> So I guess keeping a consistent experience in TTY and GUI frames isn't as important for me as improving the experience in GUI frames.

IMO, being able to bind C-[ to something else is not an important
feature, not enough to break the compatibility.  But that's me.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Jean-Christophe Helary-4


On Jun 6, 2019, at 23:37, Eli Zaretskii <[hidden email]> wrote:

From: Clément Pit-Claudel <[hidden email]>
Date: Thu, 6 Jun 2019 09:26:54 -0400

Why is it useful to have different behavior on GUI and TTY frames?

It's not so much that it's useful to have different behavior; rather, there are limitations that only TTY frames suffer from, and if you mostly or always use GUI frames, it's nice not to suffer from these limitations.

That's not the same.  C-[ being the same as ESC is very basic,

Well, for some people, obviously not for everybody.

My issue was understanding *why* it was the case. The history with ascii is cute but really makes just as much sense to me as if I had to enter unicode escaped sequences in emacs to be able to type Japanese.

like C-g, so having to remember that it might not work on GUI frames would be a PITA at least for me.

? Which is not what I'd like to have here.

What I'd like to have is some documentation about that issue in the Emacs manual *and* a documented way to override that behavior on my side.

So I guess keeping a consistent experience in TTY and GUI frames isn't as important for me as improving the experience in GUI frames.

IMO, being able to bind C-[ to something else is not an important
feature, not enough to break the compatibility.

What compatibility would that break ? If I were to bind C-[ in GUI emacs to something that I find more convenient than ESC in that position, how would that break something ?

 But that's me.

That could be me too if you explained the issue in a more intelligible way.

Now I see that some things are explained in "Named ASCII Control Characters" in the manual. That part definitely needs some explicit wording for non nerds.

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Clément Pit-Claudel
In reply to this post by Eli Zaretskii
On 2019-06-06 10:37, Eli Zaretskii wrote:

>> From: Clément Pit-Claudel <[hidden email]>
>> Date: Thu, 6 Jun 2019 09:26:54 -0400
>>
>>> Why is it useful to have different behavior on GUI and TTY frames?
>>
>> It's not so much that it's useful to have different behavior; rather, there are limitations that only TTY frames suffer from, and if you mostly or always use GUI frames, it's nice not to suffer from these limitations.
>
> That's not the same.  C-[ being the same as ESC is very basic, like
> C-g, so having to remember that it might not work on GUI frames would
> be a PITA at least for me.
>
>> So I guess keeping a consistent experience in TTY and GUI frames isn't as important for me as improving the experience in GUI frames.
>
> IMO, being able to bind C-[ to something else is not an important
> feature, not enough to break the compatibility.  But that's me.

I don't have a strong opinion :)  I very seldom have to use an Emacs with someone else's config, so I wouldn't be bothered if the option existed to rebind C-[ to something different from ESC.

By the way, is there a way to change what ESC does? If so, GUI users could just bind <escape> to esc-map and ESC to something else.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Eli Zaretskii
> From: Clément Pit-Claudel <[hidden email]>
> Date: Thu, 6 Jun 2019 11:33:56 -0400
> Cc: [hidden email]
>
> By the way, is there a way to change what ESC does?

It's a prefix command, so I'm not sure what you are asking, exactly.

Reply | Threaded
Open this post in threaded view
|

Re: Ctrl-[ ?

Clément Pit-Claudel
On 2019-06-06 13:28, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <[hidden email]>
>> Date: Thu, 6 Jun 2019 11:33:56 -0400
>> Cc: [hidden email]
>>
>> By the way, is there a way to change what ESC does?
>
> It's a prefix command, so I'm not sure what you are asking, exactly.

I wan wondering whether there was a way to make it a regular (non-prefix) command.  For example, can you bind it to `forward-char'?

123