Skip to content

Commit

Permalink
global: use "_ble_term_IFS"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 20, 2021
1 parent 9bdb37d commit d23ad3c
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion archive/layer/adapter.sh
Expand Up @@ -200,7 +200,7 @@ function ble/syntax-highlight+default/type {
}

function ble/syntax-highlight+default {
local rex IFS=$' \t\n'
local rex IFS=$_ble_term_IFS
local text=$1
local i iN=${#text} w
local mode=cmd
Expand Down
4 changes: 2 additions & 2 deletions ble.pp
Expand Up @@ -1208,7 +1208,7 @@ function ble-attach {
ble/util/buffer.flush >&2

# keymap 初期化
local IFS=$' \t\n'
local IFS=$_ble_term_IFS
ble/decode/initialize # 7ms
ble/decode/reset-default-keymap # 264ms (keymap/vi.sh)
if ! ble/decode/attach; then # 53ms
Expand Down Expand Up @@ -1272,7 +1272,7 @@ function ble/base/unload-for-reload {
}
function ble/base/unload {
ble/util/is-running-in-subshell && return 1
local IFS=$' \t\n'
local IFS=$_ble_term_IFS
builtin unset -v _ble_bash BLE_VERSION BLE_VERSINFO
ble/term/stty/TRAPEXIT
ble/term/leave
Expand Down
2 changes: 1 addition & 1 deletion keymap/emacs.sh
Expand Up @@ -33,7 +33,7 @@ function ble/keymap:emacs/is-command-white {
return 0
elif [[ $1 == ble/widget/* ]]; then
local IFS=$_ble_term_IFS
local cmd=${1#ble/widget/}; cmd=${cmd%%[$' \t\n']*}
local cmd=${1#ble/widget/}; cmd=${cmd%%["$_ble_term_IFS"]*}
[[ $cmd == emacs/* || " ${_ble_keymap_emacs_white_list[*]} " == *" $cmd "* ]] && return 0
fi
return 1
Expand Down
16 changes: 8 additions & 8 deletions keymap/vi.sh
Expand Up @@ -231,7 +231,7 @@ function ble/keymap:vi/imap/is-command-white {
return 0
elif [[ $1 == ble/widget/* ]]; then
local IFS=$_ble_term_IFS
local cmd=${1#ble/widget/}; cmd=${cmd%%[$' \t\n']*}
local cmd=${1#ble/widget/}; cmd=${cmd%%["$_ble_term_IFS"]*}
[[ $cmd == vi_imap/* || " ${_ble_keymap_vi_imap_white_list[*]} " == *" $cmd "* ]] && return 0
fi
return 1
Expand Down Expand Up @@ -892,7 +892,7 @@ function ble/keymap:vi/register#set-edit {
local reg=$1 type=$2 content=$3
if [[ $reg == '' || $reg == 34 ]]; then
local IFS=$_ble_term_IFS
local widget=${WIDGET%%[$' \t\n']*}
local widget=${WIDGET%%["$_ble_term_IFS"]*}
if [[ $content == *$'\n'* || " $widget " == " ${_ble_keymap_vi_register_49_widget_list[*]} " ]]; then
local n
for ((n=9;n>=2;n--)); do
Expand Down Expand Up @@ -3771,7 +3771,7 @@ function ble/widget/vi_nmap/kill-forward-line-and-insert {

function ble/widget/vi-command/forward-word.impl {
local arg=$1 flag=$2 reg=$3 rex_word=$4
local ifs=$' \t\n'
local ifs=$_ble_term_IFS
if [[ $flag == c && ${_ble_edit_str:_ble_edit_ind:1} != [$ifs] ]]; then
# Note: cw cW は特別な動作
# http://vim-jp.org/vimdoc-ja/change.html#cw
Expand All @@ -3795,7 +3795,7 @@ function ble/widget/vi-command/forward-word.impl {
}
function ble/widget/vi-command/forward-word-end.impl {
local arg=$1 flag=$2 reg=$3 rex_word=$4 opts=$5
local IFS=$' \t\n'
local IFS=$_ble_term_IFS
local rex="^([$IFS]*($rex_word)?){0,$arg}" # 単語末端に止まる。空行には止まらない
local offset=1; [[ :$opts: == *:allow_here:* ]] && offset=0
[[ ${_ble_edit_str:_ble_edit_ind+offset} =~ $rex ]]
Expand Down Expand Up @@ -4455,7 +4455,7 @@ function ble/keymap:vi/text-object/word.extend-backward {

function ble/keymap:vi/text-object/word.impl {
local arg=$1 flag=$2 reg=$3 type=$4
local space=$' \t' nl=$'\n' ifs=$' \t\n'
local space=$' \t' nl=$'\n' ifs=$_ble_term_IFS
((arg==0)) && return 0

local rex_word
Expand Down Expand Up @@ -4700,7 +4700,7 @@ function ble/keymap:vi/text-object/block.impl {
## @var[in] beg
## @var[out] end
function ble/keymap:vi/text-object:tag/.find-end-tag {
local ifs=$' \t\n' ret rex
local ifs=$_ble_term_IFS ret rex

rex="^<([^$ifs/>!]+)"; [[ ${_ble_edit_str:beg} =~ $rex ]] || return 1
ble/string#escape-for-extended-regex "${BASH_REMATCH[1]}"; local tagname=$ret
Expand Down Expand Up @@ -4733,7 +4733,7 @@ function ble/keymap:vi/text-object/tag.impl {
fi
fi

local ifs=$' \t\n'
local ifs=$_ble_term_IFS

local beg=$pivot count=$arg
rex="<([^$ifs/>!]+([$ifs]+([^>]*[^/])?)?|/[^>]*)>\$"
Expand Down Expand Up @@ -4855,7 +4855,7 @@ function ble/keymap:vi/text-object/sentence.impl {

# at は後方 (forward) に空白を確保できなければ前方 (backward) に空白を確保する。
if [[ $type != i* && ! $is_interval ]]; then
local ifs=$' \t\n'
local ifs=$_ble_term_IFS
if ((end)) && [[ ${_ble_edit_str:end-1:1} != ["$ifs"] ]]; then
rex="^.*(^$LF?|$LF$LF|[.!?][])'\"]*([ $HT$LF]))([ $HT$LF]*)\$"
if [[ ${_ble_edit_str::beg} =~ $rex ]]; then
Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete-def.sh
Expand Up @@ -42,7 +42,7 @@ bleopt/declare -v complete_contract_function_names 1
bleopt/declare -v complete_auto_complete 1
bleopt/declare -v complete_auto_history 1
bleopt/declare -n complete_auto_delay 1
bleopt/declare -v complete_auto_wordbreaks $' \t\n'
bleopt/declare -v complete_auto_wordbreaks "$_ble_term_IFS"
bleopt/declare -v complete_auto_menu ''
bleopt/declare -v complete_allow_reduction ''

Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete.sh
Expand Up @@ -1973,7 +1973,7 @@ function ble/complete/source:fd {
## @fn ble/complete/progcomp/.compvar-initialize-wordbreaks
## @var[out] wordbreaks
function ble/complete/progcomp/.compvar-initialize-wordbreaks {
local ifs=$' \t\n' q=\'\" delim=';&|<>()' glob='[*?' hist='!^{' esc='`$\'
local ifs=$_ble_term_IFS q=\'\" delim=';&|<>()' glob='[*?' hist='!^{' esc='`$\'
local escaped=$ifs$q$delim$glob$hist$esc
wordbreaks=${COMP_WORDBREAKS//[$escaped]} # =:
}
Expand Down
21 changes: 10 additions & 11 deletions lib/core-syntax.sh
Expand Up @@ -924,10 +924,9 @@ function ble/syntax:text/initialize-vars { :; }
#
#------------------------------------------------------------------------------

_ble_syntax_bash_IFS=$' \t\n'
_ble_syntax_bash_RexSpaces=$'[ \t]+'
_ble_syntax_bash_RexIFSs="[$_ble_syntax_bash_IFS]+"
_ble_syntax_bash_RexDelimiter="[$_ble_syntax_bash_IFS;|&<>()]"
_ble_syntax_bash_RexIFSs="[$_ble_term_IFS]+"
_ble_syntax_bash_RexDelimiter="[$_ble_term_IFS;|&<>()]"
_ble_syntax_bash_RexRedirect='((\{[a-zA-Z_][a-zA-Z_0-9]*\}|[0-9]+)?(&?>>?|>[|&]|<[>&]?|<<[-<]?))[ ]*'

## @var _ble_syntax_bash_chars[]
Expand Down Expand Up @@ -1009,7 +1008,7 @@ _ble_syntax_bash_charsFmt=()
_ble_syntax_bash_chars_simpleDef=
_ble_syntax_bash_chars_simpleFmt=
function ble/syntax:bash/cclass/initialize {
local delimiters="$_ble_syntax_bash_IFS;|&()<>"
local delimiters="$_ble_term_IFS;|&()<>"
local expansions="\$\"\`\\'"
local glob='[*?'
local tilde='~:'
Expand Down Expand Up @@ -2179,7 +2178,7 @@ _ble_syntax_bash_histexpand_RexQuicksubDef=
_ble_syntax_bash_histexpand_RexEventFmt=
_ble_syntax_bash_histexpand_RexQuicksubFmt=
function ble/syntax:bash/check-history-expansion/.initialize {
local spaces=$' \t\n' nl=$'\n'
local spaces=$_ble_term_IFS nl=$'\n'
local rex_event='-?[0-9]+|[!#]|[^-$^*%:'$spaces'=?!#;&|<>()]+|\?[^?'$nl']*\??'
_ble_syntax_bash_histexpand_RexEventDef='^!('$rex_event')'

Expand Down Expand Up @@ -3032,7 +3031,7 @@ function ble/syntax:bash/check-tilde-expansion {
((ctx==CTX_PWORD)) && chars=${chars/'{'/'{}'}

ble/syntax:bash/cclass/update/reorder chars
local delimiters="$_ble_syntax_bash_IFS;|&)<>"
local delimiters="$_ble_term_IFS;|&)<>"
local rex='^(~\+|~[^'$chars']*)([^'$delimiters'/:]?)'; [[ $tail =~ $rex ]]
local str=${BASH_REMATCH[1]}

Expand Down Expand Up @@ -3269,11 +3268,11 @@ function ble/syntax:bash/starts-with-delimiter-or-redirect {
[[ ( $tail =~ ^$delimiters || $wbegin -lt 0 && $tail =~ ^$redirect || $wbegin -lt 0 && $tail == $'\\\n'* ) && $tail != ['<>']'('* ]]
}
function ble/syntax:bash/starts-with-delimiter {
[[ $tail == ["$_ble_syntax_bash_IFS;|&<>()"]* && $tail != ['<>']'('* ]]
[[ $tail == ["$_ble_term_IFS;|&<>()"]* && $tail != ['<>']'('* ]]
}
function ble/syntax:bash/check-word-end/is-delimiter {
local tail=${text:i}
if [[ $tail == [!"$_ble_syntax_bash_IFS;|&<>()"]* ]]; then
if [[ $tail == [!"$_ble_term_IFS;|&<>()"]* ]]; then
return 1
elif [[ $tail == ['<>']* ]]; then
ble/syntax/parse/set-lookahead 2
Expand Down Expand Up @@ -4099,7 +4098,7 @@ function ble/syntax:bash/ctx-values/check-word-end {
((wbegin<0)) && return 1

# 未だ続きがある場合は抜ける
[[ ${text:i:1} == [!"$_ble_syntax_bash_IFS;|&<>()"] ]] && return 1
[[ ${text:i:1} == [!"$_ble_term_IFS;|&<>()"] ]] && return 1

local wbeg=$wbegin wlen=$((i-wbegin)) wend=$i
local word=${text:wbegin:wlen}
Expand Down Expand Up @@ -4196,7 +4195,7 @@ function ble/syntax:bash/ctx-conditions/check-word-end {
((wbegin<0)) && return 1

# 未だ続きがある場合は抜ける
[[ ${text:i:1} == [!"$_ble_syntax_bash_IFS;|&<>()"] ]] && return 1
[[ ${text:i:1} == [!"$_ble_term_IFS;|&<>()"] ]] && return 1

local wbeg=$wbegin wlen=$((i-wbegin)) wend=$i
local word=${text:wbegin:wlen}
Expand Down Expand Up @@ -4433,7 +4432,7 @@ function ble/syntax:bash/ctx-heredoc-word/remove-quotes {
## @var[out] escaped
function ble/syntax:bash/ctx-heredoc-word/escape-delimiter {
local ret=$1
if [[ $ret == *[\\\'$_ble_syntax_bash_IFS$_ble_term_FS]* ]]; then
if [[ $ret == *[\\\'$_ble_term_IFS$_ble_term_FS]* ]]; then
local a b fs=$_ble_term_FS
a=\\ ; b="\\$a"; ret="${ret//"$a"/$b}"
a=\' ; b="\\$a"; ret="${ret//"$a"/$b}"
Expand Down
2 changes: 1 addition & 1 deletion lib/vim-surround.sh
Expand Up @@ -170,7 +170,7 @@ function ble/lib/vim-surround.sh/load-template {
tag=${tag%'>'}
_ble_lib_vim_surround_previous_tag=$tag
fi
local end_tag=${tag%%[$' \t\n']*}
local end_tag=${tag%%["$_ble_term_IFS"]*}
template="<$tag>"$'\r'"</$end_tag>" ;;
('(') template=$'( \r )' ;;
('[') template=$'[ \r ]' ;;
Expand Down
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -136,6 +136,7 @@
- main (`ble/bin/.freeze-utility-path`): fix unupdated temporary implementations `#D1528` c70a3b4
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` c89aa23
- util: inherit special file descriptors `#D1552` 98835b5
- global: use `_ble_term_IFS` 0000000

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
5 changes: 5 additions & 0 deletions src/benchmark.sh
@@ -1,5 +1,10 @@
#!/bin/bash

if ! type ble/util/print &>/dev/null; then
function ble/util/print { builtin printf '%s\n' "$1"; }
function ble/util/print-lines { builtin printf '%s\n' "$@"; }
fi

function ble-measure/.loop {
builtin eval "function _target { $2; }"
local _i _n=$1
Expand Down
2 changes: 1 addition & 1 deletion src/canvas.sh
Expand Up @@ -1848,7 +1848,7 @@ function ble/textmap#update/.wrap {
## @var[in,out] x y
## @var[in,out] _ble_textmap_*
function ble/textmap#update {
local IFS=$' \t\n'
local IFS=$_ble_term_IFS
local dbeg dend dend0
((dbeg=_ble_textmap_dbeg,
dend=_ble_textmap_dend,
Expand Down
10 changes: 5 additions & 5 deletions src/decode.sh
Expand Up @@ -672,7 +672,7 @@ function ble-decode/.hook {
local buflen=${#_ble_decode_input_buffer[@]}
if ((buflen%257==0&&buflen>=2000)); then
# その場で標準入力を読み切る
local IFS=$' \t\n'
local IFS=$_ble_term_IFS
ble-decode/PROLOGUE
local char=${_ble_decode_input_buffer[buflen-1]}
if ((_ble_bash<40000||char==0xC0||char==0xDF)); then
Expand Down Expand Up @@ -701,7 +701,7 @@ function ble-decode/.hook {
# (PROLOGUE 内から呼ばれる) stdout.on より前であれば大丈夫 #D0930
[[ $_ble_bash_options_adjusted ]] && set +v || :

local IFS=$' \t\n'
local IFS=$_ble_term_IFS
ble-decode/PROLOGUE

# abort #D0998
Expand Down Expand Up @@ -3314,7 +3314,7 @@ function ble/builtin/bind/option:m {
function ble/builtin/bind/.decompose-pair {
local LC_ALL= LC_CTYPE=C
local ret; ble/string#trim "$1"
local spec=$ret ifs=$' \t\n' q=\' Q="'\''"
local spec=$ret ifs=$_ble_term_IFS q=\' Q="'\''"
keyseq= value=

# bind '' と指定した時は無視する
Expand Down Expand Up @@ -3437,7 +3437,7 @@ function ble/builtin/bind/option:x {
fi

if [[ $value == \"* ]]; then
local ifs=$' \t\n'
local ifs=$_ble_term_IFS
local rex='^"(([^\"]|\\.)*)"'
if ! [[ $value =~ $rex ]]; then
ble/util/print "ble.sh (bind): no closing '\"' in spec:'${1//$q/$Q}'" >&2
Expand Down Expand Up @@ -3569,7 +3569,7 @@ function ble/builtin/bind/option:- {
local rex='^(([^\"'$q$ifs']|"([^\"]|\\.)*"|'$q'([^\'$q']|\\.)*'$q'|\\.|['$ifs']+[^#'$_ifs'])*)['$ifs']+#'
[[ $arg =~ $rex ]] && arg=${BASH_REMATCH[1]}

local ifs=$' \t\n'
local ifs=$_ble_term_IFS
if [[ $arg == 'set'["$ifs"]* ]]; then
if [[ $_ble_decode_bind_state != none ]]; then
local variable= value= rex=$'^set[ \t]+([^ \t]+)[ \t]+([^ \t].*)$'
Expand Down
8 changes: 8 additions & 0 deletions src/def.sh
@@ -1,5 +1,13 @@
# -*- mode: sh; mode: sh-bash -*-

# Constants (様々な箇所から使うので此処に置く)
_ble_term_nl=$'\n'
_ble_term_FS=$'\034'
_ble_term_SOH=$'\001'
_ble_term_DEL=$'\177'
_ble_term_IFS=$' \t\n'
_ble_term_CR=$'\r'

function blehook/declare {
local name=$1
builtin eval "_ble_hook_h_$name=()"
Expand Down

0 comments on commit d23ad3c

Please sign in to comment.