Skip to content

Commit

Permalink
Add delayed compdef handling
Browse files Browse the repository at this point in the history
鈥o the order of `compdef` and `$fpath` statements doesn't matter.
  • Loading branch information
marlonrichert committed Mar 22, 2021
1 parent 2497113 commit dd08b2c
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions module/.autocomplete.compinit
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
zmodload -Fa zsh/files b:zf_rm
zmodload -F zsh/parameter p:funcstack p:functions

[[ -v _comp_setup ]] ||
compdef() {
unfunction compdef
.autocomplete.compinit.precmd
unfunction .autocomplete.compinit.precmd
compdef "$@"
}

_bash_complete compgen complete () {
unfunction _bash_complete compgen complete
builtin autoload -Uz bashcompinit
bashcompinit
bashcompinit() { : }
${(%):-%N} "$@"
typeset -gHa _autocomplete_compdef=()
compdef() {
_autocomplete_compdef+=( "${(j: :)${(@q+)@}}" )
}

[[ -v functions[_bash_complete] ]] ||
_bash_complete compgen complete () {
unfunction _bash_complete compgen complete
builtin autoload -Uz bashcompinit
bashcompinit
bashcompinit() { : }
${(%):-%N} "$@"
}

.autocomplete.compinit.precmd() {
[[ -z $CDPATH ]] &&
unset cdpath CDPATH
Expand Down Expand Up @@ -50,6 +48,11 @@ EOF

compinit() { : }

local args; for args in "$_autocomplete_compdef[@]"; do
eval "compdef $args"
done
unset _autocomplete_compdef

local -i fd
exec {fd}< <(
local cache_dir
Expand Down Expand Up @@ -79,7 +82,7 @@ EOF
local -i ret=1 _autocomplete__reserved_lines=0

compstate[insert]=menu # To get the best output from `_expand` (and some other functions).
compstate[last_prompt]=yes # Completion doesn't stay on same prompt without this.
compstate[last_prompt]=yes # Completion doesn't stay on the same command line without this.
compstate[list]='list force packed rows' # `_setup` doesn't work well for this.

local +h -a comppostfuncs=( _autocomplete._main_complete.post "$comppostfuncs[@]" )
Expand All @@ -100,6 +103,14 @@ EOF
return ret
}

.autocomplete.compadd() {
if [[ $_completer == expand* ]]; then
builtin compadd -fW "${${${words[CURRENT]:#[~/]*}:+$PWD/}:-/}" "$@"
else
builtin compadd "$@"
fi
}

_autocomplete._main_complete.post() {
compstate[list_max]=0
MENUSCROLL=0
Expand Down Expand Up @@ -215,14 +226,4 @@ EOF
.autocomplete._wanted "$@"
fi
}

.autocomplete.compadd() {
setopt localoptions listtypes

if [[ $_completer == expand* ]]; then
builtin compadd -f -W "${${${words[CURRENT]:#[~/]*}:+$PWD/}:-/}" "$@"
else
builtin compadd "$@"
fi
}
}

0 comments on commit dd08b2c

Please sign in to comment.