Skip to content

Commit

Permalink
cmdspec: fix completion and highlighting of declare
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 16, 2021
1 parent da38404 commit e12bae4
Show file tree
Hide file tree
Showing 14 changed files with 659 additions and 252 deletions.
1 change: 1 addition & 0 deletions GNUmakefile
Expand Up @@ -71,6 +71,7 @@ outfiles += $(OUTDIR)/lib/init-msys1.sh
outfiles += $(OUTDIR)/lib/core-complete.sh
outfiles += $(OUTDIR)/lib/core-syntax.sh
outfiles += $(OUTDIR)/lib/core-test.sh
outfiles += $(OUTDIR)/lib/core-cmdspec.sh
outfiles += $(OUTDIR)/lib/core-edit.ignoreeof-messages.txt
outfiles += $(OUTDIR)/lib/core-decode.emacs-rlfunc.txt
outfiles += $(OUTDIR)/lib/core-decode.vi_imap-rlfunc.txt
Expand Down
2 changes: 2 additions & 0 deletions README-ja_JP.md
Expand Up @@ -441,6 +441,8 @@ ble-face -s varname_number fg=64
ble-face -s varname_readonly fg=200
ble-face -s varname_transform fg=29,bold
ble-face -s varname_unset fg=124
ble-face -s argument_option fg=teal
ble-face -s argument_error fg=black,bg=225
```

現在の描画設定の一覧は以下のコマンドでも確認できます (`ble-face` を無引数で呼び出す)。
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -411,6 +411,9 @@ ble-face -s varname_number fg=64
ble-face -s varname_readonly fg=200
ble-face -s varname_transform fg=29,bold
ble-face -s varname_unset fg=124
ble-face -s argument_option fg=teal
ble-face -s argument_error fg=black,bg=225

```

The current list of faces can be obtained by the following command (`ble-face` without arguments):
Expand Down
1 change: 1 addition & 0 deletions ble.pp
Expand Up @@ -1214,6 +1214,7 @@ function ble-update {
#%x inc.r|@|src/edit|
#%x inc.r|@|lib/core-syntax-def|
#%x inc.r|@|lib/core-complete-def|
#%x inc.r|@|lib/core-cmdspec-def|

bleopt -I
#------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions blerc
Expand Up @@ -663,6 +663,7 @@
#ble-face -s command_jobs fg=red,bold
#ble-face -s command_directory fg=navy,underline
#ble-face -s argument_option fg=teal
#ble-face -s argument_option fg=black,bg=225
#ble-face -s filename_directory underline,fg=26
#ble-face -s filename_directory_sticky underline,fg=white,bg=26
#ble-face -s filename_link underline,fg=teal
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -83,6 +83,7 @@
- term: let <kbd>DECSCUSR</kbd> pass through terminal multiplexers (motivated by cmplstofB) `#D1697` 0000000
- complete: requote for more compact representations on full completions `#D1700` 0000000
- complete: improve support for `declare` and `[[ ... ]]` `#D1701` 0000000
- syntax: fix completion and highlighting of `declare` with assignment arguments `#D1704` `#D1705` 0000000

## Changes

Expand Down
4 changes: 4 additions & 0 deletions lib/core-cmdspec-def.sh
@@ -0,0 +1,4 @@
# -*- mode: sh; mode: sh-bash -*-

function ble/cmdspec/initialize { ble-import "$_ble_base/lib/core-cmdspec.sh"; }
ble/is-function ble/util/idle.push && ble-import -d "$_ble_base/lib/core-cmdspec.sh"
46 changes: 46 additions & 0 deletions lib/core-cmdspec.sh
@@ -0,0 +1,46 @@
# -*- mode: sh; mode: sh-bash -*-

function ble/cmdspec/initialize { return 0; }
ble-import core-complete

function ble/cmdinfo/cmd:declare/chroma.wattr {
local ret
if ((wtype==_ble_attr_VAR)); then
ble/syntax:bash/find-rhs "$wtype" "$wbeg" "$wlen" element-assignment &&
ble/progcolor/highlight-filename.wattr "$ret" "$wend"
else
ble/progcolor/eval-word || return "$?"

local wval=$ret
if ble/string#match "$wval" '^([_a-zA-Z][_a-zA-Z0-9]*)(\[.+\])?$'; then
# ToDo: properly support quoted case
local varname=${BASH_REMATCH[1]}
ble/syntax/highlight/vartype "$varname"
ble/progcolor/wattr#setattr "$wbeg" "$ret"
ble/progcolor/wattr#setattr $((wbeg+${#varname})) d
elif ble/string#match "$wval" '^[-+]' && ble/progcolor/is-option-context; then
# ToDo: validate available options
local ret; ble/color/face2g argument_option
ble/progcolor/wattr#setg "$wbeg" "$ret"
else
local ret; ble/color/face2g argument_error
ble/progcolor/wattr#setg "$wbeg" "$ret"
fi
fi
return 0
}

function ble/cmdinfo/cmd:declare/chroma {
local i "${_ble_syntax_progcolor_vars[@]/%/=}" # WA #D1570 checked
for ((i=1;i<${#comp_words[@]};i++)); do
local ref=${tree_words[i]}
[[ $ref ]] || continue
local progcolor_iword=$i
ble/progcolor/load-word-data "$ref"
ble/progcolor/@wattr ble/cmdinfo/cmd:declare/chroma.wattr
done
}
function ble/cmdinfo/cmd:typeset/chroma { ble/cmdinfo/cmd:declare/chroma "$@"; }
function ble/cmdinfo/cmd:local/chroma { ble/cmdinfo/cmd:declare/chroma "$@"; }
function ble/cmdinfo/cmd:readonly/chroma { ble/cmdinfo/cmd:declare/chroma "$@"; }
function ble/cmdinfo/cmd:export/chroma { ble/cmdinfo/cmd:declare/chroma "$@"; }
35 changes: 16 additions & 19 deletions lib/core-complete.sh
Expand Up @@ -4089,23 +4089,24 @@ function ble/complete/mandb/initialize-mandb-opts {
-ge (NUM1 -ge NUM2) Arithmetic comparison >=.
-nt (FILE1 -nt FILE2) True if file1 is newer than file2 (according to modification date).
-ot (FILE1 -ot FILE2) True if file1 is older than file2.
-ef (FILE1 -ef FILE2) True if file1 is a hard link to file2.
'
ble/complete/mandb/opt help=%'help test':help=@"$conditional_operators" '[['
-ef (FILE1 -ef FILE2) True if file1 is a hard link to file2.'
ble/complete/mandb/opt ignore-double-hyphen:help=%'help test':help=@"$conditional_operators" '[['

local test_operators=$conditional_operators'
-a (EXPR1 -a EXPR2) True if both expr1 AND expr2 are true.
-a (EXPR1 -o EXPR2) True if either expr1 OR expr2 is true.
'
ble/complete/mandb/opt help=%'help test':help=@"$test_operators" 'test' '['
-a (EXPR1 -o EXPR2) True if either expr1 OR expr2 is true.'
ble/complete/mandb/opt ignore-double-hyphen:help=%'help test':help=@"$test_operators" 'test' '['

ble/complete/mandb/opt no-man:help:stop-after-argument:plus-option=aAilnrtux declare typeset local
ble/complete/mandb/opt no-man:help:stop-after-argument local export readonly
ble/complete/mandb/opt no-man:help:stop-after-argument alias
}
ble/complete/mandb/initialize-mandb-opts

## @fn ble/complete/mandb/get-opts command
## @fn ble/complete/mandb/get-opts command [default_value]
## @var[out] mandb_opts
function ble/complete/mandb/get-opts {
mandb_opts=$2
local ret=
if ble/gdict#get _ble_complete_mandb_opts "$1" ||
{ [[ $1 == */*[!/] ]] && ble/gdict#get _ble_complete_mandb_opts "${1##*/}"; }
Expand Down Expand Up @@ -4242,26 +4243,21 @@ function ble/complete/mandb/load-cache {
function ble/complete/source:option/.stops-option {
(($#)) || return 1

local reject= rex_req=
local reject= rexreq=
[[ :$mandb_opts: != *:ignore-double-hyphen:* ]] && reject=--
if [[ :$mandb_opts: == *:stop-after-argument:* ]]; then
rex_req='^-.+'
if ble/string#match ":$mandb_opts:" ':plus-option(=[^:]+)?:'; then
if [[ ${BASH_REMATCH[1]} ]]; then
[[ ${BASH_REMATCH[1]:1} ]] &&
rex_req='^-.+|^\+['${BASH_REMATCH[1]:1}']'
else
rex_req='^[-+].+'
fi
rexreq='^-.+'
if ble/string#match ":$mandb_opts:" ':plus-option(=[^:]*)?:'; then
rexreq='^[-+].+'
fi
fi
[[ $reject$rex_req ]] || return 1
[[ $reject$rexreq ]] || return 1

local word ret
for word; do
ble/syntax:bash/simple-word/is-simple "$word" &&
ble/syntax:bash/simple-word/eval "$word" noglob &&
[[ $reject && $ret == $reject || $rex_req && ! ( $ret =~ $rex_req ) ]] &&
[[ $reject && $ret == $reject || $rexreq && ! ( $ret =~ $rexreq ) ]] &&
return 0
done
return 1
Expand All @@ -4286,7 +4282,7 @@ function ble/complete/source:option {
local alias_checked=' '
while local ret; ! ble/complete/mandb/load-cache "$cmd"; do
alias_checked=$alias_checked$cmd' '
ble/util/expand-alias "$cmd"
ble/util/expand-alias "$cmd" || return 1
local words; ble/string#split-words ret "$ret"; words=("${ret[@]}")

# 変数代入は読み飛ばし
Expand Down Expand Up @@ -4549,6 +4545,7 @@ function ble/complete/context/overwrite-sources {
function ble/complete/context:syntax/generate-sources {
ble/syntax/import
ble-edit/content/update-syntax
ble/cmdspec/initialize # load user configruation
ble/syntax/completion-context/generate "$comp_text" "$comp_index"
((${#sources[@]}))
}
Expand Down
1 change: 1 addition & 0 deletions lib/core-syntax-def.sh
Expand Up @@ -177,5 +177,6 @@ function ble/syntax/defface.onload {
ble/color/defface varname_transform fg=29,bold
ble/color/defface varname_export fg=200,bold
ble/color/defface argument_option fg=teal
ble/color/defface argument_error fg=black,bg=225
}
blehook/eval-after-load color_defface ble/syntax/defface.onload

0 comments on commit e12bae4

Please sign in to comment.