From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13428 invoked from network); 15 Aug 2006 14:30:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Aug 2006 14:30:46 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 80466 invoked from network); 15 Aug 2006 14:30:37 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Aug 2006 14:30:37 -0000 Received: (qmail 29347 invoked by alias); 15 Aug 2006 14:30:34 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22610 Received: (qmail 29330 invoked from network); 15 Aug 2006 14:30:34 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Aug 2006 14:30:34 -0000 Received: (qmail 79977 invoked from network); 15 Aug 2006 14:30:32 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 15 Aug 2006 14:30:30 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly15d.srv.mailcontrol.com (MailControl) with ESMTP id k7FEUHVc013418 for ; Tue, 15 Aug 2006 15:30:18 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 15 Aug 2006 15:30:18 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.4/8.13.4) with ESMTP id k7FEUIuO017186 for ; Tue, 15 Aug 2006 15:30:18 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.4/8.13.4/Submit) with ESMTP id k7FEUENP017182 for ; Tue, 15 Aug 2006 15:30:18 +0100 Message-Id: <200608151430.k7FEUENP017182@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: zstyle -L with arguments Date: Tue, 15 Aug 2006 15:30:14 +0100 From: Peter Stephenson X-OriginalArrivalTime: 15 Aug 2006 14:30:18.0322 (UTC) FILETIME=[54D05B20:01C6C077] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-04-01 (www.mailcontrol.com) on 10.68.0.125 I finally got fed up with having to use grep to get the values of styles when I ran across one with a multiple-line "eval"-style argument. The way the first argument of zstyle is a pattern and the second argument a style name seems pretty much inevitable, but it's a bit clumsy that the pattern has to match a string that's itself going to be tested as a pattern. The alternative would be to it the other way around and output styles that match in a given context, making the test the same as for normal style lookup; however, I don't think that's actually as useful for listing. It makes it hard to list every context in which a style is set, for example, which is a natural thing to want to do. Probably _zstyle needs tweaking but I haven't looked at it. Index: Doc/Zsh/mod_zutil.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_zutil.yo,v retrieving revision 1.17 diff -u -r1.17 mod_zutil.yo --- Doc/Zsh/mod_zutil.yo 24 Apr 2005 18:38:04 -0000 1.17 +++ Doc/Zsh/mod_zutil.yo 15 Aug 2006 14:18:44 -0000 @@ -7,7 +7,7 @@ startitem() findex(zstyle) -xitem(tt(zstyle) [ tt(-L) ]) +xitem(tt(zstyle) [ tt(-L) [ var(pattern) [ var(style) ] ] ]) xitem(tt(zstyle) [ tt(-e) | tt(-) | tt(-)tt(-) ] var(pattern) var(style) var(strings) ...) xitem(tt(zstyle -d) [ var(pattern) [ var(styles) ... ] ]) xitem(tt(zstyle -g) var(name) [ var(pattern) [ var(style) ] ]) @@ -31,8 +31,18 @@ `tt(*)'. The first form (without arguments) lists the definitions in the order -tt(zstyle) will test them. If the tt(-L) option is given, listing is -done in the form of calls to tt(zstyle). Forms with arguments: +tt(zstyle) will test them. + +If the tt(-L) option is given, listing is done in the form of calls to +tt(zstyle). The optional first argument is a pattern which will be matched +against the string supplied as the pattern for the context; note that +this means, for example, `tt(zstyle -L ":completion:*")' will +match any supplied pattern beginning `tt(:completion:)', not +just tt(":completion:*"): use tt(":completion:\*") to match that. +The optional second argument limits the output to a specific style (not a +pattern). tt(-L) is not compatible with any other options. + +The other forms are the following: startitem() item(tt(zstyle) [ tt(-) | tt(-)tt(-) | tt(-e) ] var(pattern) var(style) var(strings) ...)( Index: Src/Modules/zutil.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/zutil.c,v retrieving revision 1.17 diff -u -r1.17 zutil.c --- Src/Modules/zutil.c 30 May 2006 22:35:03 -0000 1.17 +++ Src/Modules/zutil.c 15 Aug 2006 14:18:52 -0000 @@ -268,9 +268,10 @@ zwarnnam(nam, "invalid argument: %s", args[0]); return 1; } - if (oc == 'L') + if (oc == 'L') { list = 2; - else if (oc == 'e') { + args++; + } else if (oc == 'e') { eval = add = 1; args++; } @@ -305,13 +306,44 @@ Style s; Stypat p; char **v; + char *context, *stylename; + Patprog contprog; + + switch (arrlen(args)) { + case 2: + context = args[0]; + stylename = args[1]; + break; + + case 1: + context = args[0]; + stylename = NULL; + break; + + case 0: + context = stylename = NULL; + break; + + default: + zwarnnam(nam, "too many arguments"); + return 1; + } + if (context) { + tokenize(context); + contprog = patcompile(context, PAT_STATIC, NULL); + } else + contprog = NULL; for (s = zstyles; s; s = s->next) { if (list == 1) { quotedzputs(s->name, stdout); putchar('\n'); } + if (stylename && strcmp(s->name, stylename) != 0) + continue; for (p = s->pats; p; p = p->next) { + if (contprog && !pattry(contprog, p->pat)) + continue; if (list == 1) printf("%s %s", (p->eval ? "(eval)" : " "), p->pat); else { -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php