zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: completion after < at the start of the line
Date: Wed, 28 Mar 2007 22:25:25 +0100	[thread overview]
Message-ID: <20070328222525.e4cf0654.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <20070328152955.8a64af07.pws@csr.com>

Peter Stephenson <pws@csr.com> wrote:
> Stephane Chazelas <Stephane_Chazelas@yahoo.fr> wrote:
>> $ mkdir 1
>> $ cd 1
>> $ touch foo bar
>> $ zsh -f
>> sc% < b<TAB> foo
>> 
>> (That is type "< b foo" move the cursor back to 4rd character,
>> then type <Tab>)
>> 
>> 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 --<TAB>" 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2007-03-28 21:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-27 21:37 Stephane Chazelas
2007-03-28 14:29 ` Peter Stephenson
2007-03-28 21:25   ` Peter Stephenson [this message]
2007-03-29 21:25     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070328222525.e4cf0654.p.w.stephenson@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).