From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12477 invoked from network); 28 Mar 2007 21:26:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.8 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 28 Mar 2007 21:26:44 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 11119 invoked from network); 28 Mar 2007 21:26:38 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 Mar 2007 21:26:38 -0000 Received: (qmail 20943 invoked by alias); 28 Mar 2007 21:26:35 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23246 Received: (qmail 20933 invoked from network); 28 Mar 2007 21:26:34 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 28 Mar 2007 21:26:34 -0000 Received: (qmail 10769 invoked from network); 28 Mar 2007 21:26:34 -0000 Received: from mtaout01-winn.ispmail.ntl.com (81.103.221.47) by a.mx.sunsite.dk with SMTP; 28 Mar 2007 21:26:31 -0000 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com with ESMTP id <20070328212628.JIVA2951.mtaout01-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Wed, 28 Mar 2007 22:26:28 +0100 Received: from pwslaptop.csr.com ([81.107.47.85]) by aamtaout02-winn.ispmail.ntl.com with SMTP id <20070328212628.BFAF17393.aamtaout02-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Wed, 28 Mar 2007 22:26:28 +0100 Date: Wed, 28 Mar 2007 22:25:25 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: completion after < at the start of the line Message-Id: <20070328222525.e4cf0654.p.w.stephenson@ntlworld.com> In-Reply-To: <20070328152955.8a64af07.pws@csr.com> References: <20070327213726.GF4885@sc.homeunix.net> <20070328152955.8a64af07.pws@csr.com> X-Mailer: Sylpheed version 2.2.10 (GTK+ 2.10.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Peter Stephenson wrote: > Stephane Chazelas wrote: >> $ mkdir 1 >> $ cd 1 >> $ touch foo bar >> $ zsh -f >> sc% < b foo >> >> (That is type "< b foo" move the cursor back to 4rd character, >> then type ) >> >> Then zsh completes that to: >> >> sc% < foo foo >> >> (instead of expected < bar foo). > > An alternative strategy is to record redirections before the command word, > but I'd rather understand what's there at present than bolt something new > on regardless. I've gone for this strategy. I thought about it in the bath: the number of cases where you might need to reset the index because you've got a new command word is quite large and it would be nastier to try to detect them all than to work around the problem. The fix using a special index for initial redirections isn't particularly horrible by the standards of this code. I've been seeing something screwy to do with the complist module when trying this. It doesn't seem to be related; it happens with or without an initial redirection, but I happened to fall over it when testing this. I've been getting it with "ls --" with menu selection turned on. Index: Src/Zle/zle_tricky.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v retrieving revision 1.84 diff -u -r1.84 zle_tricky.c --- Src/Zle/zle_tricky.c 13 Feb 2007 21:54:41 -0000 1.84 +++ Src/Zle/zle_tricky.c 28 Mar 2007 21:17:34 -0000 @@ -1072,6 +1072,12 @@ * still use zlemetacs. */ int qsub, zlemetacs_qsub = 0; + /* + * redirpos is used to record string arguments for redirection + * when they occur at the start of the line. In this case + * the command word is not at index zero in the array. + */ + int redirpos; char *s = NULL, *tmp, *p, *tt = NULL, rdop[20]; char *linptr, *u; @@ -1130,7 +1136,7 @@ lexsave(); inpush(dupstrspace(linptr), 0, NULL); strinbeg(0); - i = tt0 = cp = rd = ins = oins = linarr = parct = ia = 0; + i = tt0 = cp = rd = ins = oins = linarr = parct = ia = redirpos = 0; /* This loop is possibly the wrong way to do this. It goes through * * the previously massaged command line using the lexer. It stores * @@ -1186,6 +1192,9 @@ else strcpy(rdop, tokstrings[tok]); strcpy(rdstr, rdop); + /* Record if we haven't had the command word yet */ + if (i == redirpos) + redirpos++; } if (tok == DINPAR) tokstr = NULL; @@ -1204,7 +1213,7 @@ if (tt) break; /* Otherwise reset the variables we are collecting data in. */ - i = tt0 = cp = rd = ins = 0; + i = tt0 = cp = rd = ins = redirpos = 0; } if (lincmd && (tok == STRING || tok == FOR || tok == FOREACH || tok == SELECT || tok == REPEAT || tok == CASE)) { @@ -1213,7 +1222,9 @@ ins = (tok == REPEAT ? 2 : (tok != STRING)); zsfree(cmdstr); cmdstr = ztrdup(tokstr); - i = 0; + /* If everything before is a redirection, don't reset the index */ + if (i != redirpos) + i = redirpos = 0; } if (!zleparse && !tt0) { /* This is done when the lexer reached the word the cursor is on. */ @@ -1399,9 +1410,9 @@ * foo[_ wrong (note no $). If we are in a subscript, treat it * * as being in math. */ if (inwhat != IN_MATH) { - int i = 0; char *nnb, *nb = NULL, *ne = NULL; + i = 0; MB_METACHARINIT(); if (itype_end(s, IIDENT, 1) == s) nnb = s + MB_METACHARLEN(s); -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/