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

PATCH: fix brace completion



% mkdir 'a b c'; touch 'a b c'/{'a b c','d e f'}
% ls a\ b\ c/{<tab>
corrupts the command line into
% ls a\ b\ {c/
and the effect is worse the more backslashes there are. It seems like
this code should simply always use bp->qpos so there is no reason to
keep hasunqu around either.

For the compctl path, the curpos members need to be whatever they're
determined to be at the start by addwhat for the comparison with ppl and
psl, so just fix them at the end before add_match_data. Famous last words.

The quotename in get_comp_string fixes subsequent completions, eg
% ls a\ b\ c/{a\ b\ c,<tab>
---

I'll let this one cook a little longer, just to make sure it doesn't break anything,
(though the compctl path will certainly not get any coverage from me).

 Src/Zle/compcore.c   | 3 +--
 Src/Zle/compctl.c    | 7 +++++++
 Src/Zle/compmatch.c  | 2 --
 Src/Zle/compresult.c | 4 ++--
 Src/Zle/zle_tricky.c | 2 +-
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index d7cdd76f7e..465cfae1ae 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -83,7 +83,7 @@ mod_export int menuacc;
 /* Brace insertion stuff. */
 
 /**/
-int hasunqu, useqbr, brpcs, brscs;
+int useqbr, brpcs, brscs;
 
 /* Flags saying in what kind of string we are. */
 
@@ -307,7 +307,6 @@ do_completion(UNUSED(Hookdef dummy), Compldat dat)
     *compqstack = (instring == QT_NONE) ? QT_BACKSLASH : (char)instring;
     compqstack[1] = '\0';
 
-    hasunqu = 0;
     useline = (wouldinstab ? -1 : (lst != COMP_LIST_COMPLETE));
     useexact = isset(RECEXACT);
     zsfree(compexactstr);
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index acd4b04358..ce39db2113 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -2039,6 +2039,13 @@ addmatch(char *s, char *t)
     }
     if (!ms)
 	return;
+
+    /* when inserting braces on the command line, always use the quoted length */
+    for (bp = brbeg; bp; bp = bp->next)
+	bp->curpos = bp->qpos;
+    for (bp = brend; bp; bp = bp->next)
+	bp->curpos = bp->qpos;
+
     add_match_data(isalt, ms, s, lc, ipre, ripre, isuf, 
 		   (incompfunc ? dupstring(curcc->prefix) : curcc->prefix),
 		   prpre, 
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index a9e42e698b..7e04112945 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -1250,8 +1250,6 @@ comp_match(char *pfx, char *sfx, char *w, Patprog cp, Cline *clp, int qu,
 	} else
 	    *exact = !strcmp(pfx, w);
     }
-    if (!qu)
-	hasunqu = 1;
 
     return r;
 }
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 3a73a2dd9f..f7d74ec7ae 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -186,7 +186,7 @@ cline_str(Cline l, int ins, int *csp, LinkList posl)
 
 	if ((brp = brbeg)) {
 	    for (bp = brbeg; bp; bp = bp->next) {
-		bp->curpos = (hasunqu ? bp->pos : bp->qpos);
+		bp->curpos = bp->qpos;
 		olen -= strlen(bp->str);
 	    }
 	}
@@ -195,7 +195,7 @@ cline_str(Cline l, int ins, int *csp, LinkList posl)
 		olen -= strlen(bp->str);
 
 	    for (bp = brend; bp; bp = bp->next)
-		bp->curpos = olen - (hasunqu ? bp->pos : bp->qpos);
+		bp->curpos = olen - bp->qpos;
 	}
 	while (brp && !brp->curpos) {
 	    inststrlen(brp->str, 1, -1);
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 84ebaf1cd0..be93658bef 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -2205,7 +2205,7 @@ get_comp_string(void)
 		    char sav = *lastp;
 
 		    *lastp = '\0';
-		    untokenize(lastprebr = ztrdup(s));
+		    untokenize(lastprebr = ztrdup(quotename(s)));
 		    *lastp = sav;
 		}
 		if ((lastpostbr = ztrdup(firsts)))
-- 
2.38.1





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