* C-[ is undefined
@ 2018-07-07 19:52 Michael Brand
2018-07-26 2:00 ` Fwd: " Michael Brand
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Michael Brand @ 2018-07-07 19:52 UTC (permalink / raw)
To: help-gnu-emacs
Hi all
Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
Long story: With the help of key-chord-mode I started to use two
simultaneously pressed normal keys to get the control modifier:
#+begin_src emacs-lisp
(defvar v-key-chord-control "en"
"Key chord for `event-apply-control-modifier'.
The key chord is optimized for `vi-state' and the Colemak
keyboard layout (where `en' is QWERTY `jk').")
(key-chord-define key-translation-map v-key-chord-control
#'event-apply-control-modifier)
(key-chord-define-global v-key-chord-control
#'event-apply-control-modifier)
#+end_src
Now also ~en [~ results in "C-[ is undefined". The same applies for \,
], ^ and _ with control modifier. All other control characters (means
a-z with control modifier like for example "en s" for I-search) are
bound as expected.
I tried
#+begin_src emacs-lisp
(define-key key-translation-map (kbd "C-[") [(escape)])
#+end_src
or
#+begin_src emacs-lisp
(global-set-key (kbd "C-[") [(escape)])
#+end_src
but ~C-[~ remains undefined. What is the part that I am missing? (And
what will be needed instead of ~[(escape)]~ after the binding is
fixed?)
Please CC me as I am not subscribed to this list.
Michael
^ permalink raw reply [flat|nested] 13+ messages in thread
* Fwd: C-[ is undefined
2018-07-07 19:52 C-[ is undefined Michael Brand
@ 2018-07-26 2:00 ` Michael Brand
[not found] ` <mailman.4231.1532570417.1292.help-gnu-emacs@gnu.org>
2018-07-27 13:12 ` Noam Postavsky
2 siblings, 0 replies; 13+ messages in thread
From: Michael Brand @ 2018-07-26 2:00 UTC (permalink / raw)
To: help-gnu-emacs
There seems to be no answer yet but I am still stuck and would
appreciate any help to get further.
---------- Forwarded message ----------
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Sat, Jul 7, 2018 at 1:52 PM
Subject: C-[ is undefined
To: help-gnu-emacs@gnu.org
Hi all
Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
Long story: With the help of key-chord-mode I started to use two
simultaneously pressed normal keys to get the control modifier:
#+begin_src emacs-lisp
(defvar v-key-chord-control "en"
"Key chord for `event-apply-control-modifier'.
The key chord is optimized for `vi-state' and the Colemak
keyboard layout (where `en' is QWERTY `jk').")
(key-chord-define key-translation-map v-key-chord-control
#'event-apply-control-modifier)
(key-chord-define-global v-key-chord-control
#'event-apply-control-modifier)
#+end_src
Now also ~en [~ results in "C-[ is undefined". The same applies for \,
], ^ and _ with control modifier. All other control characters (means
a-z with control modifier like for example "en s" for I-search) are
bound as expected.
I tried
#+begin_src emacs-lisp
(define-key key-translation-map (kbd "C-[") [(escape)])
#+end_src
or
#+begin_src emacs-lisp
(global-set-key (kbd "C-[") [(escape)])
#+end_src
but ~C-[~ remains undefined. What is the part that I am missing? (And
what will be needed instead of ~[(escape)]~ after the binding is
fixed?)
Please CC me as I am not subscribed to this list.
Michael
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.4231.1532570417.1292.help-gnu-emacs@gnu.org>]
* Re: Fwd: C-[ is undefined
[not found] ` <mailman.4231.1532570417.1292.help-gnu-emacs@gnu.org>
@ 2018-07-26 12:38 ` Ben Bacarisse
2018-07-27 0:17 ` Michael Brand
[not found] ` <mailman.4284.1532650678.1292.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 13+ messages in thread
From: Ben Bacarisse @ 2018-07-26 12:38 UTC (permalink / raw)
To: help-gnu-emacs
Michael Brand <michael.ch.brand@gmail.com> writes:
> There seems to be no answer yet but I am still stuck and would
> appreciate any help to get further.
I'll make a remark, not sure if it will help...
> ---------- Forwarded message ----------
> From: Michael Brand <michael.ch.brand@gmail.com>
> Date: Sat, Jul 7, 2018 at 1:52 PM
> Subject: C-[ is undefined
> To: help-gnu-emacs@gnu.org
>
> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
I would expect C-x @ c [ to be the same as C-[ and not anything to do
with a Meta modifier. C-x @ m [ would generate M-[.
> Long story: With the help of key-chord-mode I started to use two
> simultaneously pressed normal keys to get the control modifier:
I don't know anything about that mode so I'll leave the rest to others.
> Please CC me as I am not subscribed to this list.
OK, but please don't reply to me directly.
--
Ben.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fwd: C-[ is undefined
2018-07-26 12:38 ` Ben Bacarisse
@ 2018-07-27 0:17 ` Michael Brand
[not found] ` <mailman.4284.1532650678.1292.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 13+ messages in thread
From: Michael Brand @ 2018-07-27 0:17 UTC (permalink / raw)
To: help-gnu-emacs
Hi Ben
On Thu, Jul 26, 2018 at 6:38 AM, Ben Bacarisse <ben.lists@bsb.me.uk> wrote:
> The following message is a courtesy copy of an article
> that has been posted to gnu.emacs.help as well.
>
> Michael Brand <michael.ch.brand@gmail.com> writes:
>
>> There seems to be no answer yet but I am still stuck and would
>> appreciate any help to get further.
>
> I'll make a remark, not sure if it will help...
>
>> ---------- Forwarded message ----------
>> From: Michael Brand <michael.ch.brand@gmail.com>
>> Date: Sat, Jul 7, 2018 at 1:52 PM
>> Subject: C-[ is undefined
>> To: help-gnu-emacs@gnu.org
>>
>> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
>> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
>
> I would expect C-x @ c [ to be the same as C-[
Did you try? For me it is not the same which is what I wanted to say
in the first place.
> and not anything to do with a Meta modifier.
What do you mean by this when ~C-[ t~ is the same as ~M-t~? I expected
that ~C-x @ c [ t~ to be the same as ~C-[ t~ which is the same as
~M-t~.
> C-x @ m [ would generate M-[.
Not for me. ~C-x @ m [~ results in "M-[ is undefined" but ~M-[~ waits
for more input (only when in Viper mode). So it looks like the same
issue. Anyway, you can discard as it is not what I am after at the
moment.
>> Long story: With the help of key-chord-mode I started to use two
>> simultaneously pressed normal keys to get the control modifier:
>
> I don't know anything about that mode so I'll leave the rest to others.
The "long story" is only mentioned to understand why I want to use
event-apply-control-modifier. The insanely looking minimal complete
example to substitute my use case is just ~C-x @ c [ t~ to get ~M-t~,
~C-x @ c [ u~ to get ~M-u~ and so on.
(Please CC me as I am not subscribed to this list.)
Michael
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.4284.1532650678.1292.help-gnu-emacs@gnu.org>]
* Re: Fwd: C-[ is undefined
[not found] ` <mailman.4284.1532650678.1292.help-gnu-emacs@gnu.org>
@ 2018-07-27 1:33 ` Ben Bacarisse
2018-07-27 13:24 ` John Shahid
[not found] ` <mailman.4322.1532697888.1292.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 13+ messages in thread
From: Ben Bacarisse @ 2018-07-27 1:33 UTC (permalink / raw)
To: help-gnu-emacs
Michael Brand <michael.ch.brand@gmail.com> writes:
> Hi Ben
>
> On Thu, Jul 26, 2018 at 6:38 AM, Ben Bacarisse <ben.lists@bsb.me.uk> wrote:
>> The following message is a courtesy copy of an article
>> that has been posted to gnu.emacs.help as well.
>>
>> Michael Brand <michael.ch.brand@gmail.com> writes:
>>
>>> There seems to be no answer yet but I am still stuck and would
>>> appreciate any help to get further.
>>
>> I'll make a remark, not sure if it will help...
>>
>>> ---------- Forwarded message ----------
>>> From: Michael Brand <michael.ch.brand@gmail.com>
>>> Date: Sat, Jul 7, 2018 at 1:52 PM
>>> Subject: C-[ is undefined
>>> To: help-gnu-emacs@gnu.org
>>>
>>> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
>>> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
>>
>> I would expect C-x @ c [ to be the same as C-[
>
> Did you try? For me it is not the same which is what I wanted to say
> in the first place.
Yes, I tried it, but my interpretation of the result ("C-[" is
undefined) was that C-x @ c [ was a way to generate a "key" that could
not otherwise be typed.
That's kind of what happens. For example, you can bind C-[ this way and
still use C-[ to get the ESC- prefix.
However, that seems like an unlikely explanation! It is probably
something to do with translated key sequences. ESC and C-[ are not
exactly the same, but I am not expert enough to explain the way in which
they differ.
>> and not anything to do with a Meta modifier.
>
> What do you mean by this when ~C-[ t~ is the same as ~M-t~? I expected
> that ~C-x @ c [ t~ to be the same as ~C-[ t~ which is the same as
> ~M-t~.
Ah, yes, I see. C-x @ c [ is obviously not identical to C-[ in some
subtle way. Or, more likely, C-[ is special in some way. When you list
the key bindings (C-h b) there is no entry for C-[ but ESC appears twice
-- once as a prefix and then again in the place you'd expect C-[ to
appear.
Anyway, the long and the short of it is that I can't help which is a
shame since I now actually understand the issue you are having!
--
Ben.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Fwd: C-[ is undefined
2018-07-27 1:33 ` Ben Bacarisse
@ 2018-07-27 13:24 ` John Shahid
[not found] ` <mailman.4322.1532697888.1292.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 13+ messages in thread
From: John Shahid @ 2018-07-27 13:24 UTC (permalink / raw)
To: Ben Bacarisse; +Cc: help-gnu-emacs
Ben Bacarisse <ben.lists@bsb.me.uk> writes:
[...]
>>>> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
>>>> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
>>>
>>> I would expect C-x @ c [ to be the same as C-[
>>
>> Did you try? For me it is not the same which is what I wanted to say
>> in the first place.
>
> Yes, I tried it, but my interpretation of the result ("C-[" is
> undefined) was that C-x @ c [ was a way to generate a "key" that could
> not otherwise be typed.
>
> That's kind of what happens. For example, you can bind C-[ this way and
> still use C-[ to get the ESC- prefix.
>
> However, that seems like an unlikely explanation! It is probably
> something to do with translated key sequences. ESC and C-[ are not
> exactly the same, but I am not expert enough to explain the way in which
> they differ.
I think there is an implicit assumption in this thread that Emacs is
receiving key press events for both the 'Control' and '[' keys. I tried
this on my system using 'xev' and it receives a KeyPress event for
'Control' but as soon as I hit '[' the window receives a KeyPress event
for Escape (i.e. '0x1b'). My conclusion is that Emacs doesn't even know
that you pressed 'C-['.
You can probably achieve the same result by translating 'C-[' to
'Escape' in the 'key-translation-map'. This map is used after
'local-function-key-map' where the 'event-apply-control-modifier'
applies the control modifier. Another idea is to add an advice to
'event-apply-control-modifier'.
cheers,
-js
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.4322.1532697888.1292.help-gnu-emacs@gnu.org>]
* Re: Fwd: C-[ is undefined
[not found] ` <mailman.4322.1532697888.1292.help-gnu-emacs@gnu.org>
@ 2018-07-27 16:19 ` Ben Bacarisse
0 siblings, 0 replies; 13+ messages in thread
From: Ben Bacarisse @ 2018-07-27 16:19 UTC (permalink / raw)
To: help-gnu-emacs
John Shahid <jvshahid@gmail.com> writes:
> Ben Bacarisse <ben.lists@bsb.me.uk> writes:
>
>
> [...]
>
>>>>> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
>>>>> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
>>>>
>>>> I would expect C-x @ c [ to be the same as C-[
>>>
>>> Did you try? For me it is not the same which is what I wanted to say
>>> in the first place.
>>
>> Yes, I tried it, but my interpretation of the result ("C-[" is
>> undefined) was that C-x @ c [ was a way to generate a "key" that could
>> not otherwise be typed.
>>
>> That's kind of what happens. For example, you can bind C-[ this way and
>> still use C-[ to get the ESC- prefix.
>>
>> However, that seems like an unlikely explanation! It is probably
>> something to do with translated key sequences. ESC and C-[ are not
>> exactly the same, but I am not expert enough to explain the way in which
>> they differ.
>
> I think there is an implicit assumption in this thread that Emacs is
> receiving key press events for both the 'Control' and '[' keys. I tried
> this on my system using 'xev' and it receives a KeyPress event for
> 'Control' but as soon as I hit '[' the window receives a KeyPress event
> for Escape (i.e. '0x1b'). My conclusion is that Emacs doesn't even know
> that you pressed 'C-['.
Not here. xev shows Control_L down, [ down, [ up, Control_l up. Odd
difference.
> You can probably achieve the same result by translating 'C-[' to
> 'Escape' in the 'key-translation-map'. This map is used after
> 'local-function-key-map' where the 'event-apply-control-modifier'
> applies the control modifier. Another idea is to add an advice to
> 'event-apply-control-modifier'.
I thought it might be an interaction between translation maps and
others.
--
Ben.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: C-[ is undefined
2018-07-07 19:52 C-[ is undefined Michael Brand
2018-07-26 2:00 ` Fwd: " Michael Brand
[not found] ` <mailman.4231.1532570417.1292.help-gnu-emacs@gnu.org>
@ 2018-07-27 13:12 ` Noam Postavsky
2018-07-27 20:38 ` Stefan Monnier
2018-07-28 23:40 ` Michael Brand
2 siblings, 2 replies; 13+ messages in thread
From: Noam Postavsky @ 2018-07-27 13:12 UTC (permalink / raw)
To: Michael Brand; +Cc: Help Gnu Emacs mailing list
On 7 July 2018 at 15:52, Michael Brand <michael.ch.brand@gmail.com> wrote:
> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
This seems to work correctly, though I can't say I entirely understand why:
(define-key key-translation-map
(vector (+ #x4000000 ?\[))
[?\e])
I found (+ #x4000000 ?\[) by evaluating (read-key-sequence "keyseq? ")
and then typing in C-x @ c [ in response to the prompt.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: C-[ is undefined
2018-07-27 13:12 ` Noam Postavsky
@ 2018-07-27 20:38 ` Stefan Monnier
2018-07-28 23:40 ` Michael Brand
1 sibling, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2018-07-27 20:38 UTC (permalink / raw)
To: help-gnu-emacs
> This seems to work correctly, though I can't say I entirely understand why:
>
> (define-key key-translation-map
> (vector (+ #x4000000 ?\[))
> [?\e])
Looks like a bug in `event-apply-modifier`:
(event-apply-modifier ?a 'control 26 "C-")
correctly returns 1 (aka C-a) but it doesn't apply that same
special-case to ?\[
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: C-[ is undefined
2018-07-27 13:12 ` Noam Postavsky
2018-07-27 20:38 ` Stefan Monnier
@ 2018-07-28 23:40 ` Michael Brand
2018-08-19 16:02 ` Michael Brand
1 sibling, 1 reply; 13+ messages in thread
From: Michael Brand @ 2018-07-28 23:40 UTC (permalink / raw)
To: Noam Postavsky; +Cc: Help Gnu Emacs mailing list
Hi Noam
On Fri, Jul 27, 2018 at 7:12 AM, Noam Postavsky <npostavs@gmail.com> wrote:
> On 7 July 2018 at 15:52, Michael Brand <michael.ch.brand@gmail.com> wrote:
>
>> Short story: ~C-x @ c [~ results in "C-[ is undefined" but I expected
>> it to be the Meta prefix like in for example ~C-[ t~ for ~M-t~.
>
> This seems to work correctly, though I can't say I entirely understand why:
>
> (define-key key-translation-map
> (vector (+ #x4000000 ?\[))
> [?\e])
>
> I found (+ #x4000000 ?\[) by evaluating (read-key-sequence "keyseq? ")
> and then typing in C-x @ c [ in response to the prompt.
Thank you, this is exactly what I was looking for when I mentioned in
the first post of this thread that I tried
#+begin_src emacs-lisp
(define-key key-translation-map (kbd "C-[") [(escape)])
#+end_src
without success because key and definition were wrong. Although, only
~C-x @ c [ t~ results in ~M-t~ with this. For my use case with
key-chord-mode ~en [~ still
results in "C-[ is undefined" due to a reason unknown to me.
According to the comment from Stefan in this thread I tried
event-apply-modifier as
#+begin_src emacs-lisp
(defun event-apply-modifier (event symbol lshiftby prefix)
"[...]"
(if (numberp event)
(cond ((eq symbol 'control)
(cond
;; C0 control characters (0 to 31, except 127).
((<= ?@ event ?_)
(- event ?@))
;; A to Z from above as a to z.
((<= ?a event ?z)
(- event ?a -1))
(t
(logior (lsh 1 lshiftby) event))))
((eq symbol 'shift)
(if (<= ?a (downcase event) ?z)
(upcase event)
(logior (lsh 1 lshiftby) event)))
(t
(logior (lsh 1 lshiftby) event)))
(if (memq symbol (event-modifiers event))
event
(let ((event-type (if (symbolp event) event (car event))))
(setq event-type (intern (concat prefix (symbol-name event-type))))
(if (symbolp event)
event-type
(cons event-type (cdr event)))))))
#+end_src
and it solves the issue for:
- The minimal complete example with ~C-x @ c [ t~ for ~M-t~, ~C-x @ c
[ u~ for ~M-u~ and so on.
- My use case with key-chord-mode ~en [ t~ for ~M-t~, ~en [ u~ for
~M-u~ and so on. (I will try to change my current key chord ~en~ for
event-apply-control-modifier to ~[[~ so that quickly typing ~[[~ will
be the Control modifier and ~[[[~ will be the Meta modifier).
Michael
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: C-[ is undefined
2018-07-28 23:40 ` Michael Brand
@ 2018-08-19 16:02 ` Michael Brand
2018-08-19 16:12 ` Stefan Monnier
2018-08-19 17:01 ` Michael Brand
0 siblings, 2 replies; 13+ messages in thread
From: Michael Brand @ 2018-08-19 16:02 UTC (permalink / raw)
To: Help Gnu Emacs mailing list; +Cc: Michael Brand, Noam Postavsky
Hi all
On Sun, Jul 29, 2018 at 1:40 AM, Michael Brand
<michael.ch.brand@gmail.com> wrote:
> According to the comment from Stefan in this thread I tried
> event-apply-modifier as
>
> #+begin_src emacs-lisp
> (defun event-apply-modifier (event symbol lshiftby prefix)
> "[...]"
> (if (numberp event)
> (cond ((eq symbol 'control)
> (cond
> ;; C0 control characters (0 to 31, except 127).
> ((<= ?@ event ?_)
> (- event ?@))
> ;; A to Z from above as a to z.
> ((<= ?a event ?z)
> (- event ?a -1))
> (t
> (logior (lsh 1 lshiftby) event))))
> ((eq symbol 'shift)
> (if (<= ?a (downcase event) ?z)
> (upcase event)
> (logior (lsh 1 lshiftby) event)))
> (t
> (logior (lsh 1 lshiftby) event)))
> (if (memq symbol (event-modifiers event))
> event
> (let ((event-type (if (symbolp event) event (car event))))
> (setq event-type (intern (concat prefix (symbol-name event-type))))
> (if (symbolp event)
> event-type
> (cons event-type (cdr event)))))))
> #+end_src
>
> and it solves the issue for:
>
> - The minimal complete example with ~C-x @ c [ t~ for ~M-t~, ~C-x @ c
> [ u~ for ~M-u~ and so on.
>
> - My use case with key-chord-mode ~en [ t~ for ~M-t~, ~en [ u~ for
> ~M-u~ and so on. (I will try to change my current key chord ~en~ for
> event-apply-control-modifier to ~[[~ so that quickly typing ~[[~ will
> be the Control modifier and ~[[[~ will be the Meta modifier).
I have been using ~[[~ for the Control modifier and ~[[[~ for the Meta
modifier or ESC with the above modification of ~event-apply-modifier~
for some time
now and I like it. (If anyone wants to know more or try it out get
key-chord.el http://www.emacswiki.org/emacs/KeyChord and my setup
http://github.com/brandm/emacs.d)
Now I would like to know how to proceed with ~event-apply-modifier~:
1) Should I use an advice for this function?
2) Should there be a configuration to choose between the original, the
above and possibly even more different function behaviors?
3) Should the function be changed to something similar to the above?
What to tell the users that rely on the current behavior?
Michael
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2018-08-19 17:01 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-07 19:52 C-[ is undefined Michael Brand
2018-07-26 2:00 ` Fwd: " Michael Brand
[not found] ` <mailman.4231.1532570417.1292.help-gnu-emacs@gnu.org>
2018-07-26 12:38 ` Ben Bacarisse
2018-07-27 0:17 ` Michael Brand
[not found] ` <mailman.4284.1532650678.1292.help-gnu-emacs@gnu.org>
2018-07-27 1:33 ` Ben Bacarisse
2018-07-27 13:24 ` John Shahid
[not found] ` <mailman.4322.1532697888.1292.help-gnu-emacs@gnu.org>
2018-07-27 16:19 ` Ben Bacarisse
2018-07-27 13:12 ` Noam Postavsky
2018-07-27 20:38 ` Stefan Monnier
2018-07-28 23:40 ` Michael Brand
2018-08-19 16:02 ` Michael Brand
2018-08-19 16:12 ` Stefan Monnier
2018-08-19 17:01 ` Michael Brand
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).