From 3d7c98bb7a75adc0e239ad006048a6acccd66715 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 25 Sep 2024 15:35:51 +0900 Subject: [PATCH] global: normalize quoting of function names of the form "prefix:$name" --- ble.pp | 10 +++++----- contrib | 2 +- docs/ChangeLog.md | 9 +++++---- lib/core-complete-def.sh | 2 +- lib/core-complete.sh | 8 ++++---- lib/core-syntax.sh | 4 ++-- lib/keymap.vi.sh | 4 ++-- note.txt | 27 +++++++++++++++++++++++++++ src/canvas.sh | 4 ++-- src/color.sh | 4 ++-- src/decode.sh | 8 ++++---- src/util.hook.sh | 2 +- src/util.sh | 28 ++++++++++++++-------------- 13 files changed, 70 insertions(+), 42 deletions(-) diff --git a/ble.pp b/ble.pp index d9758c74..e949d0e5 100644 --- a/ble.pp +++ b/ble.pp @@ -1224,8 +1224,8 @@ function ble/bin#freeze-utility-path { flags=n$flags continue fi - [[ $flags == *n* ]] && ble/bin#has "ble/bin/$cmd" && continue - ble/bin#has "ble/bin/.frozen:$cmd" && continue + [[ $flags == *n* ]] && ble/bin#has ble/bin/"$cmd" && continue + ble/bin#has ble/bin/.frozen:"$cmd" && continue if ble/bin#get-path "$cmd"; then [[ $path == ./* || $path == ../* ]] && path=$PWD/$path builtin eval "function ble/bin/$cmd { '${path//$q/$Q}' \"\$@\"; }" @@ -1419,7 +1419,7 @@ function ble/bin/awk/.instantiate { ble/util/unlocal LC_ALL LC_CTYPE LC_COLLATE 2>/dev/null return "$ext" } - elif [[ $_ble_bin_awk_type == [gmn]awk ]] && ! ble/is-function "ble/bin/$_ble_bin_awk_type" ; then + elif [[ $_ble_bin_awk_type == [gmn]awk ]] && ! ble/is-function ble/bin/"$_ble_bin_awk_type" ; then builtin eval "function ble/bin/$_ble_bin_awk_type { '${path//$q/$Q}' -v AWKTYPE=$_ble_bin_awk_type \"\$@\"; }" fi fi @@ -2507,8 +2507,8 @@ function ble/dispatch { (check|--test) ble/base/sub:test "$@" ;; (*) if ble/string#match "$cmd" '^[-a-zA-Z0-9]+$'; then - if ble/is-function "ble/dispatch:$cmd"; then - "ble/dispatch:$cmd" "$@" + if ble/is-function ble/dispatch:"$cmd"; then + ble/dispatch:"$cmd" "$@" return "$?" elif ble/is-function "ble-$cmd"; then "ble-$cmd" "$@" diff --git a/contrib b/contrib index 3a48ee23..cfabc321 160000 --- a/contrib +++ b/contrib @@ -1 +1 @@ -Subproject commit 3a48ee23fbfc3d387896a7c22a3f83b55c449b17 +Subproject commit cfabc3212aa62ec7033e6f29bd90f259ce48abb8 diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 3638ab9f..e253d5f9 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -92,7 +92,7 @@ - exec: refine the elapsed time resolution `#D2249` 67548656 713c4215 - highlight (`ble/syntax/highlight/vartype`): reference the saved states of variables `#D2268` 063249b4 - complete: attempt pathname expansions of incomplete pattern for `COMPV` (reported by mcepl) `#D2278` 6a426954 -- make: save commit id and branch name with `git archive` (requested by LecrisUT, blackteahamburger) `#D2290` xxxxxxxx +- make: save commit id and branch name with `git archive` (requested by LecrisUT, blackteahamburger) `#D2290` 31f264ad ## Fixes @@ -146,7 +146,7 @@ - mandb: fix incorrect use of `groff` in place of `nroff` `#D2245` e0ffc418 - edit: fix fd broken by ble-attach of new session in user space (reported by JohEngstrom) `#D2271` 49f97618 670c7ea0 - util (`ble-import`): do not specify arguments to `-C callback` `#D2277` 4f0e94a2 -- main: fix issues with `ble/bin/awk` (reported by devidw) `#D2292` xxxxxxxx +- main: fix issues with `ble/bin/awk` (reported by devidw) `#D2292` b0a7adcb ## Compatibility @@ -195,7 +195,7 @@ - mandb: process less formatting sequences in parsing `--help` `#D2244` 60d36ba5 - mandb: hook into bash-completion's `_comp_command_offset` `#D2255` cbcce625 - canvas: update tables for Unicode 16.0.0 `#D2283` 5b43ca3f 25a10a6f -- complete: work around `mawk <= 1.3.4-20200525` type-inference bug (reported by KaKi87) `#D2295` xxxxxxxx +- complete: work around `mawk <= 1.3.4-20230525` type-inference bug (reported by KaKi87) `#D2295` 546499b5 ## Contrib @@ -240,7 +240,7 @@ - docs(README): note `bleopt prompt_command_changes_layout=1` `#D2196` 208eaa9d - docs(README): move disclaimers to a later section `#D2250` ad6f58b7 - README: use `[[ ! ${BLE_VERSION-} ]] || ble-attach` `#D2264` ed11901a -- github: update GitHub issue templates `#D2294` xxxxxxxx +- github: update GitHub issue templates `#D2294` aa396f60 ## Test @@ -286,6 +286,7 @@ - main: refactor initialization sequence `#D2231` cc9d7f39 - util (`ble/util/is-stdin-ready`): check `$_ble_util_fd_tui_stdin` by default `#D2254` 29c00fd8 - decode (`ble-decode-key/bind`): reference the argument to check the widget name (contributed by musou1500) `#D2279` 21b1bb3d +- global: normalize quoting of function names of the form `prefix:$name` `#D2296` xxxxxxxx # ble-0.4.0-devel3 diff --git a/lib/core-complete-def.sh b/lib/core-complete-def.sh index 903b2d78..1249b351 100644 --- a/lib/core-complete-def.sh +++ b/lib/core-complete-def.sh @@ -67,7 +67,7 @@ bleopt/declare -v complete_requote_threshold 0 bleopt/declare -n complete_menu_style align-nowrap function bleopt/check:complete_menu_style { [[ $value == desc-raw ]] && value=desc - if ! ble/is-function "ble/complete/menu-style:$value/construct-page"; then + if ! ble/is-function ble/complete/menu-style:"$value"/construct-page; then ble/util/print-lines \ "bleopt: Invalid value complete_menu_style='$value'." \ " A function 'ble/complete/menu-style:$value/construct-page' is not defined." >&2 diff --git a/lib/core-complete.sh b/lib/core-complete.sh index b1f73b35..e3e5238a 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -4626,14 +4626,14 @@ function ble/complete/progcomp { orig_qcmds_set=1 orig_qcmds=("${qcmds[@]}") fi - if ble/is-function "ble/cmdinfo/complete:$ucmd"; then + if ble/is-function ble/cmdinfo/complete:"$ucmd"; then ble/complete/progcomp/.compline-rewrite-command "${qcmds[@]}" "${alias_args[@]}" - "ble/cmdinfo/complete:$ucmd" "$opts" + ble/cmdinfo/complete:"$ucmd" "$opts" return "$?" - elif [[ $ucmd == */?* ]] && ble/is-function "ble/cmdinfo/complete:${ucmd##*/}"; then + elif [[ $ucmd == */?* ]] && ble/is-function ble/cmdinfo/complete:"${ucmd##*/}"; then ble/string#quote-word "${ucmd##*/}"; qcmds[0]=$ret ble/complete/progcomp/.compline-rewrite-command "${qcmds[@]}" "${alias_args[@]}" - "ble/cmdinfo/complete:${ucmd##*/}" "$opts" + ble/cmdinfo/complete:"${ucmd##*/}" "$opts" return "$?" elif builtin complete -p -- "$ucmd" &>/dev/null; then cmd=$ucmd diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index d1c8ff5c..2406272d 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -6086,7 +6086,7 @@ function ble/syntax/completion-context/.check-prefix { local wbeg=$((wlen<0?wlen:istat-wlen)) local name=${_ble_syntax_completion_context_check_prefix[ctx]} if [[ $name ]]; then - builtin eval "ble/syntax/completion-context/prefix:$name" + builtin eval ble/syntax/completion-context/prefix:"$name" fi } @@ -6231,7 +6231,7 @@ function ble/syntax/completion-context/.check-here { # 補完文脈が他に生成しようがない状況に限定される。この時、実は # .check-here の側は修正は必要なかった。 local proc=${_ble_syntax_completion_context_check_here[stat[0]]-} - builtin eval "ble/syntax/completion-context/here:$proc" + builtin eval ble/syntax/completion-context/here:"$proc" fi } diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh index c50856c4..e302db2c 100644 --- a/lib/keymap.vi.sh +++ b/lib/keymap.vi.sh @@ -5363,7 +5363,7 @@ function ble/widget/vi-command/commandline { function ble/widget/vi-command/commandline.hook { local command ble/string#split-words command "$1" - local cmd="ble/widget/vi-command:${command[0]}" + local cmd=ble/widget/vi-command:"${command[0]}" if ble/is-function "$cmd"; then "$cmd" "${command[@]:1}"; local ext=$? else @@ -7352,7 +7352,7 @@ function ble/widget/vi_xmap/connect-line.impl { _ble_keymap_vi_oparg= _ble_keymap_vi_opfunc= _ble_keymap_vi_reg= - "ble/widget/$name" + ble/widget/"$name" } # xmap J function ble/widget/vi_xmap/connect-line-with-space { diff --git a/note.txt b/note.txt index 5a2e27c5..7cd90d2d 100644 --- a/note.txt +++ b/note.txt @@ -7700,6 +7700,33 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2024-12-12 + + * style: prefix:$name の形をしている定義関数の呼び出しのクォートを調整 [#D2296] + + "ble/.../prefix:$name" としている場合と ble/.../prefix:"$name" としている場 + 合がある。検索する時に探しにくいので統一したい。特に :"$name" の方が特徴的 + で検索しやすいのでそちらに統一する事にする。但し、関数呼び出し以外の文脈で + どの様にするかは微妙である。 + + * エラーメッセージの一部の場合は全体としてクォートしているので :"$name" の + 様なクォートにはできない。 + + * コメントの内部の解説の場合にも微妙である。他にも prefix:"$name" に似た形 + をしているが自動生成したラムダ式などの関数名も存在する。元々、ユーザーな + どが後付けで定義する時の関数のクォートとして prefix:"$name" を使うので、 + 自動生成する関数には適用しない事にする。但し、 + ble/function#advice/original:"$name" 等についてはちゃんと prefix:"$name" + の形になっているので :"$name" の形式を採用する事にする。 + + * ble/is-function 関数名 の場合には関数呼び出しと対になっている事が多いとい + う事、右辺に関数名が来ることが決まりきっている事などから :"$name" のクォー + トを採用する事にする。その他の一般の関数の引数 (callback など) として指定 + する場合は微妙だが全体をクォートする事にする。 + + * 類似の物として ble/widget/WIDGET_NAME などスラッシュで区切られた物も存在 + する。これについても同様に統一する事にする。 + 2024-12-11 * complete: mawk-1.3.4-20230525 以前でプログラム補完が全く効かない (reported by KaKi87) [#D2295] diff --git a/src/canvas.sh b/src/canvas.sh index a9e6e73d..0425967f 100644 --- a/src/canvas.sh +++ b/src/canvas.sh @@ -62,7 +62,7 @@ function ble/util/c2w/clear-cache { ## 定義 ble/util/c2w:$bleopt_char_width_mode bleopt/declare -n char_width_mode auto function bleopt/check:char_width_mode { - if ! ble/is-function "ble/util/c2w:$value"; then + if ! ble/is-function ble/util/c2w:"$value"; then ble/util/print "bleopt: Invalid value char_width_mode='$value'. A function 'ble/util/c2w:$value' is not defined." >&2 return 1 fi @@ -83,7 +83,7 @@ function bleopt/check:char_width_mode { function ble/util/c2w { ret=${_ble_util_c2w_cache[$1]:-${_ble_util_c2w[$1]}} if [[ ! $ret ]]; then - "ble/util/c2w:$bleopt_char_width_mode" "$1" + ble/util/c2w:"$bleopt_char_width_mode" "$1" _ble_util_c2w_cache[$1]=$ret fi } diff --git a/src/color.sh b/src/color.sh index a6cd9e32..1f311852 100644 --- a/src/color.sh +++ b/src/color.sh @@ -1578,7 +1578,7 @@ function ble/highlight/layer/update { for ((LEVEL=0;LEVEL> 1.tmp player=$layer @@ -1614,7 +1614,7 @@ function ble/highlight/layer/update/getg { g= local LEVEL=$LEVEL while ((--LEVEL>=0)); do - "ble/highlight/layer:${_ble_highlight_layer_list[LEVEL]}/getg" "$1" + ble/highlight/layer:"${_ble_highlight_layer_list[LEVEL]}"/getg "$1" [[ $g ]] && return 0 done g=0 diff --git a/src/decode.sh b/src/decode.sh index 6752a1e7..0012e238 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -838,7 +838,7 @@ ble/debug/leakvar#check $"leakvar" H2-abort #%if leakvar ble/debug/leakvar#check $"leakvar" "[H3b1: before decode $chars...]" #%end.i - "ble/encoding:$bleopt_input_encoding/decode" "${chars[@]:i:B}" + ble/encoding:"$bleopt_input_encoding/decode" "${chars[@]:i:B}" #%if leakvar ble/debug/leakvar#check $"leakvar" "[H3b1: after decode $chars...]" #%end.i @@ -853,7 +853,7 @@ ble/debug/leakvar#check $"leakvar" "[H3b1: after decode $chars...]" #%if leakvar ble/debug/leakvar#check $"leakvar" "[H3b2: before decode $c]" #%end.i - "ble/encoding:$bleopt_input_encoding/decode" "$c" + ble/encoding:"$bleopt_input_encoding/decode" "$c" #%if leakvar ble/debug/leakvar#check $"leakvar" "[H3b2: after decode $c]" #%end.i @@ -884,7 +884,7 @@ ble/debug/leakvar#check $"leakvar" H4-EPILOGUE ## この関数はユーザが呼び出す事を想定した関数です。 function ble-decode-byte { while (($#)); do - "ble/encoding:$bleopt_input_encoding/decode" "$1" + ble/encoding:"$bleopt_input_encoding"/decode "$1" shift done } @@ -2422,7 +2422,7 @@ ble/debug/leakvar#check $"leakvar" "widget $WIDGET" } ## @fn ble/decode/widget/dispatch widget args... function ble/decode/widget/dispatch { - local ret; ble/string#quote-command "ble/widget/${1#ble/widget/}" "${@:2}" + local ret; ble/string#quote-command ble/widget/"${1#ble/widget/}" "${@:2}" local WIDGET=$ret _ble_decode_widget_last=$WIDGET #%if leakvar diff --git a/src/util.hook.sh b/src/util.hook.sh index 304a0bd2..6cf0d7e3 100644 --- a/src/util.hook.sh +++ b/src/util.hook.sh @@ -1087,7 +1087,7 @@ function ble/builtin/trap/install-hook { # る事は想定していないので、builtin trap から読み取った結果は ble.sh ロー # ド前と想定して良い。 ! ble/builtin/trap/user-handler#has "$sig" && - builtin eval -- "ble/builtin/$trap_string" + builtin eval -- ble/builtin/"$trap_string" fi return "$ext" diff --git a/src/util.sh b/src/util.sh index deb69abe..290f7177 100644 --- a/src/util.sh +++ b/src/util.sh @@ -311,23 +311,23 @@ function bleopt/reinitialize { ## @bleopt input_encoding bleopt/declare -n input_encoding UTF-8 function bleopt/check:input_encoding { - if ! ble/is-function "ble/encoding:$value/decode"; then + if ! ble/is-function ble/encoding:"$value"/decode; then ble/util/print "bleopt: Invalid value input_encoding='$value'." \ "A function 'ble/encoding:$value/decode' is not defined." >&2 return 1 - elif ! ble/is-function "ble/encoding:$value/b2c"; then + elif ! ble/is-function ble/encoding:"$value"/b2c; then ble/util/print "bleopt: Invalid value input_encoding='$value'." \ "A function 'ble/encoding:$value/b2c' is not defined." >&2 return 1 - elif ! ble/is-function "ble/encoding:$value/c2bc"; then + elif ! ble/is-function ble/encoding:"$value"/c2bc; then ble/util/print "bleopt: Invalid value input_encoding='$value'." \ "A function 'ble/encoding:$value/c2bc' is not defined." >&2 return 1 - elif ! ble/is-function "ble/encoding:$value/generate-binder"; then + elif ! ble/is-function ble/encoding:"$value"/generate-binder; then ble/util/print "bleopt: Invalid value input_encoding='$value'." \ "A function 'ble/encoding:$value/generate-binder' is not defined." >&2 return 1 - elif ! ble/is-function "ble/encoding:$value/is-intermediate"; then + elif ! ble/is-function ble/encoding:"$value"/is-intermediate; then ble/util/print "bleopt: Invalid value input_encoding='$value'." \ "A function 'ble/encoding:$value/is-intermediate' is not defined." >&2 return 1 @@ -2609,13 +2609,13 @@ function ble/function#advice { case $type in (remove) if [[ $def == *'ble/function#advice/.proc'* ]]; then - ble/function#getdef "ble/function#advice/original:$name" + ble/function#getdef ble/function#advice/original:"$name" if [[ $def ]]; then if [[ $def == *ZBe85Oe28nBdg* ]]; then builtin unset -f "$name" else ble/function#evaldef "${def#*:}" - ble/function#copy-trace "ble/function#advice/original:$name" "$name" + ble/function#copy-trace ble/function#advice/original:"$name" "$name" fi fi fi @@ -2623,15 +2623,15 @@ function ble/function#advice { return 0 ;; (before|after|around) if [[ $def != *'ble/function#advice/.proc'* ]]; then - ble/function#evaldef "ble/function#advice/original:$def" - ble/function#copy-trace "$name" "ble/function#advice/original:$name" + ble/function#evaldef ble/function#advice/original:"$def" + ble/function#copy-trace "$name" ble/function#advice/original:"$name" builtin eval "function $name { ble/function#advice/.proc \"\$FUNCNAME\" \"\$@\"; }" - ble/function#copy-trace "ble/function#advice/original:$name" "$name" + ble/function#copy-trace ble/function#advice/original:"$name" "$name" fi local q=\' Q="'\''" builtin eval "ble/function#advice/$type:$name() { builtin eval -- '${proc//$q/$Q}'; }" - ble/function#copy-trace "ble/function#advice/original:$name" "ble/function#advice/$type:$name" + ble/function#copy-trace ble/function#advice/original:"$name" ble/function#advice/$type:"$name" return 0 ;; (*) ble/util/print "ble/function#advice unknown advice type '$type'" >&2 @@ -7728,7 +7728,7 @@ else done <<< "$s" IFS=$_ble_term_IFS ' - "ble/encoding:$bleopt_input_encoding/b2c" $bytes + ble/encoding:"$bleopt_input_encoding"/b2c $bytes } fi @@ -7864,7 +7864,7 @@ function ble/util/chars2s { ## @param[in] $1 = code ## @param[out] ret function ble/util/c2bc { - "ble/encoding:$bleopt_input_encoding/c2bc" "$1" + ble/encoding:"$bleopt_input_encoding"/c2bc "$1" } ## @fn ble/util/.update-locale-cache @@ -7950,7 +7950,7 @@ function ble/util/.update-locale-cache { fi ' fi - elif ble/is-function "ble/encoding:$enc/b2c"; then + elif ble/is-function ble/encoding:"$enc"/b2c; then _ble_util_locale_encoding=$enc fi fi