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

Re: If someone wants to try...



Peter Stephenson wrote:

> Sven Wischnowsky wrote:
> ...
> > And maybe we should try to avoid building values for arrays and hashes 
> > when completing their names (it's autoparamslash if I'm not completely 
> > mistaken). No patch for this yet.
> 
> Yes, something similar is going on with $mapfile which I noticed before,
> although maybe this is deeper in the parameter code: it always executes the
> special function to retrieve the value, even if you're about to assign to
> it.

In this case it really only was do_single() which called singsub() to
see if the word expanded to a directory name. The patch makes it test
if it's a simple parameter expansion (`$foo' or `${foo}', no flags, no 
subscripts) and if it is and the parameter is not a scalar, we don't
try to expand it.

Bye
 Sven

diff -ru ../z.old/Src/Zle/compresult.c Src/Zle/compresult.c
--- ../z.old/Src/Zle/compresult.c	Thu Jan 20 09:07:24 2000
+++ Src/Zle/compresult.c	Thu Jan 20 09:08:40 2000
@@ -785,19 +785,40 @@
 	    else {
 		/* Build the path name. */
 		if (partest && !*psuf && !(m->flags & CMF_PARNEST)) {
-		    int ne = noerrs;
+		    int ne = noerrs, tryit = 1;
 
 		    p = (char *) zhalloc(strlen((m->flags & CMF_ISPAR) ?
 						parpre : m->ripre) +
 					 strlen(str) + 2);
 		    sprintf(p, "%s%s%c",
 			    ((m->flags & CMF_ISPAR) ? parpre : m->ripre), str,
-			    ((m->flags & CMF_PARBR) ? Outbrace : '\0'));
-		    noerrs = 1;
-		    parsestr(p);
-		    singsub(&p);
-		    errflag = 0;
-		    noerrs = ne;
+			    ((m->flags & CMF_PARBR) ? '}' : '\0'));
+		    if (*p == '$') {
+			char *n;
+			Param pm;
+
+			if (p[1] == '{') {
+			    char *e;
+
+			    n = dupstring(p + 2);
+			    e = n + strlen(n) - 1;
+
+			    if (*e == '}')
+				*e = '\0';
+			} else
+			    n = p + 1;
+
+			if ((pm = (Param) paramtab->getnode(paramtab, n)) &&
+			    PM_TYPE(pm->flags) != PM_SCALAR)
+			    tryit = 0;
+		    }
+		    if (tryit) {
+			noerrs = 1;
+			parsestr(p);
+			singsub(&p);
+			errflag = 0;
+			noerrs = ne;
+		    }
 		} else {
 		    p = (char *) zhalloc(strlen(prpre) + strlen(str) +
 				 strlen(psuf) + 3);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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