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

Compctl fixes & a query



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

The patch below fixes a few problems with the compctl builtin, and
cleans up a couple of bits of the code.  It fixes the rather buggy
handling of the command "+", and allows command names to be preceded by
a single dash on the command line (useful for commands beginning with a
dash, and for "+").  It causes a warning message to be output if
command names are given in addition to one of -C, -D and -T, because
that doesn't work at the moment.  A warning is also printed if the
default completion is specified with a trailing + (meaning to use the
default completion), and the trailing + is ignored.  It fixes the minor
problem of an extra '' appearing at the end of the -C, -D and -T
completions when they are listed with -L.

The practcal upshot of all that is that compctl won't do anything silly
to compctls you don't intend to modify; won't silently lose bits of its
command line; can be told to set up completion for absolutely any
command name; and will have produce a fully accurate list if given the
- -L option.  It even handles cases like "compctl -C +" gracefully,
showing that command in the listing.  ("compctl + commnd" removes
command's compctl, making it a default completion.  "compctl -C +"
makes the command completion always use default completion.)

On a separate matter, does anyone ever use the numerical equals
expansion?  (That is, =1 expands to the directory at the top of the
stack, =2 to the next directory in the stack, etc.)  I find it rather
annoying, as some of the commands here begin with a digit, and =command
won't work on them with this feature.  I think that = expansion should
always be on command names.  I suggest that ~1, ~2 etc. be used
instead, as the ~ sequences are all (supposed to be) directories,
whereas the normal result of = expansion is a pathname or command.
Admittedly, having ~2 handled specially could cause problems if one has
done a few "hash -d" commands, but we already have ~+ and ~- handled
specially anyway.

 -zefram

      *** Src/builtin.c.old	Sun Jul 16 08:16:08 1995
      --- Src/builtin.c	Sun Jul 16 14:54:37 1995
      ***************
      *** 1660,1668 ****
        		printcompctl("", &cc_default);
         	    if (cclist & 8)
         		printcompctl("", &cc_first);
      ! 	} else if (*argv)
        	    /* assign the compctl to the commands given */
        	    compctl_process_cc(argv, cc);
        
        	/* remember flags for printing */
        	flags = cc->mask;
      --- 1660,1676 ----
        		printcompctl("", &cc_default);
         	    if (cclist & 8)
         		printcompctl("", &cc_first);
      ! 	} else if (*argv) {
      ! 	    /* Zefram 1995-07-16: I think this is needed on the grounds that
      ! 	    the -C, -D and -T flags don't combine successfully with command
      ! 	    names (or each other). */
      ! 	    if((cclist & 14) && *argv) {
      ! 		zwarnnam(name, "extraneous commands ignored", NULL, 0);
      ! 		*argv = NULL;
      ! 	    }
        	    /* assign the compctl to the commands given */
        	    compctl_process_cc(argv, cc);
      + 	}
        
        	/* remember flags for printing */
        	flags = cc->mask;
      ***************
      *** 1671,1677 ****
        	if (!*argv || (cclist & 1))
        	    freecompctl(cc);
            }
      !      if (!*argv && !(cclist & 14)) {
         	/* no commands and no -C, -T, or -D, so just list */
        	showflag = (cclist & 1) ? 0 : flags;
        	scanhashtable(compctltab, (HFunc) printcompctlp);
      --- 1679,1685 ----
        	if (!*argv || (cclist & 1))
        	    freecompctl(cc);
            }
      !     if (!*argv && !(cclist & 14)) {
         	/* no commands and no -C, -T, or -D, so just list */
        	showflag = (cclist & 1) ? 0 : flags;
        	scanhashtable(compctltab, (HFunc) printcompctlp);
      ***************
      *** 1699,1706 ****
            /* Handle `compctl + foo ...' specially:  turn it into
             * a default compctl by removing it from the hash table.
             */
      !     if (first && **argv == '+' && !(*argv)[1] &&
      ! 	*argv[1] != '-') {
        	freecompctl(cc);
         	cclist = 16;
        	return 0;
      --- 1707,1718 ----
            /* Handle `compctl + foo ...' specially:  turn it into
             * a default compctl by removing it from the hash table.
             */
      !     if (first && argv[0][0] == '+' && !argv[0][1] &&
      ! 	    !(argv[1] && argv[1][0] == '-' && argv[1][1])) {
      ! 	argv++;
      ! 	if(*argv && **argv == '-')
      ! 	    argv++;
      ! 	*av = argv;
        	freecompctl(cc);
         	cclist = 16;
        	return 0;
      ***************
      *** 1708,1719 ****
        
            memset((void *)&cct, 0, sizeof(cct));
        
      !     for (; !ready && *argv && **argv == '-';) {
        	/* Loop through the flags until we have no more:
        	 * those with arguments are not properly allocated yet,
        	 * we just hang on to the argument that was passed.
        	 */
      ! 	if (**argv == '-' && !(*argv)[1])
        	    *argv = "-+";
        	while (!ready && *++(*argv))
        	    switch (**argv) {
      --- 1720,1731 ----
        
            memset((void *)&cct, 0, sizeof(cct));
        
      !     for (; !ready && *argv && **argv == '-' && (argv[0][1] || !first);) {
        	/* Loop through the flags until we have no more:
        	 * those with arguments are not properly allocated yet,
        	 * we just hang on to the argument that was passed.
        	 */
      ! 	if (!(*argv)[1])
        	    *argv = "-+";
        	while (!ready && *++(*argv))
        	    switch (**argv) {
      ***************
      *** 1838,1844 ****
        		break;
        	    case 'P':
        		if (hx) {
      ! 		    zerrnam(name, "no prefix allowed in or'd (+) completion",
        			    NULL, 0);
        		    return 1;
        		}
      --- 1850,1856 ----
        		break;
        	    case 'P':
        		if (hx) {
      ! 		    zerrnam(name, "no prefix allowed in xor'd (+) completion",
        			    NULL, 0);
        		    return 1;
        		}
      ***************
      *** 1855,1861 ****
        		break;
        	    case 'S':
        		if (hx) {
      ! 		    zerrnam(name, "no suffix allowed in or'd (+) completion",
        			    NULL, 0);
        		    return 1;
        		}
      --- 1867,1873 ----
        		break;
        	    case 'S':
        		if (hx) {
      ! 		    zerrnam(name, "no suffix allowed in xor'd (+) completion",
        			    NULL, 0);
        		    return 1;
        		}
      ***************
      *** 2002,2008 ****
        	     */
        	    if (cc_assign(name, &cc, &cct, first && !hx))
        		return 1;
      - 
        	    hx = 1;
        	    ready = 0;
        
      --- 2014,2019 ----
      ***************
      *** 2010,2029 ****
        		(**argv == '-' && (!argv[0][1] ||
        				   (argv[0][1] == '-' && !argv[0][2])))) {
        		/* No argument to +, which means do default completion */
      ! 		if (isdef) {
      ! 		    zerrnam(name,
      ! 			    "recursive or'd default completions not allowed",
        			    NULL, 0);
      ! 		    return 1;
      ! 		}
      ! 		cc->xor = &cc_default;
      ! 		if (!*argv || **argv == '-') {
      ! 		    /* Nothing left after final + */
      ! 		    if (*argv)
      ! 			(*argv)--;
      ! 		    argv--;
      ! 		    ready = 1;
      ! 		}
        	    } else {
        		/* more flags follow:  prepare to loop again */
        		cc->xor = (Compctl) zcalloc(sizeof(*cc));
      --- 2021,2032 ----
        		(**argv == '-' && (!argv[0][1] ||
        				   (argv[0][1] == '-' && !argv[0][2])))) {
        		/* No argument to +, which means do default completion */
      ! 		if (isdef)
      ! 		    zwarnnam(name,
      ! 			    "recursive xor'd default completions not allowed",
        			    NULL, 0);
      ! 		else
      ! 		    cc->xor = &cc_default;
        	    } else {
        		/* more flags follow:  prepare to loop again */
        		cc->xor = (Compctl) zcalloc(sizeof(*cc));
      ***************
      *** 2032,2037 ****
      --- 2035,2042 ----
        	    }
        	}
            }
      +     if (!ready && *argv && **argv == '-')
      + 	argv++;
        
            /* assign the last set of flags we parsed */
            if (cc_assign(name, &cc, &cct, first && !hx))
      ***************
      *** 2042,2052 ****
            return 0;
        }
        
        /**/
        int
        get_xcompctl(char *name, char ***av, Compctl cc, int isdef)
        {
      -     /* Handle the -x ... -- part of compctl. */
            char **argv = *av, *t, *tt, sav;
            int n, l = 0, ready = 0;
            Compcond m, c, o;
      --- 2047,2058 ----
            return 0;
        }
        
      + /* Handle the -x ... -- part of compctl. */
      + 
        /**/
        int
        get_xcompctl(char *name, char ***av, Compctl cc, int isdef)
        {
            char **argv = *av, *t, *tt, sav;
            int n, l = 0, ready = 0;
            Compcond m, c, o;
      ***************
      *** 2468,2474 ****
        	    if ((flags & (CC_ALREG | CC_ALGLOB)) == (CC_ALREG | CC_ALGLOB))
        		putchar('a'), flags &= ~(CC_ALREG | CC_ALGLOB);
        	    while (*css) {
      ! 		if ((flags & 1) && (t & 1))
        		    putchar(*css);
        		css++;
        		flags >>= 1;
      --- 2474,2480 ----
        	    if ((flags & (CC_ALREG | CC_ALGLOB)) == (CC_ALREG | CC_ALGLOB))
        		putchar('a'), flags &= ~(CC_ALREG | CC_ALGLOB);
        	    while (*css) {
      ! 		if (flags & t & 1)
        		    putchar(*css);
        		css++;
        		flags >>= 1;
      ***************
      *** 2477,2486 ****
        	}
        	/* now flags with arguments */
        	flags = cc->mask;
      ! 	if (cc->keyvar) {
      ! 	    printf(" -k ");
      ! 	    printquoted(cc->keyvar);
      ! 	}
        	printif(cc->func, 'K');
        	printif(cc->explain, 'X');
        	printif(cc->prefix, 'P');
      --- 2483,2489 ----
        	}
        	/* now flags with arguments */
        	flags = cc->mask;
      ! 	printif(cc->keyvar, 'k');
        	printif(cc->func, 'K');
        	printif(cc->explain, 'X');
        	printif(cc->prefix, 'P');
      ***************
      *** 2555,2567 ****
        		printf(" --");
        	}
        	if (cc && cc->xor) {
      ! 	    /* print or'd (+) completions */
        	    printf(" +");
        	    if (cc->xor != &cc_default)
        		printcompctl((char *) NULL, cc->xor);
        	}
        	if (s) {
      ! 	    if (cclist & 1) {
        		putchar(' ');
        		printquoted(s);
        	    }
      --- 2558,2573 ----
        		printf(" --");
        	}
        	if (cc && cc->xor) {
      ! 	    /* print xor'd (+) completions */
        	    printf(" +");
        	    if (cc->xor != &cc_default)
        		printcompctl((char *) NULL, cc->xor);
        	}
        	if (s) {
      ! 	    if ((cclist & 1) && cc != &cc_compos &&
      ! 		    cc != &cc_default && cc != &cc_first) {
      ! 		if(s[0] == '-' || (s[0] == '+' && !s[1]))
      ! 		    printf(" -");
        		putchar(' ');
        		printquoted(s);
        	    }

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

iQBVAgUBMAkjMmWJ8JfKi+e9AQEJUQH9GU/lZTMaBR1VlnHissyFo7hMFHbZTY5A
xibbLzpTZ8Ya5w8ceminhP0Qi6EQv9hJqGzcp787f7hWv/2C9pXmNQ==
=w+az
-----END PGP SIGNATURE-----



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