#autoload
zmodload -Fa zsh/parameter p:functions

# Don't run more than once.
(( _matcher_num > 1 )) &&
    return 1

local -aU files
local -a expl expl_dirs expl_files displ
local -Pi ret i
local -P singular plural tag

.autocomplete:async:list-choices:max-lines

chpwd_recent_filehandler
files=( "$reply[@]" )

# -V: don't sort
_description -V recent-directories expl_dirs  'recent directory'
_description -V recent-files       expl_files 'recent file'
_comp_tags+=' recent-directories recent-files'

ret=1
for (( i = 1 ; i <= $#files && compstate[list_lines] < _autocomplete__max_lines ; i++ )); do
  displ=( "$files[i]" )

  if [[ -d $files[i] ]]; then
    expl=( "$expl_dirs[@]" )
  else
    expl=( "$expl_files[@]" )
  fi

  compadd "$expl[@]" -ld displ -P "${${displ[1]:h}%/}/" -fW "${${files[i]:h}%/}/" \
      -- "$files[i]:t" &&
    ret=0
done

return ret
