From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15405 invoked from network); 2 Nov 2005 11:07:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 2 Nov 2005 11:07:20 -0000 Received: (qmail 13873 invoked from network); 2 Nov 2005 11:07:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 2 Nov 2005 11:07:12 -0000 Received: (qmail 4573 invoked by alias); 2 Nov 2005 11:07:05 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9610 Received: (qmail 4564 invoked from network); 2 Nov 2005 11:07:05 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 2 Nov 2005 11:07:05 -0000 Received: (qmail 12841 invoked from network); 2 Nov 2005 11:07:05 -0000 Received: from cluster-c.mailcontrol.com (HELO rly07c.srv.mailcontrol.com) (168.143.177.190) by a.mx.sunsite.dk with SMTP; 2 Nov 2005 11:07:03 -0000 Received: from exchange03.csr.com (mailhost1.csr.com [81.105.217.43]) by rly07c.srv.mailcontrol.com (MailControl) with ESMTP id jA2B70Ib001711 for ; Wed, 2 Nov 2005 11:07:00 GMT Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 2 Nov 2005 11:09:25 +0000 Date: Wed, 2 Nov 2005 11:06:59 +0000 From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: copy-prev-word doesn't respect universal argument Message-Id: <20051102110659.0ce2c2b0.pws@csr.com> In-Reply-To: References: Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 02 Nov 2005 11:09:25.0026 (UTC) FILETIME=[E258D820:01C5DF9D] X-Scanned-By: MailControl A-05-40-01 (www.mailcontrol.com) on 10.67.0.117 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Vin Shelton wrote: > Why don't copy-prev-word and copy-prev-shell-word respect the > universal argument? > > Given the following: > > bindkey '^XA' copy-prev-word > echo abc def ghi 2^XA > > I would expect the result to be > > echo abc def ghi def > > but zle seems always to copy the most recent word, ('ghi' in this > case), yielding: > > echo abc def ghi ghi > > no matter what the prefix arg is. I'm surprised I'm the first person > to request this. I think it's just a question of "when are you going to get around to putting up those shelves". I didn't bother handling negative prefix arguments. Once, I would have been more zealous. > Is there an alternate way to copy an arbitrary word > from earlier in the same command, or is the !#: syntax sufficient > for most people? Actually, there is: see the supplied function copy-earlier-word which can cycle through earlier words in the same way as insert-last-word cycles back through the history. In fact, copy-earlier-word works in combination with insert-last-word so that you can copy earlier words on previous command lines, too. Note, however, that the sense of the digit argument is different; N copies the Nth word from the start of the line. I'm not sure why I did it that way (and althought it's correctly documented it disagrees with a comment in the function). Index: Src/Zle/zle_misc.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v retrieving revision 1.32 diff -u -r1.32 zle_misc.c --- Src/Zle/zle_misc.c 2 Nov 2005 10:11:33 -0000 1.32 +++ Src/Zle/zle_misc.c 2 Nov 2005 10:51:51 -0000 @@ -616,17 +616,28 @@ int copyprevword(UNUSED(char **args)) { - int len, t0; + int len, t0 = zlecs, t1; - for (t0 = zlecs - 1; t0 >= 0; t0--) - if (ZC_iword(zleline[t0])) - break; - for (; t0 >= 0; t0--) - if (!ZC_iword(zleline[t0])) - break; - if (t0) - t0++; - len = zlecs - t0; + if (zmult > 0) { + int count = zmult; + + for (;;) { + t1 = t0; + + while (t0 && !ZC_iword(zleline[t0-1])) + t0--; + while (t0 && ZC_iword(zleline[t0-1])) + t0--; + + if (!--count) + break; + if (t0 == 0) + return 1; + } + } + else + return 1; + len = t1 - t0; spaceinline(len); ZS_memcpy(zleline + zlecs, zleline + t0, len); zlecs += len; @@ -642,12 +653,19 @@ int i; unsigned char *p = NULL; - if ((l = bufferwords(NULL, NULL, &i))) + if (zmult <= 0) + return 1; + + if ((l = bufferwords(NULL, NULL, &i))) { + i -= (zmult-1); + if (i < 0) + return 1; for (n = firstnode(l); n; incnode(n)) if (!i--) { p = (unsigned char *)getdata(n); break; } + } if (p) { int len; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com