From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26066 invoked by alias); 16 Oct 2016 17:16:50 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39659 Received: (qmail 19423 invoked from network); 16 Oct 2016 17:16:50 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(0.0/5.0):. Processed in 0.280609 secs); 16 Oct 2016 17:16:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:in-reply-to:message-id :references:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=rtxgU kQwsaGDJhHtxUEerg5fuD4=; b=YZR2Se5LvD92P8+5t+DHH64MsECPB/pj7Jne0 i+Z6QQW4NlQa9cRODbN36hLN/0t6q7KlD4uJOMn5/zBEUuU292eW+b1eTXLQBipL I19q5zvVecgR78bdMptGU6tZbhWvCZ9fFavzXm4KtkilSNc270oVs7Y2eset70cL DguU5E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=rtxg UkQwsaGDJhHtxUEerg5fuD4=; b=SFdWgWbf1jMCaDz9m95C+qar1nFzhadW5r9C pqdGtSjNOhduXpOJz9n1p1LoXixFuyFj4nfcz54nDR69gvkGua9oksLJXD3TjQ9H fmXJcrkoOU608PjEPOLFIcxld8Oe69pFzl8anx5P2LYT+3UdcV5ffi5qN4gK0oYJ bSS4EuE= X-Sasl-enc: cuS/LOX1FCAoyyNBmhCl85XbR6kKIyX//0LF2gI51OMp 1476638206 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 3/3] _zstyle: Complete the -g, -s,-b,-a, -t,-T, -m options. Date: Sun, 16 Oct 2016 17:14:50 +0000 Message-Id: <1476638090-1551-3-git-send-email-danielsh@fujitsu.shahaf.local2> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476638090-1551-1-git-send-email-danielsh@fujitsu.shahaf.local2> References: <1476638090-1551-1-git-send-email-danielsh@fujitsu.shahaf.local2> --- Completion/Zsh/Command/_zstyle | 89 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 553917b..d6f2852 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -1,7 +1,7 @@ #compdef zstyle local state context ostate line expl ctop suf -local nm=$compstate[nmatches] taglist patterns pstyles contexts +local nm=$compstate[nmatches] taglist patterns contexts typeset -A opt_args styles _vcs_info_hooks() { @@ -216,17 +216,27 @@ taglist=( email-address ${(k)functions[(I)_email-*]#_} ) +# Be careful with the context arguments here. They like to masquerade. _arguments -C \ - '(-)-L[output in form of zstyle commands]' \ - '(: -)-d[delete style definitions]:context pattern:->patterns:*:styles:->pstyles' \ - '(-)-e[value is evaluated when style is looked up]' \ - ':context:->contexts' ':style:->styles' '*:argument:->style-arg' + '(: -)-L[output in form of zstyle commands]:pattern for context patterns:->metapatterns:style:->metastyles' \ + '(: -)-d[delete style definitions]:verbatim context pattern:->patterns:*:styles:->pstyles' \ + '(: -)-e[value is evaluated when style is looked up]:context pattern:->contexts:style:->styles:*:command:_cmdstring' \ + '(: -)-g[retrieve style definition]:array parameter:_parameters -g "*array*":verbatim context pattern:->patterns:styles:->pstyles' \ + '(: -)-s[retrieve style value as string]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*":separator: ' \ + '(: -)-b[retrieve style value as boolean]:context name:->contexts:style:->styles:scalar parameter:_parameters -g "*scalar*"' \ + '(: -)-a[retrieve style value as array]:context name:->contexts:style:->styles:array parameter:_parameters -g "*array*"' \ + '(: -)-t[test a style, returning false if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \ + '(: -)-T[test a style, returning true if it'\''s undefined]:context name:->contexts:style:->styles:*:strings to test presence of: ' \ + '(: -)-m[pattern-match values of a style]:context name:->contexts:style:->styles:pattern: ' \ + '(-):context pattern:->contexts' '(-):style:->styles' '(-)*:argument:->style-arg' while (( $#state )); do case "$state[1]" in + # 'contexts' completes either full context names (for -t/-s/-a), or context + # patterns (for 'zstyle :foo bar' and -e). (contexts) if [[ ! -prefix :*: ]]; then - _wanted contexts expl context compadd -P : -qS : chpwd completion vcs_info zftp zle + _wanted contexts expl "$state_descr" compadd -P : -qS : chpwd completion vcs_info zftp zle elif compset -P :completion:; then contexts=( functions _completers cmdorcont argument tag ) elif compset -P :vcs_info:; then @@ -250,19 +260,80 @@ while (( $#state )); do fi ;; + # 'patterns' completes context patterns that are set, for -d/-g. (patterns) zstyle -g patterns - _wanted contexts expl 'context pattern' compadd -a patterns + _wanted contexts expl "$state_descr" compadd -a patterns ;; + # 'metapatterns': patterns that are are matched not against contexts, but + # against patterns. + (metapatterns) + zstyle -g patterns + patterns=( "${(@b)patterns}" ) + _wanted contexts expl "$state_descr" compadd -a patterns + ;; + + # 'metastyles': styles that are set on context patterns matching the given + # metapattern. + (metastyles) + # Anonymous function to shadow the global $styles assoc + () { + local metapattern=${(Q)${${opt_args[-L]%:*}//(#m)\\([\\:])/${MATCH[2]}}} + local -a metastyles styles + local pattern + zstyle -g patterns + for pattern in "${(@M)patterns:#${~metapattern}}"; do + zstyle -g styles $pattern + metastyles+=( "${styles[@]}" ) + done + _wanted styles expl "$state_descr" compadd -a metastyles + unset pattern + unset metastyles + } + ;; + + # 'pstyles': complete styles that are set for the verbatim context pattern + # specified on the command line. (If the user has set no zstyles, this + # will complete nothing.) (pstyles) - zstyle -g pstyles ${(Q)${(M)opt_args[-d]#*[^\\]:}%:} + local -a pstyles + local pattern + if (( $+opt_args[-d] )); then + pattern=${opt_args[-d]} + pattern=${pattern%":${(b)PREFIX}"} # remove style + pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping + pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob) + zstyle -g pstyles $pattern + elif (( $+opt_args[-g] )); then + pattern=${opt_args[-g]} + pattern=${pattern%":${(b)PREFIX}"} # remove style + pattern=${pattern#*:} # remove array name + pattern=${pattern//(#m)\\([\\:])/${MATCH[2]}} # undo _arguments escaping + pattern=${(Q)pattern} # undo command-line escaping (assumes no noglob) + zstyle -g pstyles $pattern + fi _wanted styles expl style compadd -a pstyles + unset pattern + unset pstyles ;; + # 'styles': complete all styles that may be set in the context given on the + # command line. This is independent of what styles are set. (styles) # Get the top-level context we're completing for, if any. - case ${(Q)line[1]} in + if [[ -n $line[1] ]]; then + # zstyle :something + local the_context=$line[1] + else + # zstyle -x :something + local joined_value=${(v)opt_args[(i)(-e|-s|-b|-a|-t|-T|-m)]} + local the_context=${(Q)joined_value[0, ${joined_value[(i)[^\\]:]}-2 ]} + fi + # Note: for 'zstyle :something ' and for 'zstyle -e :something ', + # $the_context is a context pattern; for -s,-b,-a,-t,-T,-m, it is a context + # name. We currently draw no distinction between these two cases. + case $the_context in (:completion:*) ctop=c ;;