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

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

Re: Ctrl-[ ?


From: Óscar Fuentes
Subject: Re: Ctrl-[ ?
Date: Sun, 09 Jun 2019 03:24:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> 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".

Thank you for the detailed explanation. IIUC the delicate part consists
on locating and deciding what's the right thing to do about each of
those uses of "control characters" scattered through the code base.




reply via email to

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