Skip to content

Commit

Permalink
menu-complete: support selection by index
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 16, 2023
1 parent a6b2c07 commit b91b8bc
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 80 deletions.
18 changes: 13 additions & 5 deletions blerc.template
Expand Up @@ -688,11 +688,19 @@
#bleopt complete_menu_maxlines=10


## The following setting specifies the prefix for complete_menu_style=linewise.
## For example, the candidate number can be shown by setting the value "%d".
## ANSI escape sequences can be used.

#bleopt menu_linewise_prefix=
## The following settings specify the prefix of the menu items. "menu_prefix"
## specifies the default prefix for any menu-style.
## "menu_{align,desc,linewise,dense}_prefix" specify the prefixes in the
## respective menu-styles. The value is specified by a printf format, where
## the first argument is the index of the candidate. ANSI escape sequences can
## also be used. For example, the candidate index can be shown by setting the
## value '%d '. The default value is empty.

#bleopt menu_align=
#bleopt menu_align_prefix='\e[1m%d:\e[m '
#bleopt menu_desc_prefix='\e[1m%d.\e[m '
#bleopt menu_linewise_prefix='\e[1;36m%d:\e[m '
#bleopt menu_dense_prefix='\e[1;32m>\e[m '


## The following setting specifies the minimum column width for the multicolumn
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -140,6 +140,7 @@
- sabbrev: support inline and linewise sabbre with `ble-sabbrev -il` `#D2012` 56208534
- complete: add `bleopt complete_source_sabbrev_{opts,ignore}` (motivated by mozirilla213) `#D2013` f95eb0cc `#D2016` 45c76746
- util.bgproc: separate `ble/util/bgproc` from `histdb` (motivated by bkerin) `#D2017` 7803305f
- menu-complete: support selection by index (requested by bkerin) `#D2023` xxxxxxxx

## Changes

Expand Down
59 changes: 36 additions & 23 deletions keymap/vi.sh
Expand Up @@ -7891,29 +7891,28 @@ function ble-decode/keymap:vi_imap/define {

ble-bind -f 'SP' 'magic-space'
ble-bind -f '/' 'magic-slash'
# ble-bind -f 'M-^' 'history-expand-line'

# ble-bind -f 'C-c' 'discard-line'
ble-bind -f 'C-j' 'accept-line'
ble-bind -f 'C-RET' 'accept-line'
ble-bind -f 'C-m' 'accept-single-line-or-newline'
ble-bind -f 'RET' 'accept-single-line-or-newline'
# ble-bind -f 'C-o' 'accept-and-next'
# ble-bind -f 'M-#' 'insert-comment'
ble-bind -f 'C-x C-e' 'edit-and-execute-command'
# ble-bind -f 'M-C-e' 'shell-expand-line'
# ble-bind -f 'M-&' 'tilde-expand'
ble-bind -f 'C-g' 'bell'
ble-bind -f 'C-x C-g' 'bell'
# ble-bind -f 'C-M-g' 'bell'

ble-bind -f 'C-l' 'clear-screen'
# ble-bind -f 'C-M-l' 'redraw-line'

ble-bind -f 'f1' 'command-help'
ble-bind -f 'C-x C-v' 'display-shell-version'
ble-bind -c 'C-z' 'fg'
# ble-bind -c 'M-z' 'fg'

# ble-bind -f 'C-c' 'discard-line'
ble-bind -f 'C-j' 'accept-line'
ble-bind -f 'C-RET' 'accept-line'
ble-bind -f 'C-m' 'accept-single-line-or-newline'
ble-bind -f 'RET' 'accept-single-line-or-newline'
# ble-bind -f 'C-o' 'accept-and-next'
ble-bind -f 'C-x C-e' 'edit-and-execute-command'
ble-bind -f 'C-g' 'bell'
ble-bind -f 'C-x C-g' 'bell'

ble-bind -f 'C-l' 'clear-screen'

ble-bind -f 'f1' 'command-help'
ble-bind -f 'C-x C-v' 'display-shell-version'
ble-bind -c 'C-z' 'fg'

# args
local key
for key in {,C-}{0..9}; do
ble-bind -f "$key" 'append-arg'
done

#----------------------------------------------------------------------------
# vi_imap modifications
Expand Down Expand Up @@ -8043,6 +8042,20 @@ function ble-decode/keymap:vi_imap/define-meta-bindings {
ble-bind -f 'M-g' 'complete context=glob'
ble-bind -f 'M-C-i' 'complete context=dynamic-history'
ble-bind -f 'M-TAB' 'complete context=dynamic-history'

#----------------------------------------------------------------------------
# from ble-decode/keymap:safe/bind-arg

ble-bind -f 'M-0' 'append-arg'
ble-bind -f 'M-1' 'append-arg'
ble-bind -f 'M-2' 'append-arg'
ble-bind -f 'M-3' 'append-arg'
ble-bind -f 'M-4' 'append-arg'
ble-bind -f 'M-5' 'append-arg'
ble-bind -f 'M-6' 'append-arg'
ble-bind -f 'M-7' 'append-arg'
ble-bind -f 'M-8' 'append-arg'
ble-bind -f 'M-9' 'append-arg'
}

#------------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions lib/core-complete-def.sh
Expand Up @@ -82,8 +82,6 @@ ble/util/autoload "$_ble_base/lib/core-complete.sh" \
ble/complete/menu-style:linewise/construct-page \
ble/complete/menu-style:desc{,-raw}/construct-page

bleopt/declare -v menu_linewise_prefix ''
bleopt/declare -v menu_desc_multicolumn_width 65
bleopt/declare -v complete_menu_complete 1
bleopt/declare -v complete_menu_complete_opts 'insert-selection'
bleopt/declare -v complete_menu_filter 1
Expand All @@ -101,9 +99,15 @@ function ble/complete/.init-bind-readline-variables {
}
ble/complete/.init-bind-readline-variables

bleopt/declare -v menu_prefix ''
bleopt/declare -v menu_align_prefix ''
bleopt/declare -n menu_align_min 4
bleopt/declare -n menu_align_max 20
bleopt/declare -o complete_menu_align menu_align_max
bleopt/declare -v menu_dense_prefix ''
bleopt/declare -v menu_linewise_prefix ''
bleopt/declare -v menu_desc_prefix ''
bleopt/declare -v menu_desc_multicolumn_width 65

ble/util/autoload "$_ble_base/lib/core-complete.sh" \
ble/complete/menu#start \
Expand Down

0 comments on commit b91b8bc

Please sign in to comment.