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

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

Re: Ctrl-[ ?


From: Stefan Monnier
Subject: Re: Ctrl-[ ?
Date: Sat, 08 Jun 2019 20:25:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> You can monitor those low-level events. The OS usually provides some
> facilities to translate those events to higher level events. I don't
> know at which level Emacs works for GUIs, probably the later. But that's
> irrelevant, because Emacs can detect equally well C-[ as C-t, because

Indeed, as my sample patch shows.

Currently, the core of the "hardcoding" happens in `make_ctrl_char` (in
src/keyboard.c) where we compute an "event with control modifier":
rather than just set to `control` bit on integer events (Emacs
distinguishes events made of "a character plus some modifiers", which
are represented as integers where some bits are used for the modifiers,
from non-character events like `tab`, `next`, `f1, etc which are
represented as symbols instead), we sometimes set the control bit and
sometimes change the char into an "ASCII control char".  That's where
"control plus [" is turned into the "ASCII C-[" char which is also
known as ESC (aka code 27).

The core of my patch disables this special case, so instead we always
just set the "control modifier bit" (which is bit 26).

The hard work comes afterwards, because we then need to figure out what
to do with all the parts of Emacs where we previously used code 1 (the
ASCII C-a) instead of code 97 + 2^26 (the combination of the letter `a`
and the control modifier bit).

E.g. part of my patch changes the way we print those.  E.g. the current
Emacs code describes both events identically:

    (single-key-description (+ 97 (ash 1 26)))  => "C-a"
    (single-key-description 1)                  => "C-a"

Which makes debugging these things harder, so my patch changes this (it
changes it by printing "\^a" for the second).

But there are various other related issues.  E.g. when we have `?\C-m`
in Elisp code, should the reader consider it as (+ ?m (ash 1 26)) or
as 13?  In terms of backward compatibility, there's actually not much
choice: it has to be 13 otherwise lots of code will break (because this
`?\C-m` is really meant to represent the RET character and if we turn
it into (+ ?m (ash 1 26)) we get something that's not even a valid
character (it can't be put inside a string or buffer)).  But then we
need a new syntax for "the `m` char combined with the control modifier".


        Stefan




reply via email to

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