#!/bin/zsh
setopt localoptions banghist
zmodload -F zsh/terminfo p:terminfo

local context=${curcontext:-${WIDGET}:::}
unset curcontext
local +h curcontext=$context

local +h -a comppostfuncs=( .autocomplete__complete-word__post "$comppostfuncs[@]" )

local -a compargs=()

case $curcontext in
( history-incremental-search* )
  compargs=( - history-lines _autocomplete__history_lines )
;;
( recent-paths:* )
  compargs=( - recent-paths _autocomplete__recent_paths )
;;
( * )
  if  [[ $WIDGET == spell-word ]] ||
      [[ -v _autocomplete__partial_list && $WIDGETSTYLE == (|*-)(list|menu)(|-*) ]] ||
      { [[ $_lastcomp[unambiguous] != (|$PREFIX$SUFFIX) ]] &&
        _autocomplete__should_insert_unambiguous }; then
    compstate[old_list]=
  fi
;;
esac

if [[ -n $compstate[old_list] ]]; then
  compstate[old_list]=keep
  compargs=( - )
fi
autocomplete:_main_complete:new "$compargs[@]"

(( _lastcomp[nmatches] > 0 ))
