@@ -5980,6 +5980,18 @@ function ble/complete/source:option/.is-option-context {
59805980 return 0
59815981}
59825982
5983+ # # @fn ble/complete/source:option [opts]
5984+ # # @param[in,opt] opts
5985+ # # @opt empty
5986+ # # Generate option names even when the current word is empty. By
5987+ # # default, the generation of the options is enabled only when the
5988+ # # current word starts with - or +.
5989+ # # @opt reuse-comp_words
5990+ # # When this option is specified, use the externally-specified variables
5991+ # # "comp_words", "comp_line", "comp_point", and "comp_cword" instead of
5992+ # # extracting them by the syntax analysis on the current point. This is
5993+ # # used when the target command is intentionally different from the shell
5994+ # # syntax, such as the case of "sudo command ...".
59835995function ble/complete/source:option {
59845996 local opts=$1
59855997 if [[ :$opts : == * :empty:* ]]; then
@@ -5995,8 +6007,10 @@ function ble/complete/source:option {
59956007 ble/complete/source/reduce-compv-for-ambiguous-match
59966008 [[ :$comp_type : == * :[maA]:* ]] && local COMP2=$COMP1
59976009
5998- local comp_words comp_line comp_point comp_cword
5999- ble/syntax:bash/extract-command " $COMP2 " || return 1
6010+ if [[ :$opts : != * :reuse-comp_words:* ]]; then
6011+ local comp_words comp_line comp_point comp_cword
6012+ ble/syntax:bash/extract-command " $COMP2 " || return 1
6013+ fi
60006014
60016015 ble/complete/source:option/generate-for-command " ${comp_words[@]:: comp_cword} "
60026016}
@@ -6181,6 +6195,19 @@ function ble/complete/source:argument/generate {
61816195 ble/complete/source:argument/.generate-user-defined-completion; local ext=$?
61826196 (( ext== 148 || cand_count> old_cand_count)) && return " $ext "
61836197
6198+ ble/complete/source:argument/fallback
6199+ }
6200+
6201+ # # @fn ble/complete/source:argument/fallback
6202+ # # @param[in] opts
6203+ # # @opt reuse-comp_words
6204+ # # @var[in] comp_opts
6205+ # # @opt ble/default
6206+ # # @opt dirnames
6207+ # # @opt default
6208+ function ble/complete/source:argument/fallback {
6209+ local opts=$1 old_cand_count=$cand_count
6210+
61846211 # When no completions are generated, we attempt "ble/default" argument
61856212 # completions in the following. If "ble/default" completions are disabled,
61866213 # we emulate Bash's behavior based on "-o default" and "-o dirnames".
@@ -6207,7 +6234,10 @@ function ble/complete/source:argument/generate {
62076234 # 2. Attempt built-in argument completion
62086235
62096236 # "-option" の時は complete options based on mandb
6210- ble/complete/source:option; local ext=$?
6237+ local option_opts=
6238+ [[ :$opts : == * :reuse-comp_words:* ]] &&
6239+ option_opts=$option_opts :reuse-comp_words
6240+ ble/complete/source:option " $option_opts " ; local ext=$?
62116241 (( ext== 148 )) && return " $ext "
62126242
62136243 # When "-o dirnames" is specified, the directory names are first attempted,
@@ -6225,7 +6255,7 @@ function ble/complete/source:argument/generate {
62256255 fi
62266256
62276257 # 空文字列に対するオプション生成はファイル名よりも後で試みる
6228- ble/complete/source:option empty; local ext=$?
6258+ ble/complete/source:option " $option_opts : empty" ; local ext=$?
62296259 (( ext== 148 || cand_count> old_cand_count)) && return " $ext "
62306260
62316261 # ----------------------------------------------------------------------------
0 commit comments