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

Re: Global aliases, eval, and completion (Re: Expanding interactively aliases)



Bart Schaefer wrote:

> I was just diffing some backup copies I'd made of things like minor changes
> to _arguments against the current sources, and I found the solution I think
> you're thinking about.
> 
> } [...] _arguments does things like
> } 
> } 	eval ws\=\( "${action[2,-2]}" \)
> } and
> } 	eval "action=( $action )"
> } 
> } There are a number of other completion functions that use eval for similar
> } purposes.
> 
> We can replace all `eval's of that particular form with
> 
> 	set -A ws ${=~action[2,-2]}
> or
> 	set -A action ${=~action}

Ah, yes, that's what I wanted to remember...

> etc., which also gives us liberty to remove the wordsplitting or globbing
> when appropriate (I think wordsplitting always is, but globbing might better
> be left off in a few cases).

Hmhm. Haven't looked through the completion functions yet, but below
is a patch to replace the (internal) `noaliases' with an option `ALIAS'.
Should I commit that? Should it (in options.c) use (OPT_ALL & ~OPT_SH) 
instead of OPT_ALL?


Bye
 Sven

Index: Completion/Core/compinit
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/compinit,v
retrieving revision 1.16
diff -u -r1.16 compinit
--- Completion/Core/compinit	2001/02/16 14:57:50	1.16
+++ Completion/Core/compinit	2001/02/27 10:05:37
@@ -137,6 +137,7 @@
     NO_ksharrays
     NO_cshnullglob
     NO_allexport
+    NO_alias
 )
 
 # These can hold names of functions that are to be called before/after all
Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.13
diff -u -r1.13 options.yo
--- Doc/Zsh/options.yo	2001/02/14 17:58:13	1.13
+++ Doc/Zsh/options.yo	2001/02/27 10:05:39
@@ -53,6 +53,11 @@
 are changed from the default.
 
 startitem()
+pindex(ALIAS)
+cindex(alias, expansion)
+item(tt(ALIAS) <D>)(
+Expand aliases.
+)
 pindex(ALL_EXPORT)
 cindex(export, automatic)
 item(tt(ALL_EXPORT) (tt(-a), ksh: tt(-a)))(
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.24
diff -u -r1.24 exec.c
--- Src/exec.c	2001/01/16 13:44:20	1.24
+++ Src/exec.c	2001/02/27 10:05:41
@@ -3224,14 +3224,14 @@
 Shfunc
 loadautofn(Shfunc shf, int fksh, int autol)
 {
-    int noalias = noaliases, ksh = 1;
+    int noalias = opts[ALIASOPT], ksh = 1;
     Eprog prog;
 
     pushheap();
 
-    noaliases = (shf->flags & PM_UNALIASED);
+    opts[ALIASOPT] = !(shf->flags & PM_UNALIASED);
     prog = getfpfunc(shf->nam, &ksh);
-    noaliases = noalias;
+    opts[ALIASOPT] = noalias;
 
     if (ksh == 1)
 	ksh = fksh;
Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.23
diff -u -r1.23 hist.c
--- Src/hist.c	2001/02/26 09:43:08	1.23
+++ Src/hist.c	2001/02/27 10:05:42
@@ -2151,7 +2151,7 @@
 {
     int num = 0, cur = -1, got = 0, ne = noerrs, ocs = cs, oll = ll;
     int owb = wb, owe = we, oadx = addedx, ozp = zleparse, onc = nocomments;
-    int ona = noaliases;
+    int ona = opts[ALIASOPT];
     char *p;
 
     if (!list)
@@ -2190,7 +2190,7 @@
     if (cs)
 	cs--;
     strinbeg(0);
-    noaliases = 1;
+    opts[ALIASOPT] = 0;
     do {
 	if (incond)
 	    incond = 1 + (tok != DINBRACK && tok != INPAR &&
@@ -2227,7 +2227,7 @@
     }
     if (cur < 0 && num)
 	cur = num - 1;
-    noaliases = ona;
+    opts[ALIASOPT] = ona;
     strinend();
     inpop();
     errflag = 0;
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.14
diff -u -r1.14 lex.c
--- Src/lex.c	2000/12/05 10:34:23	1.14
+++ Src/lex.c	2001/02/27 10:05:42
@@ -98,11 +98,6 @@
 /**/
 mod_export int wb, we;
 
-/* 1 if aliases should not be expanded */
- 
-/**/
-mod_export int noaliases;
-
 /* we are parsing a line sent to use by the editor */
  
 /**/
@@ -1556,8 +1551,8 @@
 
 	if (tok == STRING) {
 	    /* Check for an alias */
-	    an = noaliases ? NULL :
-		(Alias) aliastab->getnode(aliastab, yytext);
+	    an = opts[ALIASOPT] ?
+		(Alias) aliastab->getnode(aliastab, yytext) : NULL;
 	    if (an && !an->inuse && ((an->flags & ALIAS_GLOBAL) || incmdpos ||
 				     inalmore)) {
 		inpush(an->text, INP_ALIAS, an);
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.6
diff -u -r1.6 options.c
--- Src/options.c	2000/08/10 16:19:12	1.6
+++ Src/options.c	2001/02/27 10:05:42
@@ -69,6 +69,7 @@
  * to avoid formatting problems.
  */
 static struct optname optns[] = {
+{NULL, "alias",		      OPT_EMULATE|OPT_ALL,	 ALIASOPT},
 {NULL, "allexport",	      OPT_EMULATE,		 ALLEXPORT},
 {NULL, "alwayslastprompt",    OPT_ALL,			 ALWAYSLASTPROMPT},
 {NULL, "alwaystoend",	      0,			 ALWAYSTOEND},
Index: Src/parse.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/parse.c,v
retrieving revision 1.17
diff -u -r1.17 parse.c
--- Src/parse.c	2001/01/22 12:03:55	1.17
+++ Src/parse.c	2001/02/27 10:05:44
@@ -2523,7 +2523,7 @@
 static int
 build_dump(char *nam, char *dump, char **files, int ali, int map, int flags)
 {
-    int dfd, fd, hlen, tlen, flen, ona = noaliases;
+    int dfd, fd, hlen, tlen, flen, ona = opts[ALIASOPT];
     LinkList progs;
     char *file;
     Eprog prog;
@@ -2537,7 +2537,7 @@
 	return 1;
     }
     progs = newlinklist();
-    noaliases = ali;
+    opts[ALIASOPT] = !ali;
 
     for (hlen = FD_PRELEN, tlen = 0; *files; files++) {
 	if (!strcmp(*files, "-k")) {
@@ -2553,7 +2553,7 @@
 		close(fd);
 	    close(dfd);
 	    zwarnnam(nam, "can't open file: %s", *files, 0);
-	    noaliases = ona;
+	    opts[ALIASOPT] = ona;
 	    unlink(dump);
 	    return 1;
 	}
@@ -2565,7 +2565,7 @@
 	    close(dfd);
 	    zfree(file, flen);
 	    zwarnnam(nam, "can't read file: %s", *files, 0);
-	    noaliases = ona;
+	    opts[ALIASOPT] = ona;
 	    unlink(dump);
 	    return 1;
 	}
@@ -2577,7 +2577,7 @@
 	    close(dfd);
 	    zfree(file, flen);
 	    zwarnnam(nam, "can't read file: %s", *files, 0);
-	    noaliases = ona;
+	    opts[ALIASOPT] = ona;
 	    unlink(dump);
 	    return 1;
 	}
@@ -2595,7 +2595,7 @@
 	tlen += (prog->len - (prog->npats * sizeof(Patprog)) +
 		 sizeof(wordcode) - 1) / sizeof(wordcode);
     }
-    noaliases = ona;
+    opts[ALIASOPT] = ona;
 
     tlen = (tlen + hlen) * sizeof(wordcode);
 
@@ -2614,21 +2614,21 @@
     WCFunc wcf;
 
     if (shf->flags & PM_UNDEFINED) {
-	int ona = noaliases;
+	int ona = opts[ALIASOPT];
 
 	if (!(what & 2)) {
 	    zwarnnam(nam, "function is not loaded: %s", shf->nam, 0);
 	    return 1;
 	}
-	noaliases = (shf->flags & PM_UNALIASED);
+	opts[ALIASOPT] = !(shf->flags & PM_UNALIASED);
 	if (!(prog = getfpfunc(shf->nam, NULL)) || prog == &dummy_eprog) {
-	    noaliases = ona;
+	    opts[ALIASOPT] = ona;
 	    zwarnnam(nam, "can't load function: %s", shf->nam, 0);
 	    return 1;
 	}
 	if (prog->dump)
 	    prog = dupeprog(prog, 1);
-	noaliases = ona;
+	opts[ALIASOPT] = ona;
     } else {
 	if (!(what & 1)) {
 	    zwarnnam(nam, "function is already loaded: %s", shf->nam, 0);
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.24
diff -u -r1.24 zsh.h
--- Src/zsh.h	2000/12/05 10:34:23	1.24
+++ Src/zsh.h	2001/02/27 10:05:45
@@ -1305,6 +1305,7 @@
 
 enum {
     OPT_INVALID,
+    ALIASOPT,
     ALLEXPORT,
     ALWAYSLASTPROMPT,
     ALWAYSTOEND,
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.44
diff -u -r1.44 compcore.c
--- Src/Zle/compcore.c	2001/01/18 14:41:40	1.44
+++ Src/Zle/compcore.c	2001/02/27 10:05:46
@@ -1237,7 +1237,7 @@
     LinkNode n;
     int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
     int tl, got = 0, i = 0, cur = -1, oll = ll, sl, remq;
-    int ois = instring, oib = inbackt, noffs = lp;
+    int ois = instring, oib = inbackt, noffs = lp, ona = opts[ALIASOPT];
     char *tmp, *p, *ns, *ol = (char *) line, sav, *qp, *qs, *ts, qc = '\0';
 
     s += lip;
@@ -1264,7 +1264,7 @@
     line = (unsigned char *) tmp;
     ll = tl - 1;
     strinbeg(0);
-    noaliases = 1;
+    opts[ALIASOPT] = 0;
     do {
 	ctxtlex();
 	if (tok == LEXERR) {
@@ -1299,7 +1299,7 @@
 	}
 	i++;
     } while (tok != ENDINPUT && tok != LEXERR);
-    noaliases = 0;
+    opts[ALIASOPT] = ona;
     strinend();
     inpop();
     errflag = zleparse = 0;
Index: Src/Zle/compctl.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compctl.c,v
retrieving revision 1.9
diff -u -r1.9 compctl.c
--- Src/Zle/compctl.c	2001/01/18 14:41:40	1.9
+++ Src/Zle/compctl.c	2001/02/27 10:05:48
@@ -2753,7 +2753,7 @@
     LinkNode n;
     int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
     int sl = strlen(ss), tl, got = 0, i = 0, cur = -1, oll = ll, remq;
-    int ois = instring, oib = inbackt;
+    int ois = instring, oib = inbackt, ona = opts[ALIASOPT];
     char *tmp, *p, *ns, *ol = (char *) line, sav, *oaq = autoq, *qp, *qs;
     char *ts, qc = '\0';
 
@@ -2778,7 +2778,7 @@
     line = (unsigned char *) tmp;
     ll = tl - 1;
     strinbeg(0);
-    noaliases = 1;
+    opts[ALIASOPT] = 0;
     do {
 	ctxtlex();
 	if (tok == LEXERR) {
@@ -2813,7 +2813,7 @@
 	}
 	i++;
     } while (tok != ENDINPUT && tok != LEXERR);
-    noaliases = 0;
+    opts[ALIASOPT] = ona;
     strinend();
     inpop();
     errflag = zleparse = 0;
@@ -3648,6 +3648,7 @@
 	LinkList foo = newlinklist();
 	LinkNode n;
 	int first = 1, ng = opts[NULLGLOB], oowe = we, oowb = wb;
+	int ona = opts[ALIASOPT];
 	char *tmpbuf;
 
 	opts[NULLGLOB] = 1;
@@ -3660,7 +3661,7 @@
 	sprintf(tmpbuf, "foo %s", cc->str); /* KLUDGE! */
 	inpush(tmpbuf, 0, NULL);
 	strinbeg(0);
-	noaliases = 1;
+	opts[ALIASOPT] = 0;
 	do {
 	    ctxtlex();
 	    if (tok == ENDINPUT || tok == LEXERR)
@@ -3669,7 +3670,7 @@
 		addlinknode(foo, ztrdup(tokstr));
 	    first = 0;
 	} while (tok != ENDINPUT && tok != LEXERR);
-	noaliases = 0;
+	opts[ALIASOPT] = ona;
 	strinend();
 	inpop();
 	errflag = zleparse = 0;
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.23
diff -u -r1.23 zle_tricky.c
--- Src/Zle/zle_tricky.c	2001/01/18 14:41:40	1.23
+++ Src/Zle/zle_tricky.c	2001/02/27 10:05:49
@@ -964,6 +964,7 @@
 get_comp_string(void)
 {
     int t0, tt0, i, j, k, cp, rd, sl, ocs, ins, oins, ia, parct, varq = 0;
+    int ona = opts[ALIASOPT];
     char *s = NULL, *linptr, *tmp, *p, *tt = NULL;
 
     freebrinfo(brbeg);
@@ -976,7 +977,7 @@
 
     /* This global flag is used to signal the lexer code if it should *
      * expand aliases or not.                                         */
-    noaliases = isset(COMPLETEALIASES);
+    opts[ALIASOPT] = !isset(COMPLETEALIASES);
 
     /* Find out if we are somewhere in a `string', i.e. inside '...', *
      * "...", `...`, or ((...)). Nowadays this is only used to find   *
@@ -1236,12 +1237,12 @@
 	    addedx = 0;
 	    goto start;
 	}
-	noaliases = 0;
+	opts[ALIASOPT] = ona;
 	lexrestore();
 	return NULL;
     }
 
-    noaliases = 0;
+    opts[ALIASOPT] = ona;
 
     /* Check if we are in an array subscript.  We simply assume that  *
      * we are in a subscript if we are in brackets.  Correct solution *
@@ -2138,7 +2139,7 @@
 doexpandhist(void)
 {
     unsigned char *ol;
-    int oll, ocs, ne = noerrs, err;
+    int oll, ocs, ne = noerrs, err, ona = opts[ALIASOPT];
 
     pushheap();
     metafy_line();
@@ -2152,7 +2153,7 @@
     /* We push ol as it will remain unchanged */
     inpush((char *) ol, 0, NULL);
     strinbeg(1);
-    noaliases = 1;
+    opts[ALIASOPT] = 0;
     noerrs = 1;
     exlast = inbufct;
     do {
@@ -2165,7 +2166,7 @@
      * means that the expanded string is unusable.                       */
     err = errflag;
     noerrs = ne;
-    noaliases = 0;
+    opts[ALIASOPT] = ona;
     strinend();
     inpop();
     zleparse = 0;
@@ -2282,12 +2283,12 @@
 int
 expandcmdpath(char **args)
 {
-    int oldcs = cs, na = noaliases;
+    int oldcs = cs, ona = opts[ALIASOPT];
     char *s, *str;
 
-    noaliases = 1;
+    opts[ALIASOPT] = 0;
     s = getcurcmd();
-    noaliases = na;
+    opts[ALIASOPT] = ona;
     if (!s || cmdwb < 0 || cmdwe < cmdwb)
 	return 1;
     str = findcmd(s, 1);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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