Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deferred compdef between sourcing antigen and antigen apply #737

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions bin/antigen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
zmodload zsh/parameter
autoload -U is-at-least

# Used to defer compinit/compdef
typeset -a __deferred_compdefs
compdef () { __deferred_compdefs=($__deferred_compdefs "${${(@q-)@}}") }

# While boot.zsh is part of the ext/cache functionallity it may be disabled
# with ANTIGEN_CACHE flag, and it's always compiled with antigen.zsh
if [[ $ANTIGEN_CACHE != false ]]; then
Expand Down Expand Up @@ -59,10 +63,6 @@ if (( ! $+commands[git] )); then
return 1
fi

# Used to defer compinit/compdef
typeset -a __deferred_compdefs
compdef () { __deferred_compdefs=($__deferred_compdefs "$*") }

# A syntax sugar to avoid the `-` when calling antigen commands. With this
# function, you can write `antigen-bundle` as `antigen bundle` and so on.
antigen () {
Expand Down Expand Up @@ -796,15 +796,15 @@ antigen-apply () {
autoload -Uz compinit
compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP"

# Apply all `compinit`s that have been deferred.
# Apply all `compdef`s that have been deferred.
local cdef
for cdef in "${__deferred_compdefs[@]}"; do
compdef "$cdef"
compdef ${(Q)${(z)cdef}}
done

{ zcompile "$ANTIGEN_COMPDUMP" } &!

unset __deferred_compdefs
__deferred_compdefs=()
}
# Syntaxes
# antigen-bundle <url> [<loc>=/]
Expand Down Expand Up @@ -1836,11 +1836,21 @@ antigen () {
typeset -gaU fpath path
fpath+=(${_fpath[@]}) path+=(${_PATH[@]})
_antigen_compinit () {
autoload -Uz compinit; compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP"; compdef _antigen antigen
autoload -Uz compinit
compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP"
compdef _antigen antigen

# Apply all \`compdef\`s that have been deferred.
local cdef
for cdef in "\${__deferred_compdefs[@]}"; do
compdef \${(Q)\${(z)cdef}}
done

__deferred_compdefs=()

add-zsh-hook -D precmd _antigen_compinit
}
autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit
compdef () {}

if [[ -n "$ZSH" ]]; then
ZSH="$ZSH"; ZSH_CACHE_DIR="$ZSH_CACHE_DIR"
Expand Down