* Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
@ 2024-07-12 12:14 Pierre Rouleau
2024-07-12 12:53 ` Robert Pluim
` (2 more replies)
0 siblings, 3 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 12:14 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
Does Emacs already have a predicate function that can be used to check if
the specified key sequence is valid for Emacs running in terminal mode?
For example, "C-;" is not accessible on Emacs running in terminal mode
because this is not an ASCII control character. It's available for Emacs
running in graphical environment, but not in terminal mode.
Is there something similar already available or one would simply wrap
describe-key and catch the error to check?
Regards,
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 12:14 Does code exist to check if a key sequence is valid for Emacs running in terminal mode? Pierre Rouleau
@ 2024-07-12 12:53 ` Robert Pluim
2024-07-12 13:07 ` tomas
2024-07-12 14:48 ` Pierre Rouleau
2024-07-12 13:10 ` Yuri Khan
2024-07-17 2:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
2 siblings, 2 replies; 22+ messages in thread
From: Robert Pluim @ 2024-07-12 12:53 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
>>>>> On Fri, 12 Jul 2024 08:14:52 -0400, Pierre Rouleau <prouleau001@gmail.com> said:
Pierre> Hi all,
Pierre> Does Emacs already have a predicate function that can be used to check if
Pierre> the specified key sequence is valid for Emacs running in terminal mode?
Not that I know of, but Emacs always has functionality I donʼt know of
:-)
Pierre> For example, "C-;" is not accessible on Emacs running in terminal mode
Pierre> because this is not an ASCII control character. It's available for Emacs
Pierre> running in graphical environment, but not in terminal mode.
Pierre> Is there something similar already available or one would simply wrap
Pierre> describe-key and catch the error to check?
Iʼm in a terminal frame:
(describe-key (kbd "C-;")) =>
#("C-; is undefined" 0 3 (face help-key-binding font-lock-face help-key-binding))
which is exactly what you get in a GUI frame.
I think the best you can do is bind the key. If itʼs available, it will work.
Robert
--
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 12:53 ` Robert Pluim
@ 2024-07-12 13:07 ` tomas
2024-07-12 14:55 ` Eli Zaretskii
2024-07-12 14:48 ` Pierre Rouleau
1 sibling, 1 reply; 22+ messages in thread
From: tomas @ 2024-07-12 13:07 UTC (permalink / raw)
To: Robert Pluim; +Cc: Pierre Rouleau, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1417 bytes --]
On Fri, Jul 12, 2024 at 02:53:36PM +0200, Robert Pluim wrote:
> >>>>> On Fri, 12 Jul 2024 08:14:52 -0400, Pierre Rouleau <prouleau001@gmail.com> said:
>
> Pierre> Hi all,
> Pierre> Does Emacs already have a predicate function that can be used to check if
> Pierre> the specified key sequence is valid for Emacs running in terminal mode?
>
> Not that I know of, but Emacs always has functionality I donʼt know of
> :-)
>
> Pierre> For example, "C-;" is not accessible on Emacs running in terminal mode
> Pierre> because this is not an ASCII control character. It's available for Emacs
> Pierre> running in graphical environment, but not in terminal mode.
>
> Pierre> Is there something similar already available or one would simply wrap
> Pierre> describe-key and catch the error to check?
>
> Iʼm in a terminal frame:
>
> (describe-key (kbd "C-;")) =>
> #("C-; is undefined" 0 3 (face help-key-binding font-lock-face help-key-binding))
>
> which is exactly what you get in a GUI frame.
>
> I think the best you can do is bind the key. If itʼs available, it will work.
OK, negatively speaking, on a terminal CTRL zeros bit 6 (counting from LSB,
starting with 0) to reach the control codes 0..1f (hex). So it only makes
sense with the character codes 40..5f hex (that's '@'..'_').
Everything else is probably GUIsh.
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 12:14 Does code exist to check if a key sequence is valid for Emacs running in terminal mode? Pierre Rouleau
2024-07-12 12:53 ` Robert Pluim
@ 2024-07-12 13:10 ` Yuri Khan
2024-07-12 13:51 ` tomas
2024-07-12 14:35 ` Pierre Rouleau
2024-07-17 2:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
2 siblings, 2 replies; 22+ messages in thread
From: Yuri Khan @ 2024-07-12 13:10 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
On Fri, 12 Jul 2024 at 19:15, Pierre Rouleau <prouleau001@gmail.com> wrote:
> Does Emacs already have a predicate function that can be used to check if
> the specified key sequence is valid for Emacs running in terminal mode?
>
> For example, "C-;" is not accessible on Emacs running in terminal mode
> because this is not an ASCII control character. It's available for Emacs
> running in graphical environment, but not in terminal mode.
This is probably not solvable because an advanced terminal can
implement a protocol extension that represents arbitrary keys as
escape sequences that can then be turned into Emacs key events using
input-decode-map.
[1]: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 13:10 ` Yuri Khan
@ 2024-07-12 13:51 ` tomas
2024-07-12 14:35 ` Pierre Rouleau
1 sibling, 0 replies; 22+ messages in thread
From: tomas @ 2024-07-12 13:51 UTC (permalink / raw)
To: Yuri Khan; +Cc: Pierre Rouleau, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 913 bytes --]
On Fri, Jul 12, 2024 at 08:10:48PM +0700, Yuri Khan wrote:
> On Fri, 12 Jul 2024 at 19:15, Pierre Rouleau <prouleau001@gmail.com> wrote:
>
> > Does Emacs already have a predicate function that can be used to check if
> > the specified key sequence is valid for Emacs running in terminal mode?
> >
> > For example, "C-;" is not accessible on Emacs running in terminal mode
> > because this is not an ASCII control character. It's available for Emacs
> > running in graphical environment, but not in terminal mode.
>
> This is probably not solvable because an advanced terminal can
> implement a protocol extension that represents arbitrary keys as
> escape sequences that can then be turned into Emacs key events using
> input-decode-map.
Well, that's not fair :-)
"God made the VT100, all else is the work of man" [1]
Cheers
[1] https://en.wikipedia.org/wiki/Leopold_Kronecker
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 13:10 ` Yuri Khan
2024-07-12 13:51 ` tomas
@ 2024-07-12 14:35 ` Pierre Rouleau
2024-07-12 14:41 ` Pierre Rouleau
2024-07-12 14:45 ` Robert Pluim
1 sibling, 2 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 14:35 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs
On Fri, Jul 12, 2024 at 9:11 AM Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Fri, 12 Jul 2024 at 19:15, Pierre Rouleau <prouleau001@gmail.com>
> wrote:
>
> > Does Emacs already have a predicate function that can be used to check if
> > the specified key sequence is valid for Emacs running in terminal mode?
> >
> > For example, "C-;" is not accessible on Emacs running in terminal mode
> > because this is not an ASCII control character. It's available for Emacs
> > running in graphical environment, but not in terminal mode.
>
> This is probably not solvable because an advanced terminal can
> implement a protocol extension that represents arbitrary keys as
> escape sequences that can then be turned into Emacs key events using
> input-decode-map.
>
> You are correct, it depends on the terminal being used.
I was thinking of writing a function that would call describe-key
but setup the scope to output into a temporary buffer that it
would discard and catch error if the key described is not a
valid one.
It would therefore like to distinguish the 3 potential cases:
- the key sequence is bound
- the key sequence is not defined.
Like "C-| is undefined" when tried in Emacs running in graphical mode.
- the key sequence is not defined, but reported via an error.
Like "C-;" when tried under Emacs running in terminal mode
inside a terminal that does not remap the C-; to some other escape
sequence.
That sounds feasible. No?
(sent again, forgot to cc. the list).
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:35 ` Pierre Rouleau
@ 2024-07-12 14:41 ` Pierre Rouleau
2024-07-12 14:57 ` Yuri Khan
2024-07-12 23:44 ` Emanuel Berg
2024-07-12 14:45 ` Robert Pluim
1 sibling, 2 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 14:41 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs
On Fri, Jul 12, 2024 at 10:35 AM Pierre Rouleau <prouleau001@gmail.com>
wrote:
>
>
> On Fri, Jul 12, 2024 at 9:11 AM Yuri Khan <yuri.v.khan@gmail.com> wrote:
>
>> On Fri, 12 Jul 2024 at 19:15, Pierre Rouleau <prouleau001@gmail.com>
>> wrote:
>>
>> > Does Emacs already have a predicate function that can be used to check
>> if
>> > the specified key sequence is valid for Emacs running in terminal mode?
>> >
>> > For example, "C-;" is not accessible on Emacs running in terminal mode
>> > because this is not an ASCII control character. It's available for Emacs
>> > running in graphical environment, but not in terminal mode.
>>
>> This is probably not solvable because an advanced terminal can
>> implement a protocol extension that represents arbitrary keys as
>> escape sequences that can then be turned into Emacs key events using
>> input-decode-map.
>>
>> You are correct, it depends on the terminal being used.
> I was thinking of writing a function that would call describe-key
> but setup the scope to output into a temporary buffer that it
> would discard and catch error if the key described is not a
> valid one.
>
> It would therefore like to distinguish the 3 potential cases:
> - the key sequence is bound
> - the key sequence is not defined.
> Like "C-| is undefined" when tried in Emacs running in graphical mode.
> - the key sequence is not defined, but reported via an error.
> Like "C-;" when tried under Emacs running in terminal mode
> inside a terminal that does not remap the C-; to some other escape
> sequence.
>
> That sounds feasible. No?
>
>
The code can determine if Emacs is running a GUI mode or in a terminal
mode.
In GUI mode it would assume that everything is possible.
In terminal mode the issue is being able to distinguish
whether the key sequence can be bound or not.
The real reason I want to do that is to prevent reporting key binding
clashes in code that tries to use the same key binding for 2 different
global key bindings
when that key binding is not even possible because Emacs will not be able
to react to it.
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:35 ` Pierre Rouleau
2024-07-12 14:41 ` Pierre Rouleau
@ 2024-07-12 14:45 ` Robert Pluim
2024-07-12 14:57 ` Pierre Rouleau
1 sibling, 1 reply; 22+ messages in thread
From: Robert Pluim @ 2024-07-12 14:45 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: Yuri Khan, help-gnu-emacs
>>>>> On Fri, 12 Jul 2024 10:35:49 -0400, Pierre Rouleau <prouleau001@gmail.com> said:
Pierre> It would therefore like to distinguish the 3 potential cases:
Pierre> - the key sequence is bound
Pierre> - the key sequence is not defined.
Pierre> Like "C-| is undefined" when tried in Emacs running in graphical mode.
Pierre> - the key sequence is not defined, but reported via an error.
Pierre> Like "C-;" when tried under Emacs running in terminal mode
Pierre> inside a terminal that does not remap the C-; to some other escape
Pierre> sequence.
In every terminal Iʼm aware of the way it works is that pressing Ctrl
and ; at the same time sends ';', so thereʼs no error case to detect
(maybe this is different with kitty with its extensions)
Plus `describe-key' happily works with key sequences that the current
terminal cannot produce:
(describe-key (kbd "A-C-H-M-s-S-;")) =>
#("A-C-H-M-S-s-; is undefined" 0 13 (face help-key-binding font-lock-face help-key-binding))
Robert
--
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 12:53 ` Robert Pluim
2024-07-12 13:07 ` tomas
@ 2024-07-12 14:48 ` Pierre Rouleau
2024-07-12 14:58 ` Robert Pluim
1 sibling, 1 reply; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 14:48 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
On Fri, Jul 12, 2024 at 8:53 AM Robert Pluim <rpluim@gmail.com> wrote:
> >>>>> On Fri, 12 Jul 2024 08:14:52 -0400, Pierre Rouleau <
> prouleau001@gmail.com> said:
>
> Pierre> Hi all,
> Pierre> Does Emacs already have a predicate function that can be used
> to check if
> Pierre> the specified key sequence is valid for Emacs running in
> terminal mode?
>
> Not that I know of, but Emacs always has functionality I donʼt know of
> :-)
>
> Pierre> For example, "C-;" is not accessible on Emacs running in
> terminal mode
> Pierre> because this is not an ASCII control character. It's available
> for Emacs
> Pierre> running in graphical environment, but not in terminal mode.
>
> Pierre> Is there something similar already available or one would
> simply wrap
> Pierre> describe-key and catch the error to check?
>
> Iʼm in a terminal frame:
>
> (describe-key (kbd "C-;")) =>
> #("C-; is undefined" 0 3 (face help-key-binding font-lock-face
> help-key-binding))
>
> which is exactly what you get in a GUI frame.
>
> I think the best you can do is bind the key. If itʼs available, it will
> work.
>
>
Yes, but I want to be able to distinguish in elisp code.
In a situation where several packages globally bind the same
key sequence to different commands I have code that detect the instance
and report by warning.
I want to prevent the warning in Emacs running in terminal mode
if that key sequence cannot even be used under Emacs in terminal mode
when running in the specific terminal.
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 13:07 ` tomas
@ 2024-07-12 14:55 ` Eli Zaretskii
2024-07-12 15:06 ` Pierre Rouleau
0 siblings, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2024-07-12 14:55 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Fri, 12 Jul 2024 15:07:40 +0200
> Cc: Pierre Rouleau <prouleau001@gmail.com>,
> help-gnu-emacs <help-gnu-emacs@gnu.org>
> From: <tomas@tuxteam.de>
>
> OK, negatively speaking, on a terminal CTRL zeros bit 6 (counting from LSB,
> starting with 0) to reach the control codes 0..1f (hex). So it only makes
> sense with the character codes 40..5f hex (that's '@'..'_').
I think you forget about the term/*.el files. It could define some
arbitrary sequence as a valid key.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:41 ` Pierre Rouleau
@ 2024-07-12 14:57 ` Yuri Khan
2024-07-12 15:05 ` Pierre Rouleau
2024-07-12 19:30 ` tomas
2024-07-12 23:44 ` Emanuel Berg
1 sibling, 2 replies; 22+ messages in thread
From: Yuri Khan @ 2024-07-12 14:57 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
On Fri, 12 Jul 2024 at 21:41, Pierre Rouleau <prouleau001@gmail.com> wrote:
> The code can determine if Emacs is running a GUI mode or in a terminal mode.
> In GUI mode it would assume that everything is possible.
> In terminal mode the issue is being able to distinguish
> whether the key sequence can be bound or not.
Even that is in general not solvable. Given an Emacs daemon, you can
connect to it with a GUI client and a terminal-based client, and they
will coexist peacefully.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:45 ` Robert Pluim
@ 2024-07-12 14:57 ` Pierre Rouleau
0 siblings, 0 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 14:57 UTC (permalink / raw)
To: Robert Pluim; +Cc: Yuri Khan, help-gnu-emacs
On Fri, Jul 12, 2024 at 10:45 AM Robert Pluim <rpluim@gmail.com> wrote:
> >>>>> On Fri, 12 Jul 2024 10:35:49 -0400, Pierre Rouleau <
> prouleau001@gmail.com> said:
>
> Pierre> It would therefore like to distinguish the 3 potential cases:
> Pierre> - the key sequence is bound
> Pierre> - the key sequence is not defined.
> Pierre> Like "C-| is undefined" when tried in Emacs running in
> graphical mode.
> Pierre> - the key sequence is not defined, but reported via an error.
> Pierre> Like "C-;" when tried under Emacs running in terminal mode
> Pierre> inside a terminal that does not remap the C-; to some
> other escape
> Pierre> sequence.
>
> In every terminal Iʼm aware of the way it works is that pressing Ctrl
> and ; at the same time sends ';', so thereʼs no error case to detect
> (maybe this is different with kitty with its extensions)
>
> Plus `describe-key' happily works with key sequences that the current
> terminal cannot produce:
>
> (describe-key (kbd "A-C-H-M-s-S-;")) =>
>
> #("A-C-H-M-S-s-; is undefined" 0 13 (face help-key-binding font-lock-face
> help-key-binding))
>
>
I get the behaviour you describe under Linux normally.
But under macOS, running under their Terminal.app terminal it's different.
The Terminal.app configuration allows selecting sequences for some ANSI
code sequence
but not for the Control sequences that do not correspond to the ASCII
Control codes
(C-@ (0x00) up to C-_ (0x1f)).
I assume I could, with some logic, try to use the key sequence binary
value,
detect the terminal by looking at the TERM environment variable,
use the knowledge appropriate to the terminal and infer whether it's
supported or not.
But that seems like the wrong approach.
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:48 ` Pierre Rouleau
@ 2024-07-12 14:58 ` Robert Pluim
0 siblings, 0 replies; 22+ messages in thread
From: Robert Pluim @ 2024-07-12 14:58 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: help-gnu-emacs
>>>>> On Fri, 12 Jul 2024 10:48:44 -0400, Pierre Rouleau <prouleau001@gmail.com> said:
Pierre> Yes, but I want to be able to distinguish in elisp code.
Pierre> In a situation where several packages globally bind the same
Pierre> key sequence to different commands I have code that detect the instance
Pierre> and report by warning.
Pierre> I want to prevent the warning in Emacs running in terminal mode
Pierre> if that key sequence cannot even be used under Emacs in terminal mode
Pierre> when running in the specific terminal.
I donʼt think what you want is possible. Even in a GUI frame, there
are key sequences that can be produced by the keyboard that Emacs will
never see because the window manager steals them.
Robert
--
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:57 ` Yuri Khan
@ 2024-07-12 15:05 ` Pierre Rouleau
2024-07-12 19:30 ` tomas
1 sibling, 0 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 15:05 UTC (permalink / raw)
To: Yuri Khan; +Cc: help-gnu-emacs
On Fri, Jul 12, 2024 at 10:58 AM Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Fri, 12 Jul 2024 at 21:41, Pierre Rouleau <prouleau001@gmail.com>
> wrote:
>
> > The code can determine if Emacs is running a GUI mode or in a terminal
> mode.
> > In GUI mode it would assume that everything is possible.
> > In terminal mode the issue is being able to distinguish
> > whether the key sequence can be bound or not.
>
> Even that is in general not solvable. Given an Emacs daemon, you can
> connect to it with a GUI client and a terminal-based client, and they
> will coexist peacefully.
>
That's true. However, on macOS I found the only way I could run a daemon
that would allow me to connect both GUI and terminal clients was to start a
daemon from code that was built with GUI capability.
And in my use case what I'm trying to do is to prevent generating
run time warning messages saying there's a clash of global key bindings
between 2 (or more) packages, when (possibly client) Emacs process
executes something during initialisation.
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:55 ` Eli Zaretskii
@ 2024-07-12 15:06 ` Pierre Rouleau
0 siblings, 0 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-12 15:06 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On Fri, Jul 12, 2024 at 10:56 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Fri, 12 Jul 2024 15:07:40 +0200
> > Cc: Pierre Rouleau <prouleau001@gmail.com>,
> > help-gnu-emacs <help-gnu-emacs@gnu.org>
> > From: <tomas@tuxteam.de>
> >
> > OK, negatively speaking, on a terminal CTRL zeros bit 6 (counting from
> LSB,
> > starting with 0) to reach the control codes 0..1f (hex). So it only makes
> > sense with the character codes 40..5f hex (that's '@'..'_').
>
> I think you forget about the term/*.el files. It could define some
> arbitrary sequence as a valid key.
>
>
Correct. I did not know about that. Thanks
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:57 ` Yuri Khan
2024-07-12 15:05 ` Pierre Rouleau
@ 2024-07-12 19:30 ` tomas
2024-07-13 14:12 ` Pierre Rouleau
1 sibling, 1 reply; 22+ messages in thread
From: tomas @ 2024-07-12 19:30 UTC (permalink / raw)
To: Yuri Khan; +Cc: Pierre Rouleau, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On Fri, Jul 12, 2024 at 09:57:49PM +0700, Yuri Khan wrote:
> On Fri, 12 Jul 2024 at 21:41, Pierre Rouleau <prouleau001@gmail.com> wrote:
>
> > The code can determine if Emacs is running a GUI mode or in a terminal mode.
> > In GUI mode it would assume that everything is possible.
> > In terminal mode the issue is being able to distinguish
> > whether the key sequence can be bound or not.
>
> Even that is in general not solvable. Given an Emacs daemon, you can
> connect to it with a GUI client and a terminal-based client, and they
> will coexist peacefully.
That just means that the function needs also the frame as input param,
no?
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 14:41 ` Pierre Rouleau
2024-07-12 14:57 ` Yuri Khan
@ 2024-07-12 23:44 ` Emanuel Berg
2024-07-13 13:45 ` Pierre Rouleau
1 sibling, 1 reply; 22+ messages in thread
From: Emanuel Berg @ 2024-07-12 23:44 UTC (permalink / raw)
To: help-gnu-emacs
Pierre Rouleau wrote:
> The real reason I want to do that is to prevent reporting
> key binding clashes in code that tries to use the same key
> binding for 2 different global key bindings when that key
> binding is not even possible because Emacs will not be able
> to react to it.
Can't you just branch on `display-graphic-p'? It is nil here
but t in a GUI Emacs instance so should work.
Another way is to just set some variable when you start it:
$ HERE="some-system" emacs
then branch on (getenv "HERE").
Sounds easier?
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 23:44 ` Emanuel Berg
@ 2024-07-13 13:45 ` Pierre Rouleau
0 siblings, 0 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-13 13:45 UTC (permalink / raw)
To: help-gnu-emacs
On Fri, Jul 12, 2024 at 11:23 PM Emanuel Berg <incal@dataswamp.org> wrote:
> Pierre Rouleau wrote:
>
> > The real reason I want to do that is to prevent reporting
> > key binding clashes in code that tries to use the same key
> > binding for 2 different global key bindings when that key
> > binding is not even possible because Emacs will not be able
> > to react to it.
>
> Can't you just branch on `display-graphic-p'? It is nil here
> but t in a GUI Emacs instance so should work.
>
> Another way is to just set some variable when you start it:
>
> $ HERE="some-system" emacs
>
> then branch on (getenv "HERE").
>
> Sounds easier?
>
Well, perhaps I did not explain the problem properly.
Code is probably easier to provide the context.
Here's the code, published here:
https://github.com/pierre-rouleau/pel/blob/master/pel-spell-iedit.el#L63
(defun pel-spell-iedit-check-conflict ()
"Check for key binding conflict between flyspell and iedit.
Warn user if necessary."
(when (and (boundp 'iedit-toggle-key-default)
(boundp 'flyspell-auto-correct-binding)
(string= (key-description iedit-toggle-key-default)
(key-description flyspell-auto-correct-binding)))
(display-warning
'pel-keys
(format "Both iedit and flyspell bind functions to \"%s\"!\n\
To use this key, change the key selected in one of the following \n\
user options:\n\
- `iedit-toggle-key-default'
- `flyspell-auto-correct-binding'
Then save your changes."
(key-description flyspell-auto-correct-binding)))))
The above code checks if the user that has configured
the system to use both iedit and flyspell and use their
default key binding that clashes. Their code has the following:
(defcustom iedit-toggle-key-default (kbd "C-;")
"If no-nil, the key is inserted into global-map,
isearch-mode-map, esc-map and help-map."
:type 'vector
:group 'iedit)
(defcustom flyspell-auto-correct-binding
[(control ?\;)]
"The key binding for flyspell auto correction."
:type 'key-sequence)
The warning is printed on Emacs running in terminal mode
even though when running under a macOS Terminal.app the C-;
cannot be used.
So, I would like to be able to *check* if the key bindings
reported as clashing can be used in the environment
(and yes I use the functions you mentioned) and if they
can't, I would change the message.
This code is part of my PEL project at:
https://github.com/pierre-rouleau/pel#readme
I wrote this Emacs Lisp project as a way to control my
Emacs startup, help me learn Emacs and help some friends
transition to Emacs.
I use it on a relatively large number of computers, OSes and Emacs versions
depending on what's available in the environment provided by my customers.
Sorry for the long description, but I hope it provides a better overview
of the context.
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 19:30 ` tomas
@ 2024-07-13 14:12 ` Pierre Rouleau
2024-07-13 20:06 ` tomas
0 siblings, 1 reply; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-13 14:12 UTC (permalink / raw)
To: tomas; +Cc: Yuri Khan, help-gnu-emacs
On Fri, Jul 12, 2024 at 3:30 PM <tomas@tuxteam.de> wrote:
> On Fri, Jul 12, 2024 at 09:57:49PM +0700, Yuri Khan wrote:
> > On Fri, 12 Jul 2024 at 21:41, Pierre Rouleau <prouleau001@gmail.com>
> wrote:
> >
> > > The code can determine if Emacs is running a GUI mode or in a terminal
> mode.
> > > In GUI mode it would assume that everything is possible.
> > > In terminal mode the issue is being able to distinguish
> > > whether the key sequence can be bound or not.
> >
> > Even that is in general not solvable. Given an Emacs daemon, you can
> > connect to it with a GUI client and a terminal-based client, and they
> > will coexist peacefully.
>
> That just means that the function needs also the frame as input param,
> no?
>
>
Interesting thought.
In the scenario I have to deal with (described in a previous mail)
I could use both display-graphic-p and the
frame type inside a hook executing to
check if the key clash exists for the buffer.
At the moment I only do that at initialization time.
That would allow identifying whether the key binding clash
situation is real (in the graphical frame), or otherwise
when the frame is a terminal based one.
But I still have the problem of being able to
determine if the key binding is accessible
or not when the frame is in terminal mode.
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-13 14:12 ` Pierre Rouleau
@ 2024-07-13 20:06 ` tomas
0 siblings, 0 replies; 22+ messages in thread
From: tomas @ 2024-07-13 20:06 UTC (permalink / raw)
To: Pierre Rouleau; +Cc: Yuri Khan, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]
On Sat, Jul 13, 2024 at 10:12:51AM -0400, Pierre Rouleau wrote:
> On Fri, Jul 12, 2024 at 3:30 PM <tomas@tuxteam.de> wrote:
[...]
> > That just means that the function needs also the frame as input param,
> > no?
> >
> >
> Interesting thought.
> In the scenario I have to deal with (described in a previous mail)
> I could use both display-graphic-p and the
> frame type inside a hook executing to
> check if the key clash exists for the buffer.
> At the moment I only do that at initialization time.
>
> That would allow identifying whether the key binding clash
> situation is real (in the graphical frame), or otherwise
> when the frame is a terminal based one.
>
> But I still have the problem of being able to
> determine if the key binding is accessible
> or not when the frame is in terminal mode.
This is indeed the hard part. Compounded by the sad fact that some
(most? all?) terminal emulators can be configured to send arbitrary
stuff for a given key combo. For Xterm it's the Term.VT100.translations
X resource.
I fear you have no choice but to offer some heuristic which will work
most of the time (and be it: terminal? Only 32 CTRL chars for you!)
and a good instruction sheet for those users who are not the common
case.
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-12 12:14 Does code exist to check if a key sequence is valid for Emacs running in terminal mode? Pierre Rouleau
2024-07-12 12:53 ` Robert Pluim
2024-07-12 13:10 ` Yuri Khan
@ 2024-07-17 2:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-19 13:31 ` Pierre Rouleau
2 siblings, 1 reply; 22+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-07-17 2:44 UTC (permalink / raw)
To: help-gnu-emacs
> Does Emacs already have a predicate function that can be used to check if
> the specified key sequence is valid for Emacs running in terminal mode?
Note the same problem exists under GUIs, where Emacs does not offer
a way to test whether a given ELisp event can be generated by your input
devices.
So, the best you can do is to use heuristics about what you think is
"usually possible" and "usually impossible". I don't know of any ELisp
package offering such a functionality yet.
Stefan
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Does code exist to check if a key sequence is valid for Emacs running in terminal mode?
2024-07-17 2:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-07-19 13:31 ` Pierre Rouleau
0 siblings, 0 replies; 22+ messages in thread
From: Pierre Rouleau @ 2024-07-19 13:31 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
On Tue, Jul 16, 2024 at 10:44 PM Stefan Monnier via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> > Does Emacs already have a predicate function that can be used to check if
> > the specified key sequence is valid for Emacs running in terminal mode?
>
> Note the same problem exists under GUIs, where Emacs does not offer
> a way to test whether a given ELisp event can be generated by your input
> devices.
>
> So, the best you can do is to use heuristics about what you think is
> "usually possible" and "usually impossible". I don't know of any ELisp
> package offering such a functionality yet.
>
>
Yep, that's what I'm doing.
Merci
--
/Pierre
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2024-07-19 13:31 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 12:14 Does code exist to check if a key sequence is valid for Emacs running in terminal mode? Pierre Rouleau
2024-07-12 12:53 ` Robert Pluim
2024-07-12 13:07 ` tomas
2024-07-12 14:55 ` Eli Zaretskii
2024-07-12 15:06 ` Pierre Rouleau
2024-07-12 14:48 ` Pierre Rouleau
2024-07-12 14:58 ` Robert Pluim
2024-07-12 13:10 ` Yuri Khan
2024-07-12 13:51 ` tomas
2024-07-12 14:35 ` Pierre Rouleau
2024-07-12 14:41 ` Pierre Rouleau
2024-07-12 14:57 ` Yuri Khan
2024-07-12 15:05 ` Pierre Rouleau
2024-07-12 19:30 ` tomas
2024-07-13 14:12 ` Pierre Rouleau
2024-07-13 20:06 ` tomas
2024-07-12 23:44 ` Emanuel Berg
2024-07-13 13:45 ` Pierre Rouleau
2024-07-12 14:45 ` Robert Pluim
2024-07-12 14:57 ` Pierre Rouleau
2024-07-17 2:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-19 13:31 ` Pierre Rouleau
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).