summaryrefslogtreecommitdiff
path: root/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post
diff options
context:
space:
mode:
Diffstat (limited to 'dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post')
-rw-r--r--dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post68
1 files changed, 68 insertions, 0 deletions
diff --git a/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post b/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post
new file mode 100644
index 00000000..71fa9fc9
--- /dev/null
+++ b/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.complete-word.post
@@ -0,0 +1,68 @@
+#autoload
+local -a match=() mbegin=() mend=() # `zstyle` for some reason assigns these.
+
+unset MENUSELECT 'compstate[list]'
+compstate[insert]=
+
+local -P key_name=
+case $KEYS in
+ ( $'\t' ) key_name=tab ;;
+ ( $terminfo[kcbt] ) key_name=shift-tab ;;
+esac
+local widget_style=
+builtin zstyle -s :autocomplete:${key_name}: widget-style widget_style ||
+ widget_style=menu-select
+
+if [[ -n $_autocomplete__unambiguous ]] &&
+ builtin zstyle -t ":autocomplete:${key_name}:" insert-unambiguous; then
+ [[ $widget_style == (|*-)menu-* ]] &&
+ compstate[insert]='automenu-'
+ compstate[insert]+=unambiguous
+ unset _autocomplete__unambiguous
+ return
+fi
+
+local -Pi nmatches=0
+if [[ $compstate[old_list] == keep ]]; then
+ nmatches=$_lastcomp[nmatches]
+else
+ nmatches=$compstate[nmatches]
+fi
+
+if (( nmatches > 1 )); then
+ if [[ $widget_style == (|*-)menu-select ]]; then
+ typeset -gHi MENUSELECT=0
+ compstate[insert]='menu:'
+
+ # Determine which terminal line we're on (for async completion).
+ typeset -gHi _autocomplete__buffer_start_line=$((
+ max( min( _autocomplete__buffer_start_line, LINES - compstate[list_lines] ), BUFFERLINES )
+ ))
+
+ elif [[ $compstate[old_list] != keep && $_lastcomp[insert] != (|*-)unambiguous ]]; then
+ compstate[list]='list force'
+ return
+ elif [[ $widget_style == (|*-)menu-complete ]]; then
+ compstate[insert]='menu:'
+ fi
+fi
+
+if [[ $key_name == shift-tab ]]; then
+ compstate[insert]+='0'
+else
+ compstate[insert]+='1'
+fi
+
+if [[ $RBUFFER != [[:space:]]* ]]; then
+ local -a spacetags=()
+ builtin zstyle -a :autocomplete: add-space spacetags ||
+ spacetags=( executables aliases functions builtins reserved-words commands )
+ local -Pa comptags=()
+ if [[ $compstate[old_list] == keep ]]; then
+ comptags=( $=_lastcomp[tags] )
+ else
+ comptags=( $=_comp_tags )
+ fi
+ [[ -n ${comptags:*spacetags} ]] &&
+ compstate[insert]+=' '
+fi