Skip to content

Commit

Permalink
global: normalize quoting of function names of the form "prefix:$name"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 19, 2024
1 parent 546499b commit 3d7c98b
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 42 deletions.
10 changes: 5 additions & 5 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}' \"\$@\"; }"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" "$@"
Expand Down
2 changes: 1 addition & 1 deletion contrib
9 changes: 5 additions & 4 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete-def.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/core-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/core-syntax.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions lib/keymap.vi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/canvas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/color.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ function ble/highlight/layer/update {
for ((LEVEL=0;LEVEL<nlevel;LEVEL++)); do
layer=${_ble_highlight_layer_list[LEVEL]}

"ble/highlight/layer:$layer/update" "$text" "$player"
ble/highlight/layer:"$layer"/update "$text" "$player"
# echo "PREV($LEVEL) $PREV_UMIN $PREV_UMAX" >> 1.tmp

player=$layer
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/decode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util.hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 14 additions & 14 deletions src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2609,29 +2609,29 @@ 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
builtin unset -f ble/function#advice/{before,after,around,original}:"$name" 2>/dev/null
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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d7c98b

Please sign in to comment.