Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _description, _message: escape % in format specs
dana wrote:
> is there a good reason that users of _description and _message, or of
> higher-level helpers like _arguments and _describe, should be able to
> pass arbitrary % sequences down to compadd -[xX] via zformat specs?
There could be a good reason if the other functions got the strings
containing % sequences from a style lookup. But I'd agree that we don't
ever want to be including hard-coded formatting in completion functions.
It could be worth checking matches from rg '_description (-x )?\S*\s\S*\s\"?\$'
This actually affects _numbers and the unit-suffixes tag with the format
style.
> diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description
> index 368b41ee2..dfa2e0860 100644
> --- a/Completion/Base/Core/_description
> +++ b/Completion/Base/Core/_description
> @@ -86,7 +86,7 @@ elif [[ -n "$format" ]]; then
> [[ -n $match[3] ]] && argv+=( o:$match[3] )
> fi
>
> - zformat -F format "$format" "d:$1" "${(@)argv[2,-1]}"
> + zformat -F format "$format" "d:${1//\%/%%}" "${(@)argv[2,-1]//\%/%%}"
How about only changing the d: key here and leaving the second argument
as "${(@)argv[2,-1]}". That gives callers the choice over extra keys
they might add. These might come from zstyle lookups and contain
formatting. A second d: argument will override the first so there's a
workaround also for d: if needed.
For _numbers, 52373 actually broke the formatting I apply for the
default suffix and I've been meaning to look into solving that. The
patch below corrects that but it would be broken again by your patch in
the exact form you posted. In _numbers, $suffixfmt does come from a
style while $argv doesn't. This only doubles a % from argv.
Oliver
diff --git a/Completion/Base/Utility/_numbers b/Completion/Base/Utility/_numbers
index 069fc75a4..9148fea13 100644
--- a/Completion/Base/Utility/_numbers
+++ b/Completion/Base/Utility/_numbers
@@ -70,10 +70,10 @@ elif [[ -prefix $~pat || $PREFIX = $~partial ]]; then
zstyle -s ":completion:${curcontext}:unit-suffixes" format suffixfmt || \
suffixfmt='%(d.%U.)%x%(d.%u.)%(r..|)'
for ((i=0;i<$#;i++)); do
- zformat -f suffix "$suffixfmt" "x:${${argv[i+1]#:}%%:*}" \
- "X:${${argv[i+1]#:}#*:}" "d:${#${argv[i+1]}[1]#:}" \
+ zformat -f suffix "$suffixfmt" "x:${${${argv[i+1]#:}%%:*}//\%/%%}" \
+ "X:${${${argv[i+1]#:}#*:}//\%/%%}" "d:${#${argv[i+1]}[1]#:}" \
i:i r:$(( $# - i - 1))
- suffixes+="${suffix//\%/%%}"
+ suffixes+=$suffix
done
[[ -n $suffixes ]] && formats+=( x:$suffixes )
Messages sorted by:
Reverse Date,
Date,
Thread,
Author