From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25526 invoked by alias); 9 Jul 2015 12:24:07 -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: 35748 Received: (qmail 29820 invoked from network); 9 Jul 2015 12:24:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1436444280; bh=s8lZ5rnLhxfe1zCRHkCxih9G4Jf5gSei7eshe/MsE4k=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=XIFYOZ5oLa0jOM+hxo7nO2VPa8HsBDvnqnVSkyZ4JWMvG7tl+iwKZbcWDLOX+ddR1fob5mSnRo/Sa/7zHop000SWDsWTOHAiiNAEj7fyGJ2C/8u6RhR0VkW4GqECIZdzZHQe4UHRpOMpw9roT63ULwMyl6pNfnu8ITAxB/8rfA48FZS++qxGBu70Ql+wqiMxv+CWBsOEMezHwR7prfpFRxZyBorgiBcNVdSl2mxasCYkSpNzA/atalIHoZQL9HAqmJ1BXVzMOKgQg0+XLXmfMj81Raq+nA9EWi0ZIES1FOloF9r0j/5kDQ47FDqynKQxK+YSLzeEfErYxJQKv9+thw== X-Yahoo-Newman-Id: 726707.18483.bm@smtp148.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: QPj1j.kVM1m2JH9qmfiwQCUepH3Qmhr9Vm0FEO1ym6fhm3C _8DoSLZJzOmPfBt42lwkma2P3X28Ms3__Tksyq0.ZChjXcdRpjTKSPVx9XlY iJK5tO5l5kKNDCdUn7oP8aHKd_YLUg3iEWcQ_KN.K91PVE2cpQDRS2rDY.bG d4UI0eCunkk.BUfQ5KzAHs9jiekKm93XF_aC.ODh.snGiBrYCHjKVPkmVaAX YXWitFix7KDM1mM2c61WeWhl4UM.CBGNtO4.y7zxxxIk4XzhNDzt_kt0wQoN uFPvICrDiWCYYqS8KgEG7nt01CeOr8mwm.9KD6YmzzQ3ZUPyAfzwyX_ISBvQ fUX7CfUct4p1ZZRmqSTjTsWzO5uWUyEW_wueqfPP3FULf9PNjOl2QIveBRlw H3SHORiRszXrT_hUtg2c72T8C57_in6wnIGvJw2yP49yywJm1oKgUqdLR1le dzRORkvMQ2p1C_PtYwYsxthMaZLSOtLnvIn8xZ41YsRTj7O1iAaKwrc5trQZ 7zU1ZL6H1fhd36LuR68yNzkfBRpaXQQ-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: From: Oliver Kiddle References: <1436143012-9243-1-git-send-email-mikachu@gmail.com> <4740.1436181110@thecus.kiddle.eu> <97E3F4A3-6951-4848-8711-B8BD609BA79D@kba.biglobe.ne.jp> To: zsh workers Subject: Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21763.1436444277.1@thecus.kiddle.eu> Content-Transfer-Encoding: quoted-printable Date: Thu, 09 Jul 2015 14:17:57 +0200 Message-ID: <21764.1436444277@thecus.kiddle.eu> Mikael Magnusson wrote: > = > I've also just noticed that completion after %D\{%\# and \^ doesn't > work, but single-quoted is fine. That's the fault of _ps1234. It's best to use compset -P and get to a point where _date_formats is called with $PREFIX only containing date formats and no prompt stuff. I finally worked out that the point of calling _default from _ps1234 is for print -P. That's _print's job to do that. This patch also fixes and improves other things like the positioning of numeric arguments for ternary expressions. > >> Completion/Unix/Type/_ps1234 | 14 +++++-- > > Shouldn't this be in Completion/Zsh/Type? > Possibly, but I figured we could use it for _date too? I meant _ps1234 not _date_formats. I'll move it when applying this patch. Oliver diff --git a/Completion/Unix/Type/_ps1234 b/Completion/Unix/Type/_ps1234 index b9e5166..8d3c5d8 100644 --- a/Completion/Unix/Type/_ps1234 +++ b/Completion/Unix/Type/_ps1234 @@ -1,82 +1,58 @@ #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMP= T3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,R= PROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,= -default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-defau= lt- -value-,SPROMPT,-default- = local -a specs -local expl bs +local expl bs suf pre changed=3D1 ret=3D1 = if [[ -z $compstate[quote] ]]; then - bs=3D'\' + bs=3D'\' # in patterns we use (\\|) widely as print -P handles backslas= hes first fi = -if [[ $PREFIX =3D=3D *%D$bs\{[^($bs\})]# ]]; then - _date_formats zsh -elif [[ $PREFIX =3D=3D *%(-|)<-># ]]; then +# first strip off any complete prompt specifications leaving only the +# current, incomplete, one +while (( changed )); do + changed=3D0 + compset -P '%[DFK](\\|){[^}]#}' && changed=3D1 # formats with arg: %x{.= ..} + compset -P '%[0-9-\\]#[^DFK(0-9-<>\\\[]' && changed=3D1 # normal format= s + compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=3D1 # tr= uncations + compset -P '%[0-9-\\]#(\\|)\(??|[^%]' && changed=3D1 # start of ternary + compset -P '[^%]##' && changed=3D1 # sundry other characters + # %D/%F/%K without a following { ... } + [[ $PREFIX =3D %(-|)<->#[DFK](\\|)[^{\\]* ]] && + compset -P '%[0-9\\-]#[DFK]' && changed=3D1 +done +[[ $PREFIX =3D %(-|)<->[FK](#e) ]] && compset -P '*' # F/K with number + +if compset -P '%[FK]'; then + # this should use -P but that somehow causes single quotes to be stripp= ed + compset -P '(\\|){' || pre=3D( -p "$bs{" ) + compset -S '(\\|)}*' || suf=3D( -S $bs\} ) specs=3D( - 'm:hostname up to first .' - '_:status of parser' - 'd:current working directory' - '/:current working directory' - '~:current working directory, with ~ replacement' - 'N:name of current script or shell function' - 'x:name of file containing code being executed' - 'c:deprecated' - '.:deprecated' - 'C:deprecated' - 'F:start using fg color' - 'K:start using bg color' - 'G:counts as extra character inside %{...%}' + black + red + green + yellow + blue + magenta + cyan + white + default ) - if [[ $PREFIX =3D=3D *% ]]; then - if [[ $service =3D=3D -value-,SPROMPT,* ]]; then - specs+=3D( - 'r:suggested correction' - 'R:corrected string' - ) - fi - specs+=3D( - '%:A %' - '):A )' - 'l:current line (tty) with /dev/tty stripped' - 'M:full hostname' - 'n:username' - 'y:current line (tty)' - '#:a # when root, % otherwise' - '?:return status of last command' - 'h:current history event number' - '!:current history event number' - 'i:current line number' - 'I:current source line number' - 'j:number of jobs' - 'L:$SHLVL' - 'D:date in yy-mm-dd format' - 'T:current time of day, 24-hour format' - 't:current time of day, 12-hour am/pm format' - '@:current time of day, 12-hour am/pm format' - '*:current time of day, 24-hour format with seconds' - 'w:the date in day-dd format' - 'W:the date in mm/dd/yy format' - 'D{:format string like strftime' - 'B:start bold' - 'b:stop bold' - 'E:clear to end of line' - 'U:start underline' - 'u:stop underline' - 'S:start standout' - 's:stop standout' - 'f:reset fg color' - 'k:reset bg color' - '{:start literal escape sequence' - '}:stop literal escape sequence' - 'v:value from $psvar array' - '(:ternary expression %(x.true-string.false-string)' - '<<:truncation from left %len>:truncation from right %len>string>' - '[]:truncation from who knows where' - ) + _wanted ansi-colors expl 'ansi color' compadd $suf $pre -a specs && ret= =3D0 + if (( $#suf )) && compset -P "<->"; then + _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=3D0 + else + _message -e terminal-colors "number between 0 and $(( $terminfo[color= s] - 1 ))" fi - compset -P "*" - _describe -t prompt-format-specifier 'prompt format specifier' specs -S= '' - _message -e prompt-format-specifier number -elif [[ $PREFIX =3D=3D *%$bs\((-|)<-># ]]; then +fi + +if compset -P '%[0-9-\\]#\(?'; then + compset -S '*' + _delimiters && ret=3D0 +elif compset -P '%[0-9-\\]#[<>\]]'; then + _message -e replacements 'replacement string' +elif compset -P '%[0-9-\\]#(\\|)\('; then + compset -S '[.:+/-%]*' || suf=3D( -S . ) + compset -S '*' specs=3D( '!:running with privileges' '#:effective uid' @@ -100,35 +76,82 @@ elif [[ $PREFIX =3D=3D *%$bs\((-|)<-># ]]; then 'V:element n of psvar is set and non-empty' 'w:day of week (Sunday =3D 0)' ) - compset -P "*" - _describe -t ternary-prompt-expression 'ternary prompt format test char= acter' specs -S '' - _message -e ternary-prompt-expression number -elif [[ $PREFIX =3D=3D *%[FK]$bs\{[0-9a-z]# ]]; then + _describe -t ternary-prompt-expressions 'ternary prompt format test cha= racter' specs $suf && ret=3D0 +elif compset -P '%D(\\|){'; then + compset -S '(\\|)}*' + _date_formats zsh && ret=3D0 +elif [[ -prefix '%' ]] || + ! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" pr= efix-needed +then specs=3D( - black - red - green - yellow - blue - magenta - cyan - white - default + 'm:hostname up to first .' + '_:status of parser' + '^:reversed status of parser' + 'd:current working directory' + '/:current working directory' + '~:current working directory, with ~ replacement' + 'N:name of current script or shell function' + 'x:name of file containing code being executed' + 'c:deprecated' + '.:deprecated' + 'C:deprecated' + 'F:start using fg color' + 'K:start using bg color' + 'G:counts as extra character inside %{...%}' + '(:ternary expression %(x.true-string.false-string)' ) - compset -P "*{" - _describe -t ansi-color-name 'ansi color' specs -S $bs\} - if compset -P "<->"; then - _wanted ansi-color-number expl 'close brace' compadd -S '' \} - else - _message -e ansi-color-number "number between 0 and $(( $terminfo[col= ors] - 1 ))" - fi -else - _default "$@" - specs=3D(%) - if compset -P "*%D"; then - specs+=3D(\{) - else - compset -P "*" + compset -P '%' || pre=3D( -p '%' ) + if ! compset -P '(-|)<->'; then + if [[ $service =3D=3D -value-,SPROMPT,* ]]; then + specs+=3D( + 'r:suggested correction' + 'R:corrected string' + ) + fi + specs+=3D( + '%:A %' + '):A )' + 'l:current line (tty) with /dev/tty stripped' + 'M:full hostname' + 'n:username' + 'y:current line (tty)' + '#:a # when root, % otherwise' + '?:return status of last command' + 'h:current history event number' + '!:current history event number' + 'i:current line number' + 'I:current source line number' + 'j:number of jobs' + 'L:$SHLVL' + 'D:date in yy-mm-dd format' + 'T:current time of day, 24-hour format' + 't:current time of day, 12-hour am/pm format' + '@:current time of day, 12-hour am/pm format' + '*:current time of day, 24-hour format with seconds' + 'w:the date in day-dd format' + 'W:the date in mm/dd/yy format' + 'D{:format string like strftime' + 'B:start bold' + 'b:stop bold' + 'E:clear to end of line' + 'U:start underline' + 'u:stop underline' + 'S:start standout' + 's:stop standout' + 'f:reset fg color' + 'k:reset bg color' + '{:start literal escape sequence' + '}:stop literal escape sequence' + 'v:value from $psvar array' + '<:truncation from left %len:truncation from right %len>string>' + '[:truncation from who knows where' + ) fi - _describe -t prompt-format-specifier 'prompt format specifier' specs -S= '' + _describe -t prompt-format-specifiers 'prompt format specifier' \ + specs -S '' $pre && ret=3D0 + (( ! $#pre )) && [[ -prefix '(-|)<->' ]] && + _message -e prompt-format-specifiers number fi + +return ret diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index 4053933..1eba13e 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -11,7 +11,7 @@ if [[ $service =3D print ]]; then pflag=3D'(-s -u -z)-p[print arguments to input of coprocess]' = if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then - rest=3D'*: :_ps1234' + rest=3D'*: :->prompt' else rest=3D'*: :_default' fi @@ -48,16 +48,17 @@ if [[ $state =3D printf ]]; then fi = if [[ $state =3D printfformat ]]; then - if [[ ${(Q)PREFIX} =3D *%((-|)<->|[-#0 +*.])# ]]; then + if [[ ${(Q)PREFIX} =3D *%[0-9\$#\ +*.\'-]# ]]; then local -a specs specs=3D( '#:alternate form' - '0:zeropad to length n' + '0:zero pad to length' '-:left adjust result' ' :leave one space in front of positive number from signed conver= sion' '+:always place sign before a number from signed conversion' '*:field width in next argument' '.:precision' + "':thousand separators" 'c:print the first character of the argument' 's:print the argument as a string' {d,i}':signed decimal number or with leading " numeric value of f= ollowing character' @@ -73,12 +74,16 @@ if [[ $state =3D printfformat ]]; then 'q:as %s but shell quote result' ) compset -P "*" - _describe -t print-format-specifier 'print format specifier' specs -S= '' - _message -e print-format-specifier 'number' + _describe -t print-format-specifiers 'print format specifier' specs -= S '' + _message -e print-format-specifiers 'number' else - _describe -t print-format-specifier 'print format specifier' '(%)' -S= '' + _wanted print-format-specifiers expl 'print format specifier' compadd= -S '' % fi ret=3D0 +elif [[ $state =3D prompt ]]; then + _default && ret=3D0 + # complete prompt specifiers without interfering too much with default = completion + (( $#compstate[unambiguous] <=3D $#PREFIX || ! $#PREFIX )) && _ps1234 &= & ret=3D0 fi = return ret