Skip to content

Commit

Permalink
menu-complete: add "insert_unique" option to the "complete" widget
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 4, 2023
1 parent bce2033 commit 36efbb7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -129,6 +129,7 @@
- syntax: recognize history expansion in here documents, `"...!"` (bash <= 4.2), and `$!` (bash <= 4.1) `#D1959` e619e73
- syntax: support context after `((...))` and `[[ ... ]]` in bash-5.2 `#D1962` 67cb967
- edit: support the readline variable `search-ignore-case` of bash-5.3 `#D1976` e3ad110
- menu-complete: add `insert_unique` option to the `complete` widget `#D1995` xxxxxxx

## Changes

Expand Down
22 changes: 18 additions & 4 deletions lib/core-complete.sh
Expand Up @@ -7169,6 +7169,8 @@ _ble_complete_state=
## 候補を全て挿入します。
## insert_braces
## 候補をブレース展開にまとめて挿入します。
## insert_unique
## 候補が一意のときメニュー補完に入らずに挿入します。
## show_menu
## メニューを表示します。
## enter_menu
Expand Down Expand Up @@ -7205,7 +7207,7 @@ function ble/widget/complete {
if [[ $_ble_complete_menu_active && :$opts: != *:context=*:* ]]; then
local footprint; ble/complete/menu/get-footprint
[[ $footprint == "$_ble_complete_menu_footprint" ]] &&
ble/complete/menu-complete/enter && return 0
ble/complete/menu-complete/enter "$opts" && return 0
fi
[[ $WIDGET == "$LASTWIDGET" && $state != complete ]] && opts=$opts:enter_menu
fi
Expand Down Expand Up @@ -7253,7 +7255,7 @@ function ble/widget/complete {
fi
fi

if [[ :$opts: == *:insert_common:* ]]; then
if [[ :$opts: == *:insert_common:* || :$opts: == *:insert_unique:* && cand_count -eq 1 ]]; then
ble/complete/insert-common; return "$?"

elif [[ :$opts: == *:insert_braces:* ]]; then
Expand Down Expand Up @@ -7292,7 +7294,7 @@ function ble/widget/complete-insert {

function ble/widget/menu-complete {
local opts=$1
ble/widget/complete enter_menu:$opts
ble/widget/complete enter_menu:insert_unique:$opts
}

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -7515,6 +7517,10 @@ function ble/complete/menu-complete/select {
ble/complete/menu#select "$@"
}

## @fn ble/complete/menu-complete/enter [opts]
## @var[in,opt] opts
## backward
## insert_unique
function ble/complete/menu-complete/enter {
((${#_ble_complete_menu_icons[@]}>=1)) || return 1
local beg end; ble/complete/menu/get-active-range || return 1
Expand All @@ -7529,6 +7535,14 @@ function ble/complete/menu-complete/enter {
((_ble_edit_mark+=comps_fixed_length))
fi

# 一意確定時。menu の処理も含めて menu-complete の枠組みの中で確定を実行する。
if [[ :$opts: == *:insert_unique:* ]] && ((${#_ble_complete_menu_items[@]}==1)); then
ble/complete/menu#select 0
ble/decode/keymap/push menu_complete
ble/widget/menu_complete/exit complete
return 0
fi

_ble_complete_menu_original=${_ble_edit_str:beg:end-beg}
ble/complete/menu/redraw

Expand Down Expand Up @@ -8411,7 +8425,7 @@ function ble/complete/sabbrev/expand {
local menu_common_part=
ble/complete/menu/show || return "$?"
[[ :$bleopt_sabbrev_menu_opts: == *:enter_menu:* ]] &&
ble/complete/menu-complete/enter
ble/complete/menu-complete/enter "$bleopt_sabbrev_menu_opts"
return 147 ;;
(*) return 1 ;;
esac
Expand Down
17 changes: 17 additions & 0 deletions note.txt
Expand Up @@ -6680,6 +6680,23 @@ bash_tips

2023-03-03

* menu-complete: enter_menu であっても一意確定なら補完完了する機能 [#D1995]
https://github.com/akinomyoga/ble.sh/discussions/297#discussioncomment-5159146

実装した。menu を既に表示してしまっている時に単に menu に入る処理をしている
所では、既存のメニューを選択してから即座に menu の確定処理を行う。menu を未
だ表示していない時には menu の処理は一切せずにその場で挿入を実行する。menu
を既に表示していて二回連続 TAB を押した時についてはまた別の処理が必要になる。

うーん。単純に opts を継承する事にした。調べてみると menu/enter が処理して
いる opts は backward と今回追加した insert_unique だけなので別の物が指定さ
れていたとしても突然問題になる様には思われない。なので、単に opts を
menu/enter に渡してしまう事にする。この様にすれば個別に insert_unique を実
装しなくて済む。

うーん。widget/menu-complete は enter_menu:insert_unique を既定にしてしまっ
て良いのではないか → 変更した。

* vi: operator:filter で end が文字列の最後の時には追加の改行は入れない [#D1994]

x fixed: うーん。v 等で中途半端な場所にある時に beg は行頭に移動するけれど
Expand Down

0 comments on commit 36efbb7

Please sign in to comment.