Skip to content

Commit

Permalink
Change the order of matchers
Browse files Browse the repository at this point in the history
Fixes #330.
  • Loading branch information
marlonrichert committed Aug 26, 2021
1 parent 99f0b2a commit 91f22ce
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions module/.autocomplete.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ _autocomplete.config.cache-path() {
reply=( "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/compcache" )
}

zstyle -e ':completion:*' completer _autocomplete.config.completer
zstyle -e ':completion:*' \
completer _autocomplete.config.completer
_autocomplete.config.completer() {
reply=( _expand _complete _correct _complete:-fuzzy _history _history:-fuzzy _ignored )
[[ CURRENT -eq 1 && -z $PREFIX$SUFFIX && $compstate[context] == command ]] &&
reply=( _complete )
}
zstyle ':completion:list-expand:*' completer _expand _complete:-fuzzy _history:-fuzzy _ignored
zstyle ':completion:list-expand:*' \
completer _expand _complete:-fuzzy _history:-fuzzy _ignored
zstyle ':completion:history-incremental-*search-*:*' \
completer _autocomplete.history_lines

zstyle -e ':completion:*' range _autocomplete.config.range
_autocomplete.config.range() {
[[ -z $PREFIX$SUFFIX ]] &&
reply=( 16 )
}
zstyle ':completion:*' remove-all-dups yes

zstyle ':completion:history-incremental-*search-*:*' completer _autocomplete.history_lines

zstyle -e ':completion:*:-command-:*' tag-order _autocomplete.config.tag-order
zstyle ':completion:*:expand:*' \
tag-order '! all-expansions original' -
zstyle -e ':completion:*:-command-:*' \
tag-order _autocomplete.config.tag-order
_autocomplete.config.tag-order() {
local -aU tags=()
[[ -n "$path[(r).]" ]] &&
Expand All @@ -44,27 +50,33 @@ _autocomplete.config.tag-order() {
tags+=( suffix-aliases )
reply=( "$tags" ${${:-$PREFIX$SUFFIX}:--} )
}
zstyle ':completion:list-expand:*:-command-:*' tag-order '*'

zstyle ':completion:*:-tilde-:*' tag-order directory-stack

zstyle ':completion:*:git-*:(|*-)argument-*:*' tag-order \
'commit(|-^(tag))s tree(|-ish)s (|*-)files (|recent-)branch(|-nam)es'
zstyle ':completion:list-expand:*:git-*:(|*-)argument-*:*' tag-order '*'

zstyle ':completion:*:expand:*' tag-order '! all-expansions original' -
zstyle ':completion:*:(approximate|correct):*' tag-order '! original' -

# If we put l: before r:, the matching does not work as expected.
zstyle ':completion:*' matcher-list 'r:|[.]=** r:?|[-_]=* l:?|=[-_\\ ] m:{[:lower:]-}={[:upper:]_}'
zstyle ':completion:*-fuzzy:*' matcher-list 'r:|?=** m:{[:lower:]-}={[:upper:]_}'
zstyle ':completion:*:options' matcher 'b:-=+'
zstyle ':completion:list-expand:*:-command-:*' \
tag-order '*'
zstyle ':completion:*:-tilde-:*' \
tag-order directory-stack
zstyle ':completion:*:git-*:(|*-)argument-*:*' \
tag-order 'commit(|-^(tag))s tree(|-ish)s (|*-)files (|recent-)branch(|-nam)es'
zstyle ':completion:list-expand:*:git-*:(|*-)argument-*:*' \
tag-order '*'
zstyle ':completion:*:(approximate|correct):*' \
tag-order '! original' -

# Order of matchers matters: m should come before r, which should come before l. Otherwise, the
# results are not as expected.
zstyle ':completion:*' \
matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|[.]=** r:?|[-_]=* l:?|=[-_\\ ]'
zstyle ':completion:*-fuzzy:*' \
matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|?=**'

zstyle ':completion:*:options' \
matcher 'b:-=+'

zstyle ':completion:*' prefix-needed yes
zstyle ':completion:*:expand:*' accept-exact continue
zstyle ':completion:*:expand-alias:*' complete yes
zstyle ':completion:*' ignore-parents 'parent pwd directory'
zstyle ':completion:*:users' ignored-patterns '_*'

zstyle ':completion:*:users' ignored-patterns '_*'
zstyle ':completion:*:widgets' ignored-patterns '.*' '*:*' '*orig-*'

zstyle -e ':completion:*:expand:*' glob '
Expand Down

0 comments on commit 91f22ce

Please sign in to comment.