zsh-workers
 help / color / mirror / code / Atom feed
* Completion on =
@ 1995-07-19  7:35 Zefram
  1995-07-19 18:32 ` Zoltan Hidvegi
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1995-07-19  7:35 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

The patch below fixes a couple of problems with filename completion on
~ and =.  Previously these characters were treated specially for
completion even if quoted.  Also, completion on = did not include
aliases, which are actually subject to = substitution.

Can someone tell me why

% echo =<TAB>

takes a good minute or so (here) to ask me if I want to see a list of
3000 matches, but

% compctl -Dx 's[@]' -ca -- + -f
% echo @<TAB>

takes under two seconds?

 -zefram

      *** 1.2	1995/07/19 06:24:40
      --- zle_tricky.c	1995/07/19 07:16:24
      ***************
      *** 1406,1412 ****
            /* addwhat: -5 is for files, -6 is for glob expansions, -8 is for
               executable files (e.g. command paths), -7 is for command names (from
               cmdnamtab) and -1 is for other file specifications (things with
      !        `~' of `=' at the beginning, ...). */
            else if (addwhat == -1 || addwhat == -5 || addwhat == -6 ||
        	     addwhat == CC_FILES || addwhat == -7 || addwhat == -8) {
        	if (sl < fpl + fsl)
      --- 1406,1413 ----
            /* addwhat: -5 is for files, -6 is for glob expansions, -8 is for
               executable files (e.g. command paths), -7 is for command names (from
               cmdnamtab) and -1 is for other file specifications (things with
      !        `~' of `=' at the beginning, ...).  -3 is for executable command names.
      !     */
            else if (addwhat == -1 || addwhat == -5 || addwhat == -6 ||
        	     addwhat == CC_FILES || addwhat == -7 || addwhat == -8) {
        	if (sl < fpl + fsl)
      ***************
      *** 2357,2363 ****
            /* Do we have one of the special characters `~' and `=' at the
               beginning? */
            if ((ic = *s) != Tilde && ic != Equals)
      ! 	ic = (*s == '~' ? Tilde : (*s == '=' ? Equals : '\0'));
            /* Re-adjust the offs variable after all the changes we might have done
               to s, cs, and wb. */
            if ((offs = cs - wb) > (t = strlen(s)))
      --- 2358,2364 ----
            /* Do we have one of the special characters `~' and `=' at the
               beginning? */
            if ((ic = *s) != Tilde && ic != Equals)
      ! 	ic = 0;
            /* Re-adjust the offs variable after all the changes we might have done
               to s, cs, and wb. */
            if ((offs = cs - wb) > (t = strlen(s)))
      ***************
      *** 2473,2483 ****
            }
            lsuf = ztrdup(s + offs);
        
      !     /* First check for ~... and =.... */
      ! 
      !     if (ic) {
      ! 	/* It is one of these, so search backward to see if there is a slash.
      ! 	   If there is one, we have to do normal file completion. */
        	for (p = lpre + strlen(lpre); p > lpre; p--)
        	    if (*p == '/')
        		break;
      --- 2474,2481 ----
            }
            lsuf = ztrdup(s + offs);
        
      !     /* First check for ~.../... */
      !     if (ic == Tilde) {
        	for (p = lpre + strlen(lpre); p > lpre; p--)
        	    if (*p == '/')
        		break;
      ***************
      *** 2485,2492 ****
        	if (*p == '/')
        	    ic = 0;
            }
      -     /* Compute real prefix/suffix. */
        
            noreal = !*delit;
            for (p = lpre; *p && *p != String && *p != Tick; p++);
            tt = ic ? lpre + 1 : lpre;
      --- 2483,2490 ----
        	if (*p == '/')
        	    ic = 0;
            }
        
      +     /* Compute real prefix/suffix. */
            noreal = !*delit;
            for (p = lpre; *p && *p != String && *p != Tick; p++);
            tt = ic ? lpre + 1 : lpre;
      ***************
      *** 2605,2614 ****
        	    maketildelist();
        	else if (ic == Equals) {
        	    /* Completion after `=', get the command names from the
      ! 	       cmdnamtab. */
        	    if (isset(HASHLISTALL))
        		fullhash();
        	    dumphashtable(cmdnamtab, -7);
        	} else {
        	    /* Normal file completion... */
        	    if (ispattern & 1) {
      --- 2603,2613 ----
        	    maketildelist();
        	else if (ic == Equals) {
        	    /* Completion after `=', get the command names from the
      ! 	       cmdnamtab and aliases from aliastab. */
        	    if (isset(HASHLISTALL))
        		fullhash();
        	    dumphashtable(cmdnamtab, -7);
      + 	    dumphashtable(aliastab, -2);
        	} else {
        	    /* Normal file completion... */
        	    if (ispattern & 1) {
      ***************
      *** 2770,2776 ****
        	}
            }
            /* Use tricat() instead of dyncat() to get zalloc()'d memory. */
      !     if (ic == Tilde || ic == Equals) {
        	/* Now change the `~' and `=' tokens to the real characters
        	   so that things starting with these characters will be added. */
        	char *orpre = rpre;
      --- 2769,2775 ----
        	}
            }
            /* Use tricat() instead of dyncat() to get zalloc()'d memory. */
      !     if (ic) {
        	/* Now change the `~' and `=' tokens to the real characters
        	   so that things starting with these characters will be added. */
        	char *orpre = rpre;

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQBVAgUBMAy1UGWJ8JfKi+e9AQGeGQH/cmsTS5R6lu2R2PGLVoGD6Q5wELaJbves
RqlTIrDquSmjIE/uPpyDbbCMS1N440ATNsL7uteDKfDk44aUvaYq2w==
=xjiw
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Completion on =
  1995-07-19 18:32 ` Zoltan Hidvegi
@ 1995-07-19 17:56   ` Zefram
  0 siblings, 0 replies; 3+ messages in thread
From: Zefram @ 1995-07-19 17:56 UTC (permalink / raw)
  To: Z Shell workers mailing list

>Zefram wrote:
>
>> The patch below fixes a couple of problems with filename completion on
>> ~ and =.  Previously these characters were treated specially for
>> completion even if quoted.
>
>I did not test your changes yet, but I'm almost sure that they are not
>correct.

I did test it.  In the cases of

% echo =<TAB>
% echo \=<TAB>
% echo ~<TAB>
% echo \~<TAB>
% echo =a<TAB>
% echo \=a<TAB>
% echo ~a<TAB>
% echo \~a<TAB>

it gave correct results.  Under what circumstances do you think it will
fail?

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Completion on =
  1995-07-19  7:35 Completion on = Zefram
@ 1995-07-19 18:32 ` Zoltan Hidvegi
  1995-07-19 17:56   ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Zoltan Hidvegi @ 1995-07-19 18:32 UTC (permalink / raw)
  To: zsh-workers

Zefram wrote:

> The patch below fixes a couple of problems with filename completion on
> ~ and =.  Previously these characters were treated specially for
> completion even if quoted.

I did not test your changes yet, but I'm almost sure that they are not
correct.  Look at the first occurrance of docompletion() in zle_tricky.c.  The
current word is untokenized just before this call except those thing which are
within ${...} parameter expansion.  For some reason I do not remember clearly,
this is necessary (I think filename completion doesn't work well without it).
I'm sure that Sven could explain the problem more clearly.  The most confusing
thing is that docompletion() sometimes called with the tokenized string.  If
you examine makecomplist() (used to be docompletion()) more carefuly, you'll
see, that tokens and simple characters are handled similarily. E.g.

            if (*b != '^' && *b != Hat &&
                *b != '=' && *b != Equals &&
                *b != '~' && *b != Tilde)

I'm working now to fix several problems related to quoted characters in
completion strings.  I fixed most of the bugs here, and I think this bug can
also be fixed. A quoted tilde or = is always preceeded by a backslash, so in
this case line[wb] == '\\'.  We can use that to decide wether the tilde or =
is quoted or not.  But I guess it may be problematic when completing things
like \~foo$bar<TAB> since in this case (if I remember right) wb points after
the $.

Bye,
  Zoltan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-07-19 18:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-07-19  7:35 Completion on = Zefram
1995-07-19 18:32 ` Zoltan Hidvegi
1995-07-19 17:56   ` Zefram

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).