about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-25 10:28:11 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-25 10:28:11 +0000
commit6623bb41b98142c24607790dc8311435d1c33257 (patch)
tree6a9ca6c9a47515acec91959747edad70e1d55f05
parentd49da606702363f0eb5615a341126c2dbe562849 (diff)
downloadzsh-6623bb41b98142c24607790dc8311435d1c33257.tar.gz
zsh-6623bb41b98142c24607790dc8311435d1c33257.tar.xz
zsh-6623bb41b98142c24607790dc8311435d1c33257.zip
report prefix/suffix of parameter expansion in IPREFIX/ISUFFIX; make _expand use them to be able to expand $foo (10909)
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Core/_expand12
-rw-r--r--Src/Zle/compcore.c31
-rw-r--r--Src/Zle/compresult.c2
4 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index af223d374..0e8c11cd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2000-04-25  Sven Wischnowsky  <wischnow@informatik.hu-berlin.de>
 
+	* 10909: Completion/Core/_expand, Src/Zle/compcore.c,
+ 	Src/Zle/compresult.c: report prefix/suffix of parameter expansion
+ 	in IPREFIX/ISUFFIX; make _expand use them to be able to expand $foo
+	
 	* 10908: Completion/Base/.distfiles, Completion/Base/_argument_sets,
  	Completion/Base/_arguments, Completion/Base/_describe,
  	Completion/Builtins/_bindkey, Completion/Builtins/_compdef,
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index 2557af884..1a96e654e 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -11,7 +11,13 @@ setopt localoptions nullglob
 
 [[ _matcher_num -gt 1 ]] && return 1
 
-local exp word="$PREFIX$SUFFIX" sort expr expl subd suf=" "
+local exp word sort expr expl subd suf=" "
+
+if [[ "$funcstack[2]" = _prefix ]]; then
+  word="$IPREFIX$PREFIX$SUFFIX"
+else
+  word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
+fi
 
 # First, see if we should insert all *completions*.
 
@@ -29,7 +35,7 @@ exp=("$word")
 # changes quoted spaces, tabs, and newlines into spaces.
 
 { zstyle -s ":completion:${curcontext}:" substitute expr ||
-  [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
+  { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( "${(e)exp//\\[ 	
 ]/ }" )
@@ -43,7 +49,7 @@ subd=("$exp[@]")
 # Now try globbing.
 
 { zstyle -s ":completion:${curcontext}:" glob expr ||
-  [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
+  { [[ "$curcontext" = expand-word:* ]] && expr=1 } } &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( ${~exp} )
 
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index d5dee0dca..0c989c427 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -492,6 +492,8 @@ after_complete(Hookdef dummy, Compldat dat)
 
 /* This calls the given completion widget function. */
 
+static int parwb, parwe, paroffs;
+
 /**/
 static void
 callcompfunc(char *s, char *fn)
@@ -637,9 +639,24 @@ callcompfunc(char *s, char *fn)
 	    compsuffix = ztrdup(ss);
 	}
 	zsfree(compiprefix);
-	compiprefix = ztrdup("");
 	zsfree(compisuffix);
-	compisuffix = ztrdup("");
+	if (parwb < 0) {
+	    compiprefix = ztrdup("");
+	    compisuffix = ztrdup("");
+	} else {
+	    int l;
+
+	    compiprefix = (char *) zalloc((l = wb - parwb) + 1);
+	    memcpy(compiprefix, line + parwb, l);
+	    compiprefix[l] = '\0';
+	    compisuffix = (char *) zalloc((l = parwe - we) + 1);
+	    memcpy(compisuffix, line + we, l);
+	    compisuffix[l] = '\0';
+
+	    wb = parwb;
+	    we = parwe;
+	    offs = paroffs;
+	}
 	zsfree(compqiprefix);
 	compqiprefix = ztrdup(qipre ? qipre : "");
 	zsfree(compqisuffix);
@@ -829,10 +846,16 @@ static int
 makecomplist(char *s, int incmd, int lst)
 {
     char *p;
+    int owb = wb, owe = we, ooffs = offs;
 
     /* Inside $... ? */
-    if (compfunc && (p = check_param(s, 0, 0)))
+    if (compfunc && (p = check_param(s, 0, 0))) {
 	s = p;
+	parwb = owb;
+	parwe = owe;
+	paroffs = ooffs;
+    } else
+	parwb = -1;
 
     linwhat = inwhat;
 
@@ -1073,7 +1096,7 @@ check_param(char *s, int set, int test)
 	    }
 	    /* Save the prefix. */
 	    if (compfunc) {
-		parflags = (br >= 2 ? CMF_PARBR : 0);
+		parflags = (br >= 2 ? CMF_PARBR | (nest ? CMF_PARNEST : 0) : 0);
 		sav = *b;
 		*b = '\0';
 		untokenize(parpre = ztrdup(s));
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 87e1f7278..3875987c5 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -1030,8 +1030,6 @@ accept_last(void)
 	else if (cs > ll)
 	    cs = ll;
 	inststrlen(" ", 1, 1);
-	if (parpre)
-	    inststr(parpre);
 	minfo.insc = minfo.len = 0;
 	minfo.pos = cs;
 	minfo.we = 1;