Skip to content

Commit

Permalink
init: correctly restore unset "IFS" and work around non-canonical "IFS"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 22, 2021
1 parent 462918d commit 5f9adfe
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 108 deletions.
2 changes: 2 additions & 0 deletions archive/getopt.sh
Expand Up @@ -81,10 +81,12 @@ function ble/getopt.init {
OPTIND=1 OPTION= OPTARG=
}
function ble/getopt.print-argument-message {
local IFS=$_ble_term_IFS
local index=$((OPTIND-1))
ble/util/print "${_optargs[0]##*/} (argument#$index \`${_optargs[index]}'): $*" >&2
}
function ble/getopt.print-message {
local IFS=$_ble_term_IFS
local index=$((OPTIND-1))
ble/util/print "${_optargs[0]##*/} (arguments): $*" >&2
}
Expand Down
13 changes: 9 additions & 4 deletions ble.pp
Expand Up @@ -218,6 +218,7 @@ function ble/base/restore-POSIXLY_CORRECT {
return 1 2>/dev/null || builtin exit 1
fi

_ble_init_original_IFS_set=${IFS+set}
_ble_init_original_IFS=$IFS
IFS=$' \t\n'

Expand Down Expand Up @@ -265,8 +266,8 @@ function ble/base/initialize-version-information {

# ble/bin

function ble/util/put { builtin printf '%s' "$*"; }
function ble/util/print { builtin printf '%s\n' "$*"; }
function ble/util/put { builtin printf '%s' "$1"; }
function ble/util/print { builtin printf '%s\n' "$1"; }
function ble/util/print-lines { builtin printf '%s\n' "$@"; }

## @fn ble/bin/.default-utility-path commands...
Expand Down Expand Up @@ -739,7 +740,6 @@ function ble-update {
#%x inc.r|@|lib/core-complete-def|
#%x inc.r|@|lib/core-syntax-def|
#------------------------------------------------------------------------------
# function .ble-time { echo "$*"; time "$@"; }

# blerc
_ble_base_rcfile=
Expand Down Expand Up @@ -1002,7 +1002,12 @@ function ble/base/initialize/.clean-up {
builtin unset -v _ble_init_test

# 状態復元
IFS=$_ble_init_original_IFS
if [[ $_ble_init_original_IFS_set ]]; then
IFS=$_ble_init_original_IFS
else
builtin unset -v IFS
fi
builtin unset -v _ble_init_original_IFS_set
builtin unset -v _ble_init_original_IFS
if [[ ! $_ble_attached ]]; then
ble/base/restore-bash-options
Expand Down
1 change: 1 addition & 0 deletions keymap/emacs.sh
Expand Up @@ -31,6 +31,7 @@ function ble/keymap:emacs/is-command-white {
# frequently used command is checked first
return 0
elif [[ $1 == ble/widget/* ]]; then
local IFS=$_ble_term_IFS
local cmd=${1#ble/widget/}; cmd=${cmd%%[$' \t\n']*}
[[ $cmd == emacs/* || " ${_ble_keymap_emacs_white_list[*]} " == *" $cmd "* ]] && return 0
fi
Expand Down
20 changes: 15 additions & 5 deletions keymap/vi.sh
Expand Up @@ -78,10 +78,10 @@ function ble-edit/content/nonbol-eolp {
! ble-edit/content/bolp "$pos" && ble-edit/content/eolp "$pos"
}

## @fn ble/keymap:vi/string#encode-rot13 text...
## @fn ble/keymap:vi/string#encode-rot13 text
## @var[out] ret
function ble/keymap:vi/string#encode-rot13 {
local text=$*
local text=$1
local -a buff=() ch
for ((i=0;i<${#text};i++)); do
ch=${text:i:1}
Expand Down Expand Up @@ -178,6 +178,7 @@ function ble/keymap:vi/imap-repeat/pop {
((top_index>=0)) && builtin unset -v '_ble_keymap_vi_irepeat[top_index]'
}
function ble/keymap:vi/imap-repeat/push {
local IFS=$_ble_term_IFS
ble/array#push _ble_keymap_vi_irepeat "${KEYS[*]-}:$WIDGET"
}

Expand Down Expand Up @@ -228,6 +229,7 @@ function ble/keymap:vi/imap/is-command-white {
# frequently used command is checked first
return 0
elif [[ $1 == ble/widget/* ]]; then
local IFS=$_ble_term_IFS
local cmd=${1#ble/widget/}; cmd=${cmd%%[$' \t\n']*}
[[ $cmd == vi_imap/* || " ${_ble_keymap_vi_imap_white_list[*]} " == *" $cmd "* ]] && return 0
fi
Expand Down Expand Up @@ -868,6 +870,7 @@ function ble/keymap:vi/register#set-edit {
ble/keymap:vi/register#set "$@" || return 1
local reg=$1 type=$2 content=$3
if [[ $reg == '' || $reg == 34 ]]; then
local IFS=$_ble_term_IFS
local widget=${WIDGET%%[$' \t\n']*}
if [[ $content == *$'\n'* || " $widget " == " ${_ble_keymap_vi_register_49_widget_list[*]} " ]]; then
local n
Expand Down Expand Up @@ -1367,6 +1370,7 @@ function ble/keymap:vi/operator:d {

# yank
IFS=$'\n' builtin eval 'local yank_content="${atext[*]-}"'
local IFS=$_ble_term_IFS
local yank_type=B:"${afill[*]-}"
ble/keymap:vi/register#set-edit "$reg" "$yank_type" "$yank_content" || return 1

Expand Down Expand Up @@ -1456,6 +1460,7 @@ function ble/keymap:vi/operator:y {
done

IFS=$'\n' builtin eval 'local yank_content="${atext[*]-}"'
local IFS=$_ble_term_IFS
yank_type=B:"${afill[*]-}"
else
yank_type=
Expand Down Expand Up @@ -2256,7 +2261,8 @@ function ble/widget/vi-command/linewise-goto.impl {
# single char arguments

function ble/keymap:vi/async-read-char.hook {
local command=${@:1:$#-1} key=${@:$#}
local IFS=$_ble_term_IFS
local command="${*:1:$#-1}" key="${*:$#}"
if ((key==(_ble_decode_Ctrl|0x6B))); then # C-k
ble-decode/keymap/push vi_digraph
_ble_keymap_vi_digraph__hook="$command"
Expand All @@ -2266,6 +2272,7 @@ function ble/keymap:vi/async-read-char.hook {
}

function ble/keymap:vi/async-read-char {
local IFS=$_ble_term_IFS
_ble_decode_key__hook="ble/keymap:vi/async-read-char.hook $*"
return 147
}
Expand Down Expand Up @@ -2330,6 +2337,7 @@ function ble/keymap:vi/mark/update-mark-history {
local value=${_ble_keymap_vi_mark_local[imark]}
ble/array#push save "$imark:$value"
done
local IFS=$_ble_term_IFS
_ble_keymap_vi_mark_history[_ble_keymap_vi_mark_hindex]="${save[*]-}"

# load
Expand Down Expand Up @@ -2658,6 +2666,7 @@ function ble/keymap:vi/repeat/record-special {
return 1
}
function ble/keymap:vi/repeat/record-normal {
local IFS=$_ble_term_IFS
local -a repeat; repeat=("$KEYMAP" "${KEYS[*]-}" "$WIDGET" "$ARG" "$FLAG" "$REG" '')
if [[ $KEYMAP == vi_[xs]map ]]; then
repeat[6]=$_ble_keymap_vi_xmap_prev_edit
Expand All @@ -2684,6 +2693,7 @@ function ble/keymap:vi/repeat/record-insert {
_ble_keymap_vi_repeat_irepeat=("${_ble_keymap_vi_irepeat[@]}")
elif ((${#_ble_keymap_vi_irepeat[@]})); then
# 挿入モード突入操作が初期化されていたら、挿入操作がある時のみに記録
local IFS=$_ble_term_IFS
_ble_keymap_vi_repeat=(vi_nmap "${KEYS[*]-}" ble/widget/vi_nmap/insert-mode 1 '' '')
_ble_keymap_vi_repeat_irepeat=("${_ble_keymap_vi_irepeat[@]}")
fi
Expand All @@ -2700,7 +2710,7 @@ function ble/keymap:vi/repeat/invoke {
local repeat_arg=$_ble_edit_arg
local repeat_reg=$_ble_keymap_vi_reg
local KEYMAP=${_ble_keymap_vi_repeat[0]}
local -a KEYS=(${_ble_keymap_vi_repeat[1]})
local -a KEYS; ble/string#split-words KEYS "${_ble_keymap_vi_repeat[1]}"
local WIDGET=${_ble_keymap_vi_repeat[2]}

# keymap の状態復元
Expand Down Expand Up @@ -3536,7 +3546,7 @@ function ble/widget/vi_nmap/paste.impl/block {

local ret cols=$_ble_textmap_cols

local -a afill=(${_ble_edit_kill_type:2})
local -a afill; ble/string#split-words afill "${_ble_edit_kill_type:2}"
local atext; ble/string#split-lines atext "$_ble_edit_kill_ring"
local ntext=${#atext[@]}

Expand Down
3 changes: 2 additions & 1 deletion lib/core-complete.sh
Expand Up @@ -1394,7 +1394,7 @@ function ble/complete/source/reduce-compv-for-ambiguous-match {
## @var[in] flag_force_fignore
## @var[in] flag_source_filter
function ble/complete/cand/yield {
local ACTION=$1 CAND=$2 DATA="${*:3}"
local ACTION=$1 CAND=$2 DATA=$3
[[ $flag_force_fignore ]] && ! ble/complete/.fignore/filter "$CAND" && return 0

[[ $flag_source_filter ]] ||
Expand Down Expand Up @@ -2491,6 +2491,7 @@ function ble/complete/progcomp/.compgen {
function ble/complete/progcomp/.compline-rewrite-command {
local ocmd=${comp_words[0]}
[[ $1 != "$ocmd" ]] || (($#>=2)) || return 1
local IFS=$_ble_term_IFS
local ins="$*"
comp_line=$ins${comp_line:${#ocmd}}
((comp_point-=${#ocmd},comp_point<0&&(comp_point=0),comp_point+=${#ins}))
Expand Down
7 changes: 6 additions & 1 deletion lib/core-syntax.sh
Expand Up @@ -4923,6 +4923,8 @@ function ble/syntax/parse {
local beg=${3:-0} end=${4:-$iN} end0=${5:-0}
((end==beg&&end0==beg&&_ble_syntax_dbeg<0)) && return 0

local IFS=$_ble_term_IFS

local shift=$((end-end0))
#%if !release
ble/util/assert \
Expand Down Expand Up @@ -5871,6 +5873,7 @@ function ble/syntax:bash/extract-command-by-noderef {
fi
done

local IFS=$_ble_term_IFS
comp_line="${comp_words[*]}"
local tmp="${comp_words[*]::comp_cword+1}"
comp_point=${#tmp}
Expand Down Expand Up @@ -6442,6 +6445,7 @@ function ble/syntax/progcolor/set-wattr {
ble/syntax/urange#update color_ "$wbeg" "$wend"
ble/syntax/wrange#update _ble_syntax_word_ "$TE_i"
node[TE_nofs+4]=$1
local IFS=$_ble_term_IFS
_ble_syntax_tree[TE_i-1]="${node[*]}"
}

Expand Down Expand Up @@ -6813,6 +6817,7 @@ function ble/syntax/progcolor/default {
function ble/syntax/progcolor/.compline-rewrite-command {
local ocmd=${comp_words[0]}
[[ $1 != "$ocmd" ]] || (($#>=2)) || return 1
local IFS=$_ble_term_IFS
local ins="$*"
comp_line=$ins${comp_line:${#ocmd}}
((comp_point-=${#ocmd},comp_point<0&&(comp_point=0),comp_point+=${#ins}))
Expand Down Expand Up @@ -7058,7 +7063,7 @@ function ble/highlight/layer:syntax/update-error-table {
if ((jN)); then
for ((j=0;j<jN;j++)); do
local -a range
range=(${_ble_highlight_layer_syntax3_list[j]})
ble/string#split-words range "${_ble_highlight_layer_syntax3_list[j]}"

local a=${range[0]} b=${range[1]}
((a>=DMAX0?(a+=DMAX-DMAX0):(a>=DMIN&&(a=DMIN)),
Expand Down
2 changes: 1 addition & 1 deletion lib/init-bind.sh
Expand Up @@ -84,7 +84,7 @@ function ble/init:bind/generate-binder {
local bind18XX=0
if ((40400<=_ble_bash&&_ble_bash<50000)); then
# Insert a dummy entry in "cmd_xmap"
ble/util/print "[[ -o emacs ]] && bind 'set keyseq-timeout 1'" >> "$fbind1"
ble/util/print "[[ -o emacs ]] && builtin bind 'set keyseq-timeout 1'" >> "$fbind1"
fbind2=$fbind1 ble/init:bind/append '\C-x\C-x' 24 '[[ -o emacs ]]'
elif ((_ble_bash<40300)); then
bind18XX=1
Expand Down
2 changes: 2 additions & 0 deletions lib/init-term.sh
Expand Up @@ -32,12 +32,14 @@ function ble/init:term/register-varname {
}

function ble/init:term/define-cap {
local IFS=$_ble_term_IFS
local name=$1 def=$2
shift 2
ble/util/assign "$name" "ble/init:term/tput $* || ble/util/put \"\$def\""
ble/init:term/register-varname "$name"
}
function ble/init:term/define-cap.2 {
local IFS=$_ble_term_IFS
local name=$1 def=$2
shift 2
ble/util/assign "$name" "ble/util/put x; ble/init:term/tput $* || ble/util/put \"\$def\"; ble/util/put x"
Expand Down
8 changes: 4 additions & 4 deletions lib/test-main.sh
Expand Up @@ -8,11 +8,11 @@ ble/test/start-section 'main' 14
(
ble/test ble/util/put a stdout=a
ble/test ble/util/print a stdout=a
ble/test ble/util/put a b stdout='a b'
ble/test ble/util/print a b stdout='a b'
ble/test 'ble/util/put a b; ble/util/put c d' \
ble/test 'ble/util/put "a b"' stdout='a b'
ble/test 'ble/util/print "a b"' stdout='a b'
ble/test 'ble/util/put "a b"; ble/util/put "c d"' \
stdout='a bc d'
ble/test 'ble/util/print a b; ble/util/print c d' \
ble/test 'ble/util/print "a b"; ble/util/print "c d"' \
stdout='a b' \
stdout='c d'
)
Expand Down
4 changes: 2 additions & 2 deletions lib/test-util.sh
Expand Up @@ -9,9 +9,9 @@ ble/test/start-section 'util' 1191
(
# 定義・設定・出力
ble/test 'bleopt a=1' \
exit=1
exit=2
ble/test 'bleopt a' \
stdout= exit=1
stdout= exit=2
ble/test 'bleopt a:=2'
ble/test 'bleopt a' \
stdout="bleopt a=2"
Expand Down
2 changes: 2 additions & 0 deletions lib/vim-surround.sh
Expand Up @@ -128,10 +128,12 @@ function ble/lib/vim-surround.sh/async-inputtarget.hook {
fi
}
function ble/lib/vim-surround.sh/async-inputtarget {
local IFS=$_ble_term_IFS
_ble_decode_key__hook="ble/lib/vim-surround.sh/async-inputtarget.hook init:digit $*"
return 147
}
function ble/lib/vim-surround.sh/async-inputtarget-noarg {
local IFS=$_ble_term_IFS
_ble_decode_key__hook="ble/lib/vim-surround.sh/async-inputtarget.hook init $*"
return 147
}
Expand Down
4 changes: 2 additions & 2 deletions make_command.sh
Expand Up @@ -209,7 +209,7 @@ function sub:check-all {
# sub:scan

function sub:scan/grc-source {
local -a options=(--color --exclude=./{test,memo,ext,wiki,contrib,[TD]????.*} --exclude=\*.{md,awk} --exclude=./make_command.sh)
local -a options=(--color --exclude=./{test,memo,ext,wiki,contrib,[TD]????.*} --exclude=\*.{md,awk} --exclude=./{GNUmakefile,make_command.sh})
grc "${options[@]}" "$@"
}
function sub:scan/list-command {
Expand Down Expand Up @@ -261,7 +261,7 @@ function sub:scan/check-todo-mark {
}
function sub:scan/a.txt {
echo "--- $FUNCNAME ---"
grc --color --exclude=./test --exclude=./lib/test-*.sh --exclude=./make_command.sh --exclude=\*.md 'a\.txt|/dev/(pts/|pty)[0-9]*' |
grc --color --exclude=./{test,ext} --exclude=./lib/test-*.sh --exclude=./make_command.sh --exclude=\*.md 'a\.txt|/dev/(pts/|pty)[0-9]*' |
grep -Ev "$rex_grep_head#|[[:space:]]#"
}

Expand Down
6 changes: 4 additions & 2 deletions memo/ChangeLog.md
Expand Up @@ -15,9 +15,9 @@
- canvas, edit: support `bleopt info_display` (suggested by 0neGuyDev) `#D1458` 69228fa
- canvas (panel): always call `panel::render` to update height `#D1472` 51d2c05
- prompt: support `bleopt prompt_status_{line,align}` and `face prompt_status_line` `#D1462` cca1cbc
- prompt: fix missing height allocation for status line `#D1487` 0000000
- prompt: fix missing height allocation for status line `#D1487` b424fa5
- syntax: properly support case patterns `#D1474` `#D1475` `#D1476` 64b55b7
- keymap/vi: add `ble/keymap:vi/script/get-mode` for user-defined mode strings `#D1488` 0000000
- keymap/vi: add `ble/keymap:vi/script/get-mode` for user-defined mode strings `#D1488` f25a6e8 462918d

## Changes

Expand Down Expand Up @@ -57,6 +57,7 @@
- edit: clear graphic rendition on newlines and external commands `#D1479` 18bb2d5
- mandb: improve extraction and cache for each locale `#D1480` 3588158
- decode (rlfunc): work around incomplete bytes in keyseq (reported by onelittlehope) `#D1483` 3559658 beb0383 37363be
- main: fix a bug that unset `IFS` is not correctly restored `#D1489` 0000000

## Compatibility

Expand All @@ -78,6 +79,7 @@
- util, color (`bleopt`, `blehook`, `ble-color-setface`): support `--color` and fix `sgr0` contamination in non-color output `#D1466` 69248ff
- global: fix status check for read timeout `#D1467` e886883
- decode: move `{keymap/*. => lib/core-decode.*-}rlfunc.txt` and clean up files `#D1486` f7323b4
- util, etc: ensure each function to work with arbitrary `IFS` `#D1490` `#D1491` 0000000

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down

0 comments on commit 5f9adfe

Please sign in to comment.