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

PATCH: brace stuff follow-up



Some smaller bugs fixed by this patch:

- with completeinword and closing braces, these somtimes weren't
  placed correctly because the information about the original length
  in the cline structs was sometimes wrong
- if an unambiguous string with at least one closing brace is
  inserted, the cursor should be left before that brace (I did that
  for do_single() and wanted to remember to do it for cline_str(),
  too, but then forgot to do so)
- the prefixes/suffixes used in `_path_files' were wrong in some
  cases, which could cause completeinword-behaviour to fail completely 
  and (and that's how I found it) the braces to be re-inserted in the
  wrong places


Bye
 Sven

diff -u oldsrc/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- oldsrc/Zle/zle_tricky.c	Wed Oct 20 15:27:22 1999
+++ Src/Zle/zle_tricky.c	Thu Oct 21 08:44:23 1999
@@ -3045,7 +3045,8 @@
 	    add_match_str(NULL, NULL, w + rpl, wl - rpl - rsl, 1);
 	    add_match_str(NULL, NULL, wpfx, wpl, 1);
 
-	    mli = bld_parts(w + rpl, wl - rpl - rsl, (mpl - rpl), &mlil);
+	    mli = bld_parts(w + rpl, wl - rpl - rsl,
+			    (mpl - rpl) + (msl - rsl), &mlil);
 	    mlil->flags |= CLF_MID;
 	    mlil->slen = msl - rsl;
 	    mlil->next = revert_cline(matchparts);
@@ -6846,10 +6847,11 @@
 	    if (brend) {
 		Brinfo bp;
 		char *p;
+		int bl;
 
 		for (bp = brend; bp; bp = bp->next) {
-		    p = lpsuf + (we - cs) - bp->qpos;
-		    strcpy(p, p + strlen(bp->str));
+		    p = lpsuf + (we - cs) - bp->qpos - (bl = strlen(bp->str));
+		    strcpy(p, p + bl);
 		}
 	    }
 	    if (!(lpsuf = strchr(lpsuf, '/')) && sf2)
@@ -8226,14 +8228,14 @@
 cline_str(Cline l, int ins, int *csp)
 {
     Cline s;
-    int ocs = cs, ncs, pcs, pm, pmax, pmm, sm, smax, smm, d, dm, mid;
-    int i, j, li = 0;
+    int ocs = cs, ncs, pcs, scs, pm, pmax, pmm, sm, smax, smm, d, dm, mid;
+    int i, j, li = 0, cbr;
     Brinfo brp, brs;
 
     l = cut_cline(l);
 
     pmm = smm = dm = 0;
-    pm = pmax = sm = smax = d = mid = -1;
+    pm = pmax = sm = smax = d = mid = cbr = -1;
 
     /* Get the information about the brace beginning and end we have
      * to re-insert. */
@@ -8259,6 +8261,8 @@
 	    brp = brp->next;
 	}
 	while (brs && !brs->curpos) {
+	    if (cbr < 0)
+		cbr = cs;
 	    inststrlen(brs->str, 1, -1);
 	    brs = brs->prev;
 	}
@@ -8277,6 +8281,8 @@
 		    inststrlen(s->line, 1, s->llen);
 		else
 		    inststrlen(s->word, 1, s->wlen);
+		scs = cs;
+
 		if ((s->flags & CLF_DIFF) && (!dm || (s->flags & CLF_MATCHED))) {
 		    d = cs; dm = s->flags & CLF_MATCHED;
 		}
@@ -8293,6 +8299,7 @@
 		inststrlen(brp->str, 1, bl);
 		cs = ocs + bl;
 		pcs += bl;
+		scs += bl;
 		brp = brp->next;
 	    }
 	}
@@ -8306,10 +8313,12 @@
 	if (ins) {
 	    int ocs, bl;
 
-	    while (brs && li > brs->curpos) {
+	    while (brs && li >= brs->curpos) {
 		ocs = cs;
 		bl = strlen(brs->str);
-		cs = pcs - (li - brs->curpos);
+		cs = scs - (li - brs->curpos);
+		if (cbr < 0)
+		    cbr = cs;
 		inststrlen(brs->str, 1, bl);
 		cs = ocs + bl;
 		pcs += bl;
@@ -8322,6 +8331,7 @@
 	    inststrlen(l->line, 1, l->llen);
 	else
 	    inststrlen(l->word, 1, l->wlen);
+	scs = cs;
 	if (ins) {
 	    int ocs, bl;
 
@@ -8334,6 +8344,7 @@
 		inststrlen(brp->str, 1, bl);
 		cs = ocs + bl;
 		pcs += bl;
+		scs += bl;
 		brp = brp->next;
 	    }
 	}
@@ -8354,7 +8365,9 @@
 	    while (brs && li >= brs->curpos) {
 		ocs = cs;
 		bl = strlen(brs->str);
-		cs = pcs + l->llen - (li - brs->curpos);
+		cs = scs - (li - brs->curpos);
+		if (cbr < 0)
+		    cbr = cs;
 		inststrlen(brs->str, 1, bl);
 		cs = ocs + bl;
 		pcs += bl;
@@ -8383,6 +8396,8 @@
 		    ocs = cs;
 		    bl = strlen(brs->str);
 		    cs = pcs + l->olen - (li - brs->curpos);
+		    if (cbr < 0)
+			cbr = cs;
 		    inststrlen(brs->str, 1, bl);
 		    cs = ocs + bl;
 		    pcs += bl;
@@ -8398,10 +8413,10 @@
 		pcs = cs;
 		if (s->flags & CLF_LINE) {
 		    inststrlen(s->line, 0, s->llen);
-		    i += s->llen; pcs = cs + s->llen;
+		    i += s->llen; scs = cs + s->llen;
 		} else {
 		    inststrlen(s->word, 0, s->wlen);
-		    i += s->wlen; pcs = cs + s->wlen;
+		    i += s->wlen; scs = cs + s->wlen;
 		}
 		if (ins) {
 		    int ocs, bl;
@@ -8411,16 +8426,19 @@
 		    while (brp && li >= brp->curpos) {
 			ocs = cs;
 			bl = strlen(brp->str);
-			cs = pcs - (li - brp->curpos);
+			cs = pcs + (li - brp->curpos);
 			inststrlen(brp->str, 1, bl);
 			cs = ocs + bl;
 			pcs += bl;
+			scs += bl;
 			brp = brp->next;
 		    }
 		    while (brs && li >= brs->curpos) {
 			ocs = cs;
 			bl = strlen(brs->str);
-			cs = pcs - (li - brs->curpos);
+			cs = scs - (li - brs->curpos);
+			if (cbr < 0)
+			    cbr = cs;
 			inststrlen(brs->str, 1, bl);
 			cs = ocs + bl;
 			pcs += bl;
@@ -8440,9 +8458,11 @@
 
 	for (; brp; brp = brp->next)
 	    inststrlen(brp->str, 1, -1);
-	for (; brs; brs = brs->prev)
+	for (; brs; brs = brs->prev) {
+	    if (cbr < 0)
+		cbr = cs;
 	    inststrlen(brs->str, 1, -1);
-
+	}
 	if (mid >= ocs)
 	    mid += cs - ocs;
 	if (pm >= ocs)
@@ -8456,7 +8476,9 @@
      * with missing characters, we take this, otherwise if we have a
      * prefix with missing characters, we take that, the same for a
      * suffix, and finally a place where the matches differ. */
-    ncs = (mid >= 0 ? mid : (pm >= 0 ? pm : (sm >= 0 ? sm : (d >= 0 ? d : cs))));
+    ncs = (cbr >= 0 ? cbr :
+	   (mid >= 0 ? mid :
+	    (pm >= 0 ? pm : (sm >= 0 ? sm : (d >= 0 ? d : cs)))));
 
     if (!ins) {
 	/* We always inserted the string in the line. If that was not
diff -u -r oldcompletion/Core/_path_files Completion/Core/_path_files
--- oldcompletion/Core/_path_files	Wed Oct 20 15:27:34 1999
+++ Completion/Core/_path_files	Thu Oct 21 08:45:36 1999
@@ -284,8 +284,8 @@
 	break;
       elif [[ "$haspats" = no && -z "$tpre$tsuf" &&
 	"$pre" = */ && -z "$suf" ]]; then
-	PREFIX="${opre}${osuf}"
-	SUFFIX=""
+	PREFIX="${opre}"
+	SUFFIX="${osuf}"
         compadd -nQS '' - "$linepath$donepath$orig"
         tmp4=-
       fi
@@ -312,13 +312,15 @@
   # The next loop searches the first ambiguous component.
 
   tmp3="$pre$suf"
+  tpre="$pre"
+  tsuf="$suf"
   tmp1=( "${(@)tmp1#${prepath}${realpath}${testpath}}" )
 
   while true; do
 
     # First we check if some of the files match the original string
     # for this component. If there are some we remove all other
-    # names. This avoid having `foo' complete to `foo' and `foobar'.
+    # names. This avoids having `foo' complete to `foo' and `foobar'.
 
     if [[ "$tmp3" = */* ]]; then
       tmp4=( "${(@M)tmp1:#${tmp3%%/*}/*}" )
@@ -344,12 +346,12 @@
       # collected as the suffixes to make the completion code expand
       # it as far as possible.
 
-      if [[ "$tmp3" = */* ]]; then
-        PREFIX="${donepath}${linepath}${cpre}${tmp3%%/*}"
-	SUFFIX="/${tmp3#*/}"
+      if [[ "$tsuf" = */* ]]; then
+        PREFIX="${donepath}${linepath}${cpre}${tpre%%/*}"
+	SUFFIX="/${tsuf#*/}"
       else
-        PREFIX="${donepath}${linepath}${cpre}${tmp3}"
-	SUFFIX=""
+        PREFIX="${donepath}${linepath}${cpre}${tpre}"
+	SUFFIX="${tsuf}"
       fi
 
       if [[ -n $menu || "$compconfig[path_expand]" != *suffix* ]]; then
@@ -402,13 +404,24 @@
     testpath="${testpath}${tmp1[1]%%/*}/"
     tmp1=( "${(@)tmp1#*/}" )
 
-    cpre="${cpre}${tmp3%%/*}/"
     tmp3="${tmp3#*/}"
+
+    if [[ "$tpre" = */* ]]; then
+      cpre="${cpre}${tpre%%/*}/"
+      tpre="${tpre#*/}"
+    elif [[ "$tsuf" = */* ]]; then
+      cpre="${cpre}${tpre}/"
+      tpre="${tsuf#*/}"
+      tsuf=""
+    else
+      tpre=""
+      tsuf=""
+    fi
   done
 
   if [[ -z "$tmp4" ]]; then
-    PREFIX="${opre}${osuf}"
-    SUFFIX=""
+    PREFIX="${opre}"
+    SUFFIX="${osuf}"
     compadd -Qf -p "$linepath${testpath:q}" \
 	    -W "$prepath$realpath$testpath" "$ignore[@]" \
 	    "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \
@@ -425,8 +438,8 @@
 
 if [[ "$compconfig[path_expand]" = *prefix* &&
       $#exppaths -gt 0 && nm -eq compstate[nmatches] ]]; then
-  PREFIX="${opre}${osuf}"
-  SUFFIX=""
+  PREFIX="${opre}"
+  SUFFIX="${osuf}"
   compadd -Q -S '' "$group[@]" "$expl[@]" \
           -M "r:|/=* r:|=* $match" -p "$linepath" - "$exppaths[@]"
 fi

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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