#3494: \Cj results in a bind to <Return> rather than ctrl+j
---------------------+----------------------
Reporter: rafael | Owner: mutt-dev
Type: defect | Status: new
Priority: major | Milestone:
Component: mutt | Version: 1.5.21
Resolution: | Keywords:
---------------------+----------------------
Comment (by vapier):
incoming brain dump, but i'll reward you with a patch to make it work :P
https://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
{{{<enter>}}} is {{{0xa (10)}}}, aka {{{\n}}}, aka newline, and is what
{{{ctrl+j (^Cj)}}} sends.[[BR]]
{{{<return>}}} is {{{0xd (13)}}}, aka {{{\r}}}, aka carriage return, and
is what {{{ctrl+m (^Cm)}}} sends.
iow, it is not possible to bind {{{^Cj}}} and {{{<enter>}}} to different
operations (same goes for {{{^Cm}}} and {{{<return>}}}) because they are
the same key stroke.
most likely, your X11 keyboard map has it so that the keyboard sends
{{{<return>}}} (regardless of what is printed on the physical keyboard --
"enter" or "return"). the {{{<enter>}}} key is typically part of the
numpad. see the pic on the right side:[[BR]]
https://en.wikipedia.org/wiki/Enter_key
legacy wise, this has long been so inconsistent across keyboards/OS's,
that many terminal related programs have options like "enter is return"
and "return is enter" so that both keys get interpreted the same way
(which is easier than figuring out how to change your keyboard maps for
most people), and why a lot of code bases accept either \r or \n as the
"confirm" key. including mutt -- grep for the CI_is_return func as an
example.
the rabbit hole gets even deeper as this is baked into the terminal
itself. the termios options you can tweak on the fly via {{{stty}}}:
* {{{inlcr}}}: translate newline to carriage return on input
* {{{icrnl}}}: translate carriage return to newline on input
* {{{ocrnl}}}: translate newline to carriage return on output
* {{{onlcr}}}: translate carriage return to newline on output
most likely your terminal line settings have it set to {{{-inlcr icrnl
-ocrnl onlcr}}} by default.
of course, when you use ncurses, it helpfully takes over the terminal
fully and lets the programmer bend it to its will. mutt has not used the
{{{nonl()}}} func which means ncurses takes care of rewriting the
enter/return keystrokes into {{{\n}}} everywhere. this is further
compounded by the mutt code defining {{{M_ENTER_C}}} to {{{\n}}} in
{{{mutt_curses.h}}} (in the ncurses code path), then aliasing
{{{<return>}}} to {{{M_ENTER_C}}}. so whenever you hit either enter or
return, it all gets turned into the {{{<return>}}} binding.
the attached patch works for me in the ncurses code path, although i can
see the {{{M_ENTER_C/M_ENTER_S}}} code paths need updating. i'll post
updates as i notice problems.
--
Ticket URL: <http://dev.mutt.org/trac/ticket/3494#comment:2>
Mutt <http://www.mutt.org/>
The Mutt mail user agent