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

Re: -subscript- completion for assoc array



Peter Stephenson wrote:

> Is there some math mode behaviour still built into subscript completion?  I
> can't complete the -*- elements of _comps, although they are listed all
> right immediately after the [ and are entered OK with menu completion.
> 
> % $_comps[-def<TAB>
> 
> tries to complete variable names.  Significantly, it claims it's allowing
> two errors and the set I get is
> 
> fignore      hep_env_sh   perl5lib     testhash     vers         
> foo          keys         ret          texinputs    
> fpath        lf           sets         ufmt         
> 
> so I suspect the - has been chucked out at some point.  (Since you're
> wondering :-), the list consists of variables starting in f (delete two
> characters) or with e second (replace two characters) or with f second
> (delete one and transpose the other two).)

The patch below only makes the parameter name correctly handled.

The problem with the missing `-' is not handled, but I found the
reason for it (and am not sure how we should change it). The reason is 
that inside subscripts, match-mode parsing is done to get the string
to complete, which normally is a string of characters on which
`iident(c)' yields true. This is what one wants in math envs including 
normal subscripts. Hm, I have to leave now so I won't be able to send
a patch for this now (hance this mail). I'll think some more about
this, but if some of you have ideas, let me know.
Possibilities include: give the whole subscript string to the function 
(which is a bit ugly for normal subscripts), and let the C-code find
out what kind of parameter we have -- and let it report a new context
for assocs.

> I don't think it matters much, but I'm now using the slightly modified
> _subscript below.  (It does show I shouldn't get the variable names at all
> in this case and hence compstate[parameter] isn't set properly, either.)

I think this is reasonable (and it seems I didn't think when writing
that...), so the patch below also changes `_subscript'


Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Mon Mar 15 10:52:39 1999
+++ Src/Zle/zle_tricky.c	Mon Mar 15 16:43:38 1999
@@ -1322,18 +1322,17 @@
 	 * as being in math.                                              */
 	if (inwhat != IN_MATH) {
 	    int i = 0;
-	    char *nb = (iident(*s) ? s : s + 1), *ne = NULL;
+	    char *nnb = (iident(*s) ? s : s + 1), *nb = NULL, *ne = NULL;
 
 	    for (tt = s; ++tt < s + cs - wb;)
 		if (*tt == Inbrack) {
 		    i++;
+		    nb = nnb;
 		    ne = tt;
 		} else if (i && *tt == Outbrack)
 		    i--;
-		else if (!iident(*tt)) {
-		    nb = tt + 1;
-		    ne = NULL;
-		}
+		else if (!iident(*tt))
+		    nnb = tt + 1;
 	    if (i) {
 		inwhat = IN_MATH;
 		insubscr = 1;
diff -u oc/Base/_subscript Completion/Base/_subscript
--- oc/Base/_subscript	Mon Mar 15 10:08:48 1999
+++ Completion/Base/_subscript	Mon Mar 15 16:51:33 1999
@@ -1,10 +1,7 @@
 #defcomp -subscript-
 
-local ret=1
-
-_compalso -math- && ret=0
-
-[[ ${(Pt)${compstate[parameter]}} = assoc* ]] &&
-  compgen -k "( ${(kP)${compstate[parameter]}} )" && ret=0
-
-return ret
+if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
+  compgen -S ']' -k "( ${(kP)${compstate[parameter]}} )"
+else
+  _compalso -math-
+fi

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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