help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-[ is undefined


From: Michael Brand
Subject: Re: C-[ is undefined
Date: Sat, 28 Jul 2018 17:40:35 -0600

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]