Skip to content

Commit

Permalink
syntax: revert 371a5a4 and generate empty completion source on syntax…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
akinomyoga committed Dec 11, 2021
1 parent 6123551 commit e09fcab
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 29 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -121,6 +121,7 @@
- main: suppress non-interactive warnings from manually sourced startup files (reported by andreclerigo) `#D1676` 0525528 88e2df5
- mandb: integrate `mandb` with `bash-completion` (motivated by Shahabaz-Bagwan, bbyfacekiller and EmilySeville7cfg) `#D1688` c1cd666
- syntax: do not start argument completions immediately after previous word (reported by EmilySeville7cfg) `#D1690` 371a5a4
- syntax: revert 371a5a4 and generate empty completion source on syntax error `#D1609` 0000000
- syntax: strictly check variable names of `for`-statements `#D1692` d056547
- widget `self-insert`: untranslate control chars and insert the last character `#D1696` 0000000

Expand Down
40 changes: 24 additions & 16 deletions lib/core-complete.sh
Expand Up @@ -1244,12 +1244,31 @@ function ble/complete/action/inherit-from {
}

# action:plain

function ble/complete/action:plain/initialize {
ble/complete/action/util/quote-insert
}
function ble/complete/action:plain/complete { :; }

# action:literal-substr
function ble/complete/action:literal-substr/initialize { :; }
function ble/complete/action:literal-substr/complete { :; }

# action:substr (equivalent to plain)
function ble/complete/action:substr/initialize {
ble/complete/action/util/quote-insert
}
function ble/complete/action:substr/complete { :; }

# action:literal-word
function ble/complete/action:literal-word/initialize { :; }
function ble/complete/action:literal-word/complete {
if [[ $comps_flags == *x* ]]; then
ble/complete/action/util/complete.addtail ','
else
ble/complete/action/util/complete.addtail ' '
fi
}

# action:word
#
# DATA ... 候補の説明として使用する文字列を指定します
Expand All @@ -1259,26 +1278,12 @@ function ble/complete/action:word/initialize {
}
function ble/complete/action:word/complete {
ble/complete/action/util/complete.close-quotation
if [[ $comps_flags == *x* ]]; then
ble/complete/action/util/complete.addtail ','
else
ble/complete/action/util/complete.addtail ' '
fi
ble/complete/action:literal-word/complete
}
function ble/complete/action:word/get-desc {
[[ $DATA ]] && desc=$DATA
}

# action:literal-substr
# action:literal-word
# action:substr
function ble/complete/action:literal-substr/initialize { :; }
function ble/complete/action:literal-substr/complete { :; }
function ble/complete/action:literal-word/initialize { :; }
function ble/complete/action:literal-word/complete { ble/complete/action:word/complete; }
function ble/complete/action:substr/initialize { ble/complete/action:word/initialize; }
function ble/complete/action:substr/complete { :; }

# action:file
# action:file_rhs (source:argument 内部使用)
function ble/complete/action:file/initialize {
Expand Down Expand Up @@ -1690,6 +1695,9 @@ function ble/complete/cand/unpack {
## @var[in,out] cand_count cand_cand cand_word cand_pack
## @var[in,out] cand_limit_reached

# source:none
function ble/complete/source:none { return 0; }

# source:wordlist
#
# -r 指定された単語をエスケープせずにそのまま挿入する
Expand Down
53 changes: 40 additions & 13 deletions lib/core-syntax.sh
Expand Up @@ -5412,6 +5412,11 @@ function ble/syntax/completion-context/.check-prefix/ctx:next-identifier {
local source=$1 word=${text:istat:index-istat}
if [[ $word =~ $rex_param ]]; then
ble/syntax/completion-context/.add "$source" "$istat"
elif [[ $word =~ ^$_ble_syntax_bash_RexSpaces$ ]]; then
# 単語が未だ開始していない時は現在位置から補完開始
ble/syntax/completion-context/.add "$source" "$index"
else
ble/syntax/completion-context/.add none "$istat"
fi
}
_ble_syntax_bash_complete_check_prefix[CTX_ARGX0]="next-word sabbrev"
Expand All @@ -5425,7 +5430,9 @@ _ble_syntax_bash_complete_check_prefix[CTX_FARGX2]="next-word wordlist:-rs:'in:d
_ble_syntax_bash_complete_check_prefix[CTX_FARGI2]="next-word wordlist:-rs:'in:do'"
function ble/syntax/completion-context/.check-prefix/ctx:next-word {
local source=$1 word=${text:istat:index-istat} rex=$'^[^ \t]*$'
if [[ $word =~ $rex ]]; then
if [[ $word =~ ^$_ble_syntax_bash_RexSpaces$ ]]; then
ble/syntax/completion-context/.add "$source" "$index"
else
ble/syntax/completion-context/.add "$source" "$istat"
fi
}
Expand Down Expand Up @@ -5679,20 +5686,18 @@ function ble/syntax/completion-context/.check-here {
local -a stat
ble/string#split-words stat "${_ble_syntax_stat[index]}"
if [[ ${stat[0]} ]]; then
# ここで CTX_CMDI や CTX_ARGI は処理しない。
# 既に check-prefix で引っかかっている筈だから。
local ctx=${stat[0]}

# #D1690: 引数類の補完はその場で開始はしない事にする。以下は削除した。
# CTX_ARGX0, CTX_CPATX0, CTX_ARGX, CTX_FARGX{1..3}, CTX_SARGX1,
# CTX_CARGX{1,2}, CTX_TARGX{1,2}, CTX_COARGX
# Note: ここで CTX_CMDI や CTX_ARGI は処理しない。既に check-prefix で引っ
# かかっている筈だから。
#
# 引数の類は開始点の前に必ず空白類が存在する筈なので、ここで補完が開始され
# た場合前の単語とくっついて予期せぬ結果になる。もし本当に一つの単語の中で
# 新しく補完候補を生成する必要があるのであれば、それはその単語に対する補完
# の一環として行われるべきであって、"新しい単語" としての補完である必要はな
# い。
# Note (#D1690): 文句が出たので 当初引数類の補完はその場で開始しない事にし
# たが、すると空文字列から補完を開始できなくなってしまった。やはり、ここ
# で引数の補完を開始しなければならない。
#
# そもそも .check-prefix で補完文脈を生成できる時は、入力済みの内容に拘ら
# ず補完文脈を生成するべきである。それにより、.check-here に到達するのは
# 補完文脈が他に生成しようがない状況に限定される。この時、実は
# .check-here の側は修正は必要なかった。
local ctx=${stat[0]}
if ((ctx==CTX_CMDX||ctx==CTX_CMDXV||ctx==CTX_CMDX1||ctx==CTX_CMDXT)); then
if ! shopt -q no_empty_cmd_completion; then
ble/syntax/completion-context/.add command "$index"
Expand All @@ -5706,6 +5711,28 @@ function ble/syntax/completion-context/.check-here {
ble/syntax/completion-context/.add wordlist:-rs:';:{:do' "$index"
elif ((ctx==CTX_CMDXD)); then
ble/syntax/completion-context/.add wordlist:-rs:'{:do' "$index"
elif ((ctx==CTX_ARGX0||ctx==CTX_CPATX0)); then
ble/syntax/completion-context/.add sabbrev "$index"
elif ((ctx==CTX_ARGX||ctx==CTX_CARGX1||ctx==CTX_FARGX3)); then
ble/syntax/completion-context/.add argument "$index"
elif ((ctx==CTX_FARGX1||ctx==CTX_SARGX1)); then
ble/syntax/completion-context/.add variable:w "$index"
ble/syntax/completion-context/.add sabbrev "$index"
elif ((ctx==CTX_CARGX2)); then
ble/syntax/completion-context/.add wordlist:-rs:'in' "$index"
elif ((ctx==CTX_FARGX2)); then
ble/syntax/completion-context/.add wordlist:-rs:'in:do' "$index"
elif ((ctx==CTX_TARGX1)); then
local words='-p'
((_ble_bash>=50100)) && words='-p':'--'
ble/syntax/completion-context/.add command "$index"
ble/syntax/completion-context/.add wordlist:--:"$words" "$index"
elif ((ctx==CTX_TARGX2)); then
ble/syntax/completion-context/.add command "$index"
ble/syntax/completion-context/.add wordlist:--:'--' "$index"
elif ((ctx==CTX_COARGX)); then
ble/syntax/completion-context/.add variable:w "$index"
ble/syntax/completion-context/.add command "$index"
elif ((ctx==CTX_CPATI||ctx==CTX_RDRF||ctx==CTX_RDRS)); then
ble/syntax/completion-context/.add file "$index"
elif ((ctx==CTX_RDRD)); then
Expand Down
29 changes: 29 additions & 0 deletions note.txt
Expand Up @@ -5899,6 +5899,35 @@ bash_tips
である。従って、check-here による ARGX 系統の補完文脈は寧ろ削除するべきであ
る。

x fixed: 2021-12-11 complete: 何故か空の引数から補完を開始する事ができない

| と思ったが、これはもしかするとつい先日修正した物が原因なのかもしれない。
| →うーん。そうだった。これは困る。どう判定するのが良いのだろうか。もう面
| 倒なので空白で判定する。依然として "for \ " の直後で問題になりそうだが仕
| 方がない。
|
| うーん。然し類似のケースとして "echo hello[TAB]" の時には何故問題にならな
| かったのか? 或いは一つでも補完文脈が生成されていれば、check-here は有効化
| されないという事? → と思ったらそうだった。.check-here 関数の一番初めで、
| 既に source が存在していた時には何もせずに戻る様になっている。
|
| つまり、今回の問題点は何だったかというと…FARGI1 及び FARGX1 に対して正し
| く補完を生成しなかった事? うーん。然し実装を見る限りはちゃんと生成しそう
| な物である。

"echo hello[TAB]" で問題にならないのは何れにしても check-prefix で引っか
かって補完文脈が生成されるので、check-here が抑制されるからである。然し、
"for -[TAB]" の時には - から始まる補完文脈を生成できないので、check-here
が始まってしまう。本来、"-" が文法的に正しくないとしたら、その位置からの
補完は存在しないという事で、何も生成しない補完文脈を此処に設置するべきな
のである → 新しく source:none を作成してそれを使う事にした。

x fixed: { echo; } 'f[TAB] を実行すると fi' の様に補完されてしまう。"fi と
すると fi" になるし、$"fi とすると fi" になる。つまり、遡って書き換えが起
こっているのにも拘らず、終端の quote が付加されてしまっている。

これは action:literal-word のバグだった。修正した。

* mandb: 空文字列の時にも mandb に基づくオプション生成を実行するべき [#D1689]

* 2021-08-30 complete: オプションの説明と progcomp の integration を考える (motivated by Shahabaz-Bagwan, bbyfacekiller and EmilySeville7cfg) [#D1688]
Expand Down

0 comments on commit e09fcab

Please sign in to comment.