Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow utf-8 safe meta key mapping in inputrc #723

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Jun 12, 2024

Fixes #603

The inputrc file below will add "\ec" to additional key binding but does not add "\xE3". This behavior is different from Readline but I believe this is better.

# inputrc
"\M-c": "[You input M-c]"

Also supports these formats

"\M-\C-x": key
"\Meta-\C-x": key
"\Control-\Meta-x": key
Meta-c: key
Control-c: key
Meta-Control-c: key
C-M-c: key

Problem of Readline

Using this inputrc file,

# inputrc
"\M-c": "[You input M-c]"

"\M-c" is "\xE3". Readline only assign "\xE3" to the right hand side key. Terminal emulator that supports utf-8 does not send "\xE3" by alt+c because "\xE3" is part of a valid utf-8 string.
When you enter "あ" == "\xE3\x81\x82", Readline thinks the input is "\M-c" + [invalid two bytes].

ruby -rreadline -e "Readline.readline '>'"
>[You input M-c]??

If convert-meta is enabled, Readline assigns "\xE3" and "\ec". Now alt-c works.

# inputrc
set convert-meta on

But now, "え" == "\xE3\x81\x88" == "\xE3\x81\M-\C-H" will trigger \M-\C-H = ed-delete-prev-word.
In utf-8 environment, convert-meta is unusably terrible.

IMO Reline should not follow this old specification.
"\M-c": key should only assign "\ec" to the key.

Readline's convert-meta setting is utf-8 unsafe.
Allow assigning `"\M-char": key` to bind "\echar": key even if convert-meta is not enabled.
Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ima1zumi ima1zumi merged commit 9844b99 into ruby:master Oct 6, 2024
40 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Oct 6, 2024
(ruby/reline#723)

Readline's convert-meta setting is utf-8 unsafe.
Allow assigning `"\M-char": key` to bind "\echar": key even if convert-meta is not enabled.

ruby/reline@9844b99c6e
@tompng tompng deleted the utf8_safe_convert_meta branch October 7, 2024 04:15
@ima1zumi ima1zumi added the enhancement New feature or request label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

Key mappings using Meta- prefix don't map
2 participants