Skip to content

Commit

Permalink
Add smoke testing & autoloading by absolute path
Browse files Browse the repository at this point in the history
Let's see if this can detect/prevent errors like in issue #215.
  • Loading branch information
marlonrichert committed Mar 23, 2021
1 parent dd08b2c commit 68bae95
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
9 changes: 2 additions & 7 deletions module/.autocomplete.__init__
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
zmodload -Fa zsh/files b:zf_mkdir b:zf_rm
zmodload -Fa zsh/parameter p:functions
zmodload -F zsh/zutil b:zstyle
builtin autoload -Uz add-zsh-hook .autocomplete.mathfunc .autocomplete.screen-space
builtin autoload -Uz add-zsh-hook
.autocomplete.mathfunc

.autocomplete.__init__.precmd() {
Expand Down Expand Up @@ -34,17 +34,12 @@ builtin autoload -Uz add-zsh-hook .autocomplete.mathfunc .autocomplete.screen-sp
local -a older_than_1_day=( $datadir/*(N-.m+1) )
[[ -n $older_than_1_day ]] &&
zf_rm -f $older_than_1_day[@]

exec {_autocomplete__log_fd}>$(mktemp $datadir/XXXXXXXXXXXX)

export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
[[ -d $XDG_CACHE_HOME/zsh ]] ||
zf_mkdir -pm 0700 $XDG_CACHE_HOME/zsh

export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
[[ -d $XDG_DATA_HOME/zsh ]] ||
zf_mkdir -pm 0700 $XDG_DATA_HOME/zsh

add-zsh-hook precmd .autocomplete.screen-space
local -i pslines=${#${(%%)PS1}//[^$'\n']}
typeset -gHi _autocomplete__screen_space=$(( LINES - pslines - 2 ))
Expand All @@ -61,9 +56,9 @@ builtin autoload -Uz add-zsh-hook .autocomplete.mathfunc .autocomplete.screen-sp
local mod; for mod in compinit config widget key key-binding recent-dirs async; do
if ! zstyle -t ':autocomplete:' $mod false no off 0; then
mod=.autocomplete.$mod
builtin autoload -Uz $mod
$mod
unfunction $mod
builtin autoload -Uz $mod
fi
done

Expand Down
2 changes: 1 addition & 1 deletion module/.autocomplete.async
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ zmodload -F zsh/parameter p:funcstack p:functions p:parameters
zmodload -F zsh/system p:sysparams
zmodload -F zsh/zselect b:zselect
zmodload -F zsh/zutil b:zparseopts
builtin autoload -Uz add-zle-hook-widget .autocomplete.zle-flags
builtin autoload -Uz add-zle-hook-widget

typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=yes

Expand Down
9 changes: 6 additions & 3 deletions module/.autocomplete.compinit
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ compdef() {

typeset -gH _comp_dumpfile=${_comp_dumpfile:-${ZSH_COMPDUMP:-$XDG_CACHE_HOME/zsh/compdump}}

local f; for f in ${${(%):-%x}:h:h}/completion/*; do
local -a comps=( $^fpath/_autocomplete.*~*.zwc(N-.) )
if ! (( $#comps )); then
print -u2 -- 'zsh-autocomplete: Failed to find completion functions. Aborting.'
return 66
fi
local f; for f in $comps[@]; do
if [[ $f -nt $_comp_dumpfile ]]; then
zf_rm -f $_comp_dumpfile
break
Expand Down Expand Up @@ -75,8 +80,6 @@ EOF

compinit() { : }

builtin autoload -Uz .autocomplete.patch

.autocomplete.patch _main_complete
_main_complete() {
local -i ret=1 _autocomplete__reserved_lines=0
Expand Down
4 changes: 1 addition & 3 deletions module/.autocomplete.key-binding
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ zmodload -Fa zsh/parameter p:funcstack p:functions

.autocomplete.key-binding.precmd() {
# Work around plugin managers making `key` local.
if [[ -z $key[Tab] || -z $key[Backtab] ]]; then
autoload -Uz .autocomplete.key
[[ -z $key[Tab] || -z $key[Backtab] ]] &&
.autocomplete.key
fi

local tab_style; zstyle -s :autocomplete:tab: widget-style tab_style ||
tab_style='complete-word'
Expand Down
8 changes: 2 additions & 6 deletions module/.autocomplete.widget
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ typeset -g ZSH_AUTOSUGGEST_MANUAL_REBIND=1
zmodload zsh/complist

.autocomplete.widget.c() {
local func=.autocomplete.$3.completion-widget
builtin autoload -Uz $func
zle -C $1 $2 $func
zle -C $1 $2 .autocomplete.$3.completion-widget
}

.autocomplete.widget.z() {
local func=.autocomplete.$2.zle-widget
builtin autoload -Uz $func
zle -N $1 $func
zle -N $1 .autocomplete.$2.zle-widget
}

.autocomplete.widget.non-tab() {
Expand Down
2 changes: 0 additions & 2 deletions utility/.autocomplete.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
zmodload -F zsh/parameter p:functions

.autocomplete.patch() {
emulate -L zsh; setopt $_autocomplete__options

builtin autoload +X -Uz $1
functions[.autocomplete.$1]=$functions[$1]
}
Expand Down
23 changes: 20 additions & 3 deletions zsh-autocomplete.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ setopt NO_singlelinezle
)
setopt $_autocomplete__options

hash -d zsh-autocomplete=${${(%):-%x}:h}
typeset -gU FPATH fpath=( ~zsh-autocomplete/*(-/) $fpath )
local basedir=${${(%):-%x}:h}
if ! [[ -n $basedir && -d $basedir ]]; then
print -u2 -- 'zsh-autocomplete: Failed to find base dir. Aborting.'
return 66
fi
hash -d zsh-autocomplete=$basedir

local -a subdirs=( ~zsh-autocomplete/*(N-/) )
if ! (( $#subdirs )); then
print -u2 -- 'zsh-autocomplete: Failed to find sub dirs. Aborting.'
return 66
fi
typeset -gU FPATH fpath=( $subdirs[@] $fpath[@] )

local -a funcs=( $^subdirs/.autocomplete.*~*.zwc(N-.) )
if ! (( $#funcs )); then
print -u2 -- 'zsh-autocomplete: Failed to find functions. Aborting.'
return 66
fi
builtin autoload -Uz $funcs[@]

builtin autoload -Uz .autocomplete.__init__
.autocomplete.__init__

# Workaround for https://github.com/zdharma/zinit/issues/366
Expand Down

0 comments on commit 68bae95

Please sign in to comment.