Skip to content

Commit

Permalink
bind: fix "M-C-@", "C-x C-@", and "M-C-x" (bash-4.2 -o emacs)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 15, 2022
1 parent b568ade commit a410b03
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 6 additions & 4 deletions docs/ChangeLog.md
Expand Up @@ -330,7 +330,9 @@
- main: fix adjustments of bash options (reported by rashil2000) `#D1895` 138c476
- complete: suppress error messages for non-bash_completion `_parse_help` (reported by nik312123) `#D1900` 267de7f
- prompt: fix the marker position for the readline variable `show-mode-in-prompt` (reported by Strykar) `#D1903` 09bb4d3
- highlight: fix a bug that `bleopt filename_ls_colors` is not working (reported by qoreQyaS) `#D1919` xxxxxxx
- highlight: fix a bug that `bleopt filename_ls_colors` is not working (reported by qoreQyaS) `#D1919` b568ade
- bind: fix <kbd>M-C-@</kbd>, <kbd>C-x C-@</kbd>, and <kbd>M-C-x</kbd> (`bash-4.2 -o emacs`) `#D1920` xxxxxxx


## Documentation

Expand All @@ -343,8 +345,8 @@
- wiki/Q&A: add item for defining a widget calling multiple widgets (motivated by micimize) `#D1898` e19b796
- blerc: rename from `blerc` to `blerc.template` `#D1899` e19b796
- README: add a link to the explanation on the "more reliable setup" of bashrc (motivated by telometto) `#D1905` 09bb4d3
- README: describe `contrib/fzf` integration (reported by SuperSandro2000, tbagrel1) `#D1907` 3bc3bea xxxxxxx
- README: add links to Manual pages for *kspec* and `modifyOtherKeys` `#D1917` xxxxxxx
- README: describe `contrib/fzf` integration (reported by SuperSandro2000, tbagrel1) `#D1907` 3bc3bea b568ade
- README: add links to Manual pages for *kspec* and `modifyOtherKeys` `#D1917` fb7bd0b1 b568ade

## Optimization

Expand Down Expand Up @@ -466,7 +468,7 @@
- util (ble/util/s2c): work around intermediate mbstate of bash <= 5.2 `#D1881` 2e1a7c1
- util (ble/util/s2bytes): clear locale cache `#D1881` 2e1a7c1
- complete: fix syntax error for bash-3.0 `#D1881` 0b3e611
- github/workflows: work around grep-3.0 which crashes in windows-latest `#D1915` xxxxxxx
- github/workflows: work around grep-3.0 which crashes in windows-latest `#D1915` fb7bd0b
- test (ble/util/writearray): use `ble/file#hash` instead of `sha256sum` `#D1882` b76e21e
- test (ble/util/readlink): work around external aliases `#D1890` 0c6291f

Expand Down
15 changes: 12 additions & 3 deletions lib/init-bind.sh
Expand Up @@ -38,6 +38,7 @@ function ble/init:bind/generate-binder {
: >| "$fbind2"

local q=\' Q="'\\''"
local altdqs00='\xC0\x80'
local altdqs24='\xC0\x98'
local altdqs27='\xC0\x9B'

Expand Down Expand Up @@ -162,7 +163,7 @@ function ble/init:bind/generate-binder {
# C-@
if ((esc00)); then
# ENCODING: UTF-8 2-byte code of 0 (UTF-8依存)
ble/init:bind/append-macro '\C-@' '\xC0\x80'
ble/init:bind/append-macro '\C-@' "$altdqs00"
else
ble/init:bind/append "$ret" "$i"
fi
Expand Down Expand Up @@ -198,7 +199,9 @@ function ble/init:bind/generate-binder {
# emacs mode では "C-x ?" の組み合わせで登録する。
# Note: 普通に bind -x すると cmd_xmap の \C-x が曖昧になって vi 側の単一
# "C-x" が動かなくなるので、ここでは UTF-8 2B 表示を通して受信する。
if ((i==24)); then
if ((i==0)); then
ble/init:bind/append-macro "\C-x$ret" "$altdqs24$altdqs00" '[[ -o emacs ]]'
elif ((i==24)); then
ble/init:bind/append-macro "\C-x$ret" "$altdqs24$altdqs24" '[[ -o emacs ]]'
else
ble/init:bind/append-macro "\C-x$ret" "$altdqs24$ret" '[[ -o emacs ]]'
Expand All @@ -207,7 +210,13 @@ function ble/init:bind/generate-binder {

# ESC *
if ((esc1B==3)); then
ble/init:bind/append-macro '\e'"$ret" "$altdqs27$ret"
if ((i==0)); then
ble/init:bind/append-macro '\e'"$ret" "$altdqs27$altdqs00"
elif ((bind18XX&&i==24)); then
ble/init:bind/append-macro '\e'"$ret" "$altdqs27$altdqs24"
else
ble/init:bind/append-macro '\e'"$ret" "$altdqs27$ret"
fi
else
if ((esc1B==1)); then
# ESC [
Expand Down
16 changes: 16 additions & 0 deletions note.txt
Expand Up @@ -6666,6 +6666,22 @@ bash_tips

2022-12-13

* bind: M-C-@ が正しく捕まえられていない気がする [#D1920]

bind -s で確認するとマクロ置換後の C-@ が消滅している。これは単にマクロが内
部的に null-terminated string で表現されている為である。

更に同様の状況を考えてみると C-x C-@ も正しく検出できていない。また M-C-x
(in bash-4.2, emacs binding) もその瞬間に検出できていなくて遅延が生じる。実
際にその場で入力を検出できていないという事を確認した。

取り敢えず M-C-@, C-x C-@, M-C-x (bash-4.2 -o emacs) を修正した。

? reject: これは bash の側で修正するべきなのだろうか? 然し、bash は null
terminated な raw string でマクロを補完していて、これを変更するのは難しい
し其処までする理由もない様な気がする。取り敢えずは現在の workaround を保
持して、bash には何も要求しない方向が妥当の気がする。

* highlight: パス名着色において ls_colors が動いていなかった (reported by qoreQyaS) [#D1919]
https://github.com/akinomyoga/ble.sh/issues/263

Expand Down

0 comments on commit a410b03

Please sign in to comment.