From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9832 invoked from network); 16 May 2008 09:34:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 May 2008 09:34:15 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 2041 invoked from network); 16 May 2008 09:34:11 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 May 2008 09:34:11 -0000 Received: (qmail 12256 invoked by alias); 16 May 2008 09:34:08 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25051 Received: (qmail 12242 invoked from network); 16 May 2008 09:34:07 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 16 May 2008 09:34:07 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 3A7D180589A4 for ; Fri, 16 May 2008 11:34:04 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly23d.srv.mailcontrol.com (MailControl) with ESMTP id m4G9Vtl8005356 for ; Fri, 16 May 2008 10:33:56 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 16 May 2008 10:33:02 +0100 Date: Fri, 16 May 2008 10:33:01 +0100 From: Peter Stephenson To: zsh-workers Subject: Re: %F doesn't work in format style Message-ID: <20080516103301.40f6f44e@news01> In-Reply-To: <20080515220800.6a91e574@pws-pc> References: <237967ef0805151229r4955bacep64af7bb018bc16b@mail.gmail.com> <20080515220800.6a91e574@pws-pc> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 16 May 2008 09:33:02.0946 (UTC) FILETIME=[D679F420:01C8B737] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.68.0.133 X-Virus-Scanned: ClamAV 0.91.2/7132/Fri May 16 00:14:34 2008 on bifrost X-Virus-Status: Clean On Thu, 15 May 2008 22:08:00 +0100 Peter Stephenson wrote: > On Thu, 15 May 2008 21:29:25 +0200 > "Mikael Magnusson" wrote: > > zstyle ':completion:*:corrections' format '%B---- %d (errors: %e)%b' > > works fine > > zstyle ':completion:*:corrections' format '%F{red}---- %f%d (errors: %e)%b' > > produces > > {red}---- corrections (errors: 2) > > (unformatted) > > > > The manpage claims > > This string may also contain the sequences > > to specify output attributes, such as `%B', `%S' and `%{...%}' > > > > Is %F such as %B? :) It's listed in the same section anyway. > > This is all handled completely separately in zle_tricky.c for standard > completion formatting and yet again in complist.c when zsh/complist is > loaded. The code's not that big, and there wasn't enough nexus for a joinder (I don't know what this means either), so I've just added it in both places. Also fix the non-use of fallthrough in the prompt code (for %F{default}, just to be compatible), and propagate the use of %{ with a number to indicate width to the completion code. Possibly the documentation now needs to be more explict. (Lucky I didn't grab %d for any of the colour sequences.) Index: Src/prompt.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v retrieving revision 1.50 diff -u -r1.50 prompt.c --- Src/prompt.c 12 May 2008 13:50:42 -0000 1.50 +++ Src/prompt.c 16 May 2008 09:28:02 -0000 @@ -471,7 +471,6 @@ break; } /* else FALLTHROUGH */ - break; case 'f': txtchangeset(txtchangep, TXTNOFGCOLOUR, TXT_ATTR_FG_ON_MASK); txtunset(TXT_ATTR_FG_ON_MASK); @@ -493,7 +492,6 @@ break; } /* else FALLTHROUGH */ - break; case 'k': txtchangeset(txtchangep, TXTNOBGCOLOUR, TXT_ATTR_BG_ON_MASK); txtunset(TXT_ATTR_BG_ON_MASK); @@ -1472,7 +1470,7 @@ */ /**/ -static int +mod_export int match_colour(const char **teststrp, int is_fg, int colour) { int shft, on, named = 0, tc; Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.115 diff -u -r1.115 complist.c --- Src/Zle/complist.c 12 May 2008 16:49:59 -0000 1.115 +++ Src/Zle/complist.c 16 May 2008 09:28:02 -0000 @@ -1046,6 +1046,8 @@ if (doesc && cchar == ZWC('%')) { p += len; if (*p) { + int arg = 0, is_fg; + len = MB_METACHARLENCONV(p, &cchar); #ifdef MULTIBYTE_SUPPORT if (cchar == WEOF) @@ -1053,6 +1055,9 @@ #endif p += len; + if (idigit(*p)) + arg = zstrtol(p, &p, 10); + m = 0; switch (cchar) { case ZWC('%'): @@ -1099,7 +1104,32 @@ if (dopr) tcout(TCUNDERLINEEND); break; + case ZWC('F'): + case ZWC('K'): + is_fg = (cchar == ZWC('F')); + /* colours must be ASCII */ + if (*p == '{') { + p++; + arg = match_colour((const char **)&p, is_fg, 0); + if (*p == '}') + p++; + } else + arg = match_colour(NULL, is_fg, arg); + if (arg >= 0 && dopr) + set_colour_attribute(arg, is_fg ? COL_SEQ_FG : + COL_SEQ_BG, 0); + break; + case ZWC('f'): + if (dopr) + set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, 0); + break; + case ZWC('k'): + if (dopr) + set_colour_attribute(TXTNOBGCOLOUR, COL_SEQ_BG, 0); + break; case ZWC('{'): + if (arg) + cc += arg; for (; *p && (*p != '%' || p[1] != '}'); p++) if (dopr) putc(*p == Meta ? *++p ^ 32 : *p, shout); Index: Src/Zle/zle_tricky.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v retrieving revision 1.94 diff -u -r1.94 zle_tricky.c --- Src/Zle/zle_tricky.c 22 Apr 2008 15:08:14 -0000 1.94 +++ Src/Zle/zle_tricky.c 16 May 2008 09:28:03 -0000 @@ -2272,7 +2272,10 @@ for (; *p; ) { /* Handle the `%' stuff (%% == %, %n == ). */ if (doesc && *p == '%') { - if (*++p) { + int arg = 0, is_fg; + if (idigit(*++p)) + arg = zstrtol(p, &p, 10); + if (*p) { m = 0; switch (*p) { case '%': @@ -2316,11 +2319,33 @@ if (dopr) tcout(TCUNDERLINEEND); break; + case 'F': + case 'K': + is_fg = (*p == 'F'); + if (p[1] == '{') { + p += 2; + arg = match_colour((const char **)&p, is_fg, 0); + if (*p != '}') + p--; + } else + arg = match_colour(NULL, is_fg, arg); + if (arg >= 0) + set_colour_attribute(arg, is_fg ? COL_SEQ_FG : + COL_SEQ_BG, 0); + break; + case 'f': + set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, 0); + break; + case 'k': + set_colour_attribute(TXTNOBGCOLOUR, COL_SEQ_BG, 0); + break; case '{': + if (arg) + cc += arg; for (p++; *p && (*p != '%' || p[1] != '}'); p++) { if (*p == Meta) { p++; - if (dopr) + if (dopr) putc(*p ^ 32, shout); } else if (dopr) -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070