Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Further completion fixes



The patch velow fixes several bugs:

1. Parameter completion did not work after an equals:

% echo =$V_<TAB>
% echo \= _

2. Expansion did not work in some cases. E.g.

% foo=
% echo ~/$foo+<TAB>   BEEEP

It should give

% echo ~/_

3. \~ and \= was treated as they were unquoted. Zefram tried to fix it in
article 241. He tested if the ~ or = was a token or a normal character.  I
wrote then that there is something wrong with this approach.  Now I remeber
the problem (I had a correspondence about that with Sven sometime in March and
it took me some time to recall the details).  So if the a line contains some
wildcards and expand-or-complete was requested, first an expansion is tried.
If it doesn't change the line (no match) then completion is tried but now the
wildcard are treated as normal characters.  For that the parsed word is
untokenized before calling docompletion(). But this method did not really
worked for ~ and =.  After this patch leading ~ and = is not untokenized.
This allowed me to include the second hunk of Zefram's patch in article
241. After my patch the whole patch from Zefram can be applied ignoring the
rejected patch near line 2363.

4. GLOB_COMPLETE did not work in some cases properly:

% zsh -f 
% setopt autolist globcomplete 
% echo ~/$Z*<TAB>
% echo ~/$ARGC
zsh: do you wish to see all 101 possibilities? 

Some parts of the patch are not strictly bugfixes only cleanups.

The patch depends on my previous patch in article 250. It applies to the hzoli
releases only. For normal beta10 releases it can be merged by hand. The
rejection is in doexpansion. In my releases the postfork call is replaced by
an if (...) globlist(vl); and that's the reason for the rejection.  I'll try
to make a patch for normal beta10 if I have time.

Bye,

   Zoltan

*** 1.30	1995/07/24 09:38:31
--- Src/zle_tricky.c	1995/07/24 10:16:46
***************
*** 611,620 ****
  			if (n == 1)
  			    lst = COMP_EXPAND;
  		    }
! 	    } else /* if (*q != Tilde) Why was this test here? */
  		do {
! 		    /* An equivalent check for words not starting with `~'.
! 		       First check if there is a parameter expresiion. */
  		    for (; *q && *q != String; q++);
  		    if (*q == String && q[1] != Inpar && q[1] != Inbrack) {
  			if (*++q == Inbrace) {
--- 611,620 ----
  			if (n == 1)
  			    lst = COMP_EXPAND;
  		    }
! 	    }
! 	    if (lst == COMP_EXPAND_COMPLETE)
  		do {
! 		    /* check if there is a parameter expresiion. */
  		    for (; *q && *q != String; q++);
  		    if (*q == String && q[1] != Inpar && q[1] != Inbrack) {
  			if (*++q == Inbrace) {
***************
*** 713,719 ****
  		cs = ocs;
  		errflag = 0;
  
! 		for (p = s; *p; p++)
  		    if (itok(*p))
  			if (*p != String && *p != Qstring)
  			    *p = ztokens[*p - Pound];
--- 713,722 ----
  		cs = ocs;
  		errflag = 0;
  
! 		p = s;
! 		if (*p == Tilde || *p == Equals)
! 		    p++;
! 		for (; *p; p++)
  		    if (itok(*p))
  			if (*p != String && *p != Qstring)
  			    *p = ztokens[*p - Pound];
***************
*** 1146,1163 ****
  {
      LinkList vl = newlinklist();
      char *ss;
-     int ng = opts[NULLGLOB];
  
-     opts[NULLGLOB] = OPT_SET;
-     lexsave();
-     s = dupstring(s);
      pushheap();
!     addlinknode(vl, s);
      prefork(vl, 0);
      if (errflag)
  	goto end;
!     if ((lst == COMP_LIST_EXPAND) || (lst == COMP_EXPAND))
  	globlist(vl);
      if (errflag)
  	goto end;
      if (empty(vl) || !*(char *)peekfirst(vl)) {
--- 1149,1168 ----
  {
      LinkList vl = newlinklist();
      char *ss;
  
      pushheap();
!     ss = dupstring(s);
!     addlinknode(vl, ss);
      prefork(vl, 0);
      if (errflag)
  	goto end;
!     if ((lst == COMP_LIST_EXPAND) || (lst == COMP_EXPAND)) {
! 	int ng = opts[NULLGLOB];
! 
! 	opts[NULLGLOB] = OPT_SET;
  	globlist(vl);
+ 	opts[NULLGLOB] = ng;
+     }
      if (errflag)
  	goto end;
      if (empty(vl) || !*(char *)peekfirst(vl)) {
***************
*** 1165,1171 ****
  	    feep();
  	goto end;
      }
!     if (peekfirst(vl) == (void *) s ||
  	       (!nextnode(firstnode(vl)) && *s == Tilde &&
  		(ss = dupstring(s), filesubstr(&ss, 0)) &&
  		!strcmp(ss, (char *)peekfirst(vl)))) {
--- 1170,1176 ----
  	    feep();
  	goto end;
      }
!     if (peekfirst(vl) == (void *) ss ||
  	       (!nextnode(firstnode(vl)) && *s == Tilde &&
  		(ss = dupstring(s), filesubstr(&ss, 0)) &&
  		!strcmp(ss, (char *)peekfirst(vl)))) {
***************
*** 1202,1210 ****
  	}
      }
    end:
-     opts[NULLGLOB] = ng;
      popheap();
-     lexrestore();
  }
  
  /* This is called from the lexer to give us word positions. */
--- 1207,1213 ----
***************
*** 2262,2279 ****
      }
      /* Do we have one of the special characters `~' and `=' at the
         beginning? */
!     switch (*s) {
!     case '~':
!     case Tilde:
! 	ic = Tilde;
! 	break;
!     case '=':
!     case Equals:
! 	ic = Equals;
! 	break;
!     default:
! 	ic = '\0';
!     }
  
      /* Check if we have to complete a parameter name... */
  
--- 2265,2272 ----
      }
      /* Do we have one of the special characters `~' and `=' at the
         beginning? */
!     if ((ic = *s) != Tilde && ic != Equals)
! 	ic = 0;
  
      /* Check if we have to complete a parameter name... */
  
***************
*** 2401,2407 ****
  
      noreal = !*delit;
      for (p = lpre; *p && *p != String && *p != Tick; p++);
!     tt = ic ? lpre + 1 : lpre;
      rpre = (*p || *lpre == Tilde || *lpre == Equals) ?
  	(noreal = 0, getreal(tt)) :
  	ztrdup(tt);
--- 2394,2400 ----
  
      noreal = !*delit;
      for (p = lpre; *p && *p != String && *p != Tick; p++);
!     tt = ic && !parampre ? lpre + 1 : lpre;
      rpre = (*p || *lpre == Tilde || *lpre == Equals) ?
  	(noreal = 0, getreal(tt)) :
  	ztrdup(tt);



Messages sorted by: Reverse Date, Date, Thread, Author