Skip to content

Commit

Permalink
Remove _expand patch
Browse files Browse the repository at this point in the history
It's now included in Zsh itself.
  • Loading branch information
marlonrichert committed May 27, 2023
1 parent 57fbd04 commit 6a80e62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 52 deletions.
34 changes: 21 additions & 13 deletions scripts/.autocomplete.async
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ builtin zle -N history-incremental-search-backward .autocomplete.async.history-i
(( KEYS_QUEUED_COUNT || PENDING )) &&
return

# #549: Work around bug in zdharma/fast-syntax-highlighting.
# WORKAROUND: #549 Bug in zdharma/fast-syntax-highlighting.
[[ -v _FAST_MAIN_CACHE ]] &&
_zsh_highlight

Expand Down Expand Up @@ -263,7 +263,6 @@ log_functions+=( .autocomplete.async.pty.zle-widget.inner )
}
autocomplete:_message:old "$@"
unfunction zformat
functions[compadd]="$functions[.autocomplete.compadd]"
}

local +h -a comppostfuncs=( .autocomplete.async.pty.message )
Expand All @@ -290,6 +289,9 @@ log_functions+=( .autocomplete.async.pty.completion-widget.inner )
{
builtin zle -F $fd # Unhook ourselves immediately, so we don't get called more than once.

[[ -v DEBUG ]] &&
set -x -o localoptions

# Ensure our input will not be stopped.
unset _autocomplete__async_complete_fd

Expand Down Expand Up @@ -355,6 +357,9 @@ log_functions+=( .autocomplete.async.complete.fd-widget.inner )
}

.autocomplete.async.list-choices.completion-widget() {
[[ -v DEBUG ]] &&
set -x -o localoptions

unset _autocomplete__mesg _autocomplete__comp_mesg
unset _autocomplete__curcontext _autocomplete__current _autocomplete__words

Expand Down Expand Up @@ -383,7 +388,7 @@ log_functions+=( .autocomplete.async.complete.fd-widget.inner )
typeset -gF _autocomplete__async_avg_duration=$((
.1 * _seconds_ + .9 * _autocomplete__async_avg_duration
))
.autocomplete.async.list-choices.main-complete
.autocomplete.async.list-choices.main-complete
fi

typeset -ga _autocomplete__comp_mesg=( "$@" )
Expand All @@ -403,6 +408,9 @@ log_functions+=( .autocomplete.async.complete.fd-widget.inner )
_lastcomp[list_lines]=$compstate[list_lines]
fi

[[ -v DEBUG ]] &&
typeset -m _lastcomp >&2

return 2 # Don't return 1, to prevent beeping.
} 2>>| $_autocomplete__log
log_functions+=( .autocomplete.async.list-choices.completion-widget )
Expand Down Expand Up @@ -433,8 +441,9 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
[[ -v functions[compadd] ]] &&
functions[autocomplete:async:compadd:old]="$functions[compadd]"
functions[compadd]="$functions[.autocomplete.async.compadd]"

[[ -v DEBUG ]] &&
functions -T compadd .autocomplete.compadd _describe
functions -T compadd _describe
} "$@"

.autocomplete.async.list-choices.max-lines 16
Expand All @@ -459,7 +468,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )

if [[ -v _opts_[-x] && $# -eq 2 ]]; then
# Adding a message only.
.autocomplete.compadd "$@"
builtin compadd "$@"
return
fi

Expand All @@ -479,7 +488,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
return 1

else
.autocomplete.compadd "$@"
builtin compadd "$@"
_ret_=$?

_displ_=( ${(@PA)_displ_name_} )
Expand All @@ -501,7 +510,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
elif [[ -n $_opts_[-E] ]]; then
# End of describe loop. It will now add matches in a special way. Can't interfere with this or it will break.
(( _autocomplete__described_lines = 0 )) # Done with this _describe loop.
.autocomplete.compadd "$@"
builtin compadd "$@"
return
fi

Expand All @@ -511,15 +520,15 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )

# Deleting or collecting completions, but not actually adding them.
if [[ -n $_opts_[-D]$_opts_[-O] ]]; then
.autocomplete.compadd "$@"
builtin compadd "$@"
return
fi

[[ -v _autocomplete__partial_list ]] &&
return 1

local -Pi _resulting_list_lines="$(
.autocomplete.compadd "$@"
builtin compadd "$@"
print -nr -- $compstate[list_lines]
)"
local -Pi _new_list_lines_=$(( _resulting_list_lines - $compstate[list_lines] ))
Expand All @@ -529,7 +538,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
.autocomplete.async.compadd.disable

if (( _remaining_list_lines >= 0 )); then
.autocomplete.compadd "$@"
builtin compadd "$@"
return
fi

Expand All @@ -538,7 +547,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
local -a _Dopt_=( -D $_displ_name_ )

# Collect all matching completions and, if present, remove the display strings of those that don't match.
.autocomplete.compadd -O _matches_ $_Dopt_ "$@"
builtin compadd -O _matches_ $_Dopt_ "$@"

if [[ -z $_displ_name_ ]]; then
_displ_=( "$_matches_[@]" )
Expand Down Expand Up @@ -566,8 +575,7 @@ log_functions+=( .autocomplete.async.list-choices.completion-widget )
shift -p $_nmatches_to_remove_ _matches_ $_displ_name_

_autocomplete.compadd_opts_len "$@"
.autocomplete.compadd $_dopt_ -a "$@[1,?]" _matches_

builtin compadd $_dopt_ -a "$@[1,?]" _matches_
}

.autocomplete.async.compadd.disable() {
Expand Down
46 changes: 7 additions & 39 deletions scripts/.autocomplete.compinit
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,8 @@ EOF
compstate[list]='list force packed rows' # `_setup` doesn't work well for this.
unset 'compstate[vared]'

{
() {
emulate -L zsh
setopt $_autocomplete__func_opts[@]

if ! (( funcstack[(I).autocomplete.async.list-choices.main-complete] )); then
[[ -v functions[compadd] ]] &&
functions[autocomplete:compadd:old]="$functions[compadd]"
functions[compadd]="$functions[.autocomplete.compadd]"
fi
} "$@"

local +h -a comppostfuncs=( autocomplete:_main_complete:new:post "$comppostfuncs[@]" )
autocomplete:_main_complete:old "$@"
} always {
unfunction compadd 2> /dev/null
if [[ -v functions[autocomplete:compadd:old] ]]; then
functions[compadd]="$functions[autocomplete:compadd:old]"
unfunction autocomplete:compadd:old
fi
}
}

# Add support for coloring file types to _expand.
# TODO: Might be added a future version of zsh.
.autocomplete.compadd() {
if [[ $_completer == expand* ]]; then
[[ $@[-1] == space && $#space[@] -eq 1 ]] &&
space=( ${(q+)${(Q)space}} )
builtin compadd -fW "${${${words[CURRENT]:#[~/]*}:+$PWD/}:-/}" "$@"
else
builtin compadd "$@"
fi
local +h -a comppostfuncs=( autocomplete:_main_complete:new:post "$comppostfuncs[@]" )
autocomplete:_main_complete:old "$@"
}

autocomplete:_main_complete:new:post() {
Expand Down Expand Up @@ -173,8 +142,7 @@ EOF
_autocomplete.ancestor_dirs "$@" ||
_autocomplete.recent_paths "$@"

# Work around the fact that some completion functions mistakenly don't
# return 0 when they have succeeded.
# WORKAROUND: Some completion functions mistakenly don't return 0 when they have succeeded.
(( compstate[nmatches] > nmatches ))
}

Expand Down Expand Up @@ -208,14 +176,14 @@ EOF

if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
else
else
PREFIX="(#a${_comp_correct})$PREFIX"
fi
fi

if [[ -v functions[autocomplete:compadd:old] ]]; then
autocomplete:compadd:old "$@"
else
builtin compadd "$@"
fi
builtin compadd "$@"
fi
}
}

0 comments on commit 6a80e62

Please sign in to comment.