Skip to content

Commit

Permalink
decode (rlfunc2widget): re-implement without fork
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 2, 2019
1 parent e163b9a commit d2e7dbe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
11 changes: 10 additions & 1 deletion memo.txt
Expand Up @@ -2208,7 +2208,7 @@ bash_tips
- emacs: support widgets `insert-comment` and `do-lowercase-version` `#D1041` 7aae37b
- main: support options `--version` and `--help` `#D1042` b5ab789
- main: read `.inputrc` as `ble.sh` settings `#D1042` b5ab789
- decode: fix a bug of error messages on reading `.inputrc` `#D1062`
- decode: fix a bug of error messages on reading `.inputrc` `#D1062` e163b9a
- complete: support widget `menu-complete insert_braces` `#D1043` 3d29c8d
- complete (insert_braces): reimplement range contraction `#D1044` dc586da
- complete (insert_braces): remove empty quotations `#D1045` `#D1046` dc586da
Expand Down Expand Up @@ -2247,6 +2247,7 @@ bash_tips
Internal changes
- complete: isolate menu related codes `#D1029` 43bb074
- global: use `builtin echo` explicitly `#D1035` a6232c2
- decode: re-implement rlfunc2widget without fork `#D1063` bee35d8

2019-02-09 (#D0915...#D1015) 949e9a8...df4feaa

Expand Down Expand Up @@ -3194,6 +3195,14 @@ bash_tips

2019-04-02

* 2019-04-02 decode: ble/builtin/bind/rlfunc2widget が遅い [#D1063]
呼び出し回数がそんなになければ良いが inputrc に沢山の項目が書かれていると、
その項目の数だけ awk を fork しなければならない。
特に Cygwin で重くなってしまうのである。実際に Cygwin 上で確認すると重い…。
awk を使わない実装に切り替える事にした。実際に試してみたがそんなに改善していない。
うーん。元々遅かったという事なのかもしれない。
少なくとも多少は早くなったと思うので気にしない事にする。

* decode: 起動時に error_cseq_vbell で変なエラーメッセージが出る様になった… [#D1062]
と思ったらこれは inputrc の decode で発生している様だ。
成る程、decode で visible-bell が表示されては困る。
Expand Down
35 changes: 23 additions & 12 deletions src/decode.sh
Expand Up @@ -2824,25 +2824,36 @@ function ble/builtin/bind/option:r {
ble-decode-key/unbind "${keys[*]}"
}

_ble_decode_rlfunc2widget_emacs=()
_ble_decode_rlfunc2widget_vi_imap=()
_ble_decode_rlfunc2widget_vi_nmap=()
function ble/builtin/bind/rlfunc2widget {
local kmap=$1 rlfunc=$2

local rlfunc_dict=
local rlfunc_file= rlfunc_dict=
case $kmap in
(emacs) rlfunc_dict=$_ble_base/keymap/emacs.rlfunc.txt ;;
(vi_imap) rlfunc_dict=$_ble_base/keymap/vi_imap.rlfunc.txt ;;
(vi_nmap) rlfunc_dict=$_ble_base/keymap/vi_nmap.rlfunc.txt ;;
(emacs) rlfunc_file=$_ble_base/keymap/emacs.rlfunc.txt
rlfunc_dict=_ble_decode_rlfunc2widget_emacs ;;
(vi_imap) rlfunc_file=$_ble_base/keymap/vi_imap.rlfunc.txt
rlfunc_dict=_ble_decode_rlfunc2widget_vi_imap ;;
(vi_nmap) rlfunc_file=$_ble_base/keymap/vi_nmap.rlfunc.txt
rlfunc_dict=_ble_decode_rlfunc2widget_vi_nmap ;;
esac

if [[ $rlfunc_dict && -s $rlfunc_dict ]]; then
local awk_script='$1 == ENVIRON["RLFUNC"] { $1=""; print; exit; }'
ble/util/assign ret 'RLFUNC=$rlfunc ble/bin/awk "$awk_script" "$rlfunc_dict"'
ble/string#trim "$ret"
ret=ble/widget/$ret
local dict script='
((${#RLFUNC_DICT[@]})) ||
ble/util/mapfile RLFUNC_DICT < "$rlfunc_file"
dict=("${RLFUNC_DICT[@]}")'
builtin eval -- "${script//RLFUNC_DICT/$rlfunc_dict}"

local line
for line in "${dict[@]}"; do
[[ $line == "$rlfunc "* ]] || continue
local rl widget; builtin read -r rl widget <<< "$line"
ret=ble/widget/$widget
return 0
else
return 1
fi
done
return 1
}

## 関数 ble/builtin/bind/option:u function
Expand Down

0 comments on commit d2e7dbe

Please sign in to comment.