zsh completion: helper functions in private namespace

The generate_xxx() helpers, once defined, would appear as
user-visible functions; this would lead to unexpected and
confusing completion suggestions for gene<tab> after having
once run mpv in that shell.

This PR adds the prefix '_mpv_' to all completion functions
as a convention to make them less user-visible and less likely
to collide with other packages.
This commit is contained in:
Ed Santiago 2020-05-10 07:44:59 -06:00 committed by wm4
parent 152b0e2a8c
commit 43cb89fca3
1 changed files with 6 additions and 6 deletions

View File

@ -35,7 +35,7 @@ zstyle -a ":completion:*:*:$service:*" tag-order tag_order ||
typeset -ga _mpv_completion_arguments _mpv_completion_protocols typeset -ga _mpv_completion_arguments _mpv_completion_protocols
function generate_arguments { function _mpv_generate_arguments {
_mpv_completion_arguments=() _mpv_completion_arguments=()
@ -143,7 +143,7 @@ function generate_arguments {
} }
function generate_protocols { function _mpv_generate_protocols {
_mpv_completion_protocols=() _mpv_completion_protocols=()
local list_protos_line local list_protos_line
for list_protos_line in "${(@f)$($words[1] --list-protocols)}"; do for list_protos_line in "${(@f)$($words[1] --list-protocols)}"; do
@ -153,7 +153,7 @@ function generate_protocols {
done done
} }
function generate_if_changed { function _mpv_generate_if_changed {
# Called with $1 = 'arguments' or 'protocols'. Generates the respective list # Called with $1 = 'arguments' or 'protocols'. Generates the respective list
# on the first run and re-generates it if the executable being completed for # on the first run and re-generates it if the executable being completed for
# is different than the one we used to generate the cached list. # is different than the one we used to generate the cached list.
@ -168,7 +168,7 @@ function generate_if_changed {
# However, we can't rely on PCRE being available, so we keep all our # However, we can't rely on PCRE being available, so we keep all our
# patterns POSIX-compatible. # patterns POSIX-compatible.
zmodload -s -F zsh/pcre C:pcre-match && setopt re_match_pcre zmodload -s -F zsh/pcre C:pcre-match && setopt re_match_pcre
generate_$1 _mpv_generate_$1
_mpv_completion_binary[$1]=$current_binary _mpv_completion_binary[$1]=$current_binary
fi fi
} }
@ -177,7 +177,7 @@ function generate_if_changed {
# an option. This way, the user should never see a delay when just completing a # an option. This way, the user should never see a delay when just completing a
# filename. # filename.
if [[ $words[$CURRENT] == -* ]]; then if [[ $words[$CURRENT] == -* ]]; then
generate_if_changed arguments _mpv_generate_if_changed arguments
fi fi
local rc=1 local rc=1
@ -237,7 +237,7 @@ case $state in
if _requested urls; then if _requested urls; then
while _next_label urls expl URL; do while _next_label urls expl URL; do
_urls "$expl[@]" && rc=0 _urls "$expl[@]" && rc=0
generate_if_changed protocols _mpv_generate_if_changed protocols
compadd -S '' "$expl[@]" $_mpv_completion_protocols && rc=0 compadd -S '' "$expl[@]" $_mpv_completion_protocols && rc=0
done done
fi fi