zsh-workers
 help / color / mirror / code / Atom feed
* Re: help with _match, globcomplete etc. (with a PATCH)
@ 2000-02-17 14:43 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-02-17 14:43 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> ...
> 
> > } zsh -f
> > } bindkey -me
> > } unsetopt glob
> > } typeset -A code
> > } code[ai]=foo
> > } echo $code[ai]/{a,<tab>
> > 
> > All I get from that is a beep, before Sven's 9749, and
> > 
> > zagzig% echo foo/\{a, 
> >                       ^note trailing space added
> > with 9749 applied.
> > 
> > Of course that seems wrong, too.  I didn't want the brace to be quoted.
> 
> As I said: I guess, this was intentional. If you have `a="foo bar"' or 
> the words from globbing contain special characters, you want them to
> be quoted. There may be a possibility to fix this by changing the
> tokenization stuff in doexpansion().

Hrmpff. I still think that things like these should be done in
shell-code widgets (likewise for the globbing-but-not-expansion
thing), but...

Part of the problem can be solved quite easily, by swapping the calls
to quotename() and untokenize() in doexpansion(). Unfortunately this
still doesn't give what you all want because glob() call untokenize()
itself (so the call in doexpansion() was superfluous). Hence this
patch -- *if* it will be accepted/wanted -- gives glob() and
globlist() an extra argument saying if it should untokenize or
not. And that only for this expand-word thing (or does anybody see
other uses for it?).

About the space: this was obviously intentional, too. I've just
changed the test in doexpansion() so we can go back easily if suddenly 
we decide the old behaviour was better. But what I would really like
to have is a better test: when do we want the space and when not.


One of the things I'd like to try after 3.2/4.0/whatever is to move
more stuff out of the zle module into separate modules (zle_vi, and so 
on), loaded on demand (we need a way to autoload modules due to
widgets being called then). That plus better support for shell-code
widgets.

Bye
 Sven

diff -ru ../z.old/Src/Zle/compctl.c Src/Zle/compctl.c
--- ../z.old/Src/Zle/compctl.c	Thu Feb 17 14:57:50 2000
+++ Src/Zle/compctl.c	Thu Feb 17 15:23:16 2000
@@ -2219,7 +2219,7 @@
 			    /* Do the globbing... */
 			    remnulargs(p);
 			    addlinknode(l, p);
-			    globlist(l);
+			    globlist(l, 0);
 			    /* And see if that produced a filename. */
 			    tt = nonempty(l);
 			    while (ugetnode(l));
@@ -3334,7 +3334,7 @@
 		tokenize(p);
 		remnulargs(p);
 		addlinknode(l, p);
-		globlist(l);
+		globlist(l, 0);
 
 		if (nonempty(l)) {
 		    /* And add the resulting words. */
@@ -3483,7 +3483,7 @@
 				/* Do the globbing. */
 				ng = opts[NULLGLOB];
 				opts[NULLGLOB] = 1;
-				globlist(l);
+				globlist(l, 0);
 				opts[NULLGLOB] = ng;
 				/* Get the results. */
 				if (nonempty(l) && peekfirst(l)) {
@@ -3679,7 +3679,7 @@
 	/* Fine, now do full expansion. */
 	prefork(foo, 0);
 	if (!errflag) {
-	    globlist(foo);
+	    globlist(foo, 0);
 	    if (!errflag)
 		/* And add the resulting words as matches. */
 		for (n = firstnode(foo); n; incnode(n))
diff -ru ../z.old/Src/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- ../z.old/Src/Zle/zle_tricky.c	Thu Feb 17 14:57:52 2000
+++ Src/Zle/zle_tricky.c	Thu Feb 17 15:37:59 2000
@@ -1612,11 +1612,11 @@
 	prefork(vl, 0);
 	if (errflag)
 	    goto end;
-	if ((lst == COMP_LIST_EXPAND) || (lst == COMP_EXPAND)) {
+	if (lst == COMP_LIST_EXPAND || lst == COMP_EXPAND) {
 	    int ng = opts[NULLGLOB];
 
 	    opts[NULLGLOB] = 1;
-	    globlist(vl);
+	    globlist(vl, 1);
 	    opts[NULLGLOB] = ng;
 	}
 	if (errflag)
@@ -1645,11 +1645,14 @@
 	foredel(we - wb);
 	while ((ss = (char *)ugetnode(vl))) {
 	    ret = 0;
-	    untokenize(ss);
 	    ss = quotename(ss, NULL);
+	    untokenize(ss);
 	    inststr(ss);
+#if 0
 	    if (olst != COMP_EXPAND_COMPLETE || nonempty(vl) ||
 		(cs && line[cs-1] != '/')) {
+#endif
+	    if (nonempty(vl)) {
 		spaceinline(1);
 		line[cs++] = ' ';
 	    }
diff -ru ../z.old/Src/exec.c Src/exec.c
--- ../z.old/Src/exec.c	Thu Feb 17 14:57:45 2000
+++ Src/exec.c	Thu Feb 17 15:22:48 2000
@@ -1419,7 +1419,7 @@
 		return;
 	    }
 	    if (isset(GLOBASSIGN) || !isstr)
-		globlist(vl);
+		globlist(vl, 0);
 	    if (errflag) {
 		state->pc = opc;
 		return;
@@ -1520,7 +1520,7 @@
 	prefork(strs, esprefork);
 	if (esglob) {
 	    LinkList ostrs = strs;
-	    globlist(strs);
+	    globlist(strs, 0);
 	    strs = ostrs;
 	}
     }
@@ -1644,7 +1644,7 @@
 	    if (!(cflags & BINF_NOGLOB))
 		while (!checked && !errflag && args && nonempty(args) &&
 		       has_token((char *) peekfirst(args)))
-		    glob(args, firstnode(args));
+		    glob(args, firstnode(args), 0);
 	    else if (!unglobbed) {
 		for (node = firstnode(args); node; incnode(node))
 		    untokenize((char *) getdata(node));
@@ -1927,7 +1927,7 @@
 
     if ((esglob = !(cflags & BINF_NOGLOB)) && args) {
 	LinkList oargs = args;
-	globlist(args);
+	globlist(args, 0);
 	args = oargs;
     }
     if (errflag) {
diff -ru ../z.old/Src/glob.c Src/glob.c
--- ../z.old/Src/glob.c	Thu Feb 17 14:57:45 2000
+++ Src/glob.c	Thu Feb 17 15:21:54 2000
@@ -872,7 +872,7 @@
 
 /**/
 void
-glob(LinkList list, LinkNode np)
+glob(LinkList list, LinkNode np, int nountok)
 {
     struct qual *qo, *qn, *ql;
     LinkNode node = prevnode(np);
@@ -887,7 +887,8 @@
 
     MUSTUSEHEAP("glob");
     if (unset(GLOBOPT) || !haswilds(ostr)) {
-	untokenize(ostr);
+	if (!nountok)
+	    untokenize(ostr);
 	return;
     }
     save_globstate(saved);
@@ -1339,7 +1340,8 @@
     if (!q || errflag) {	/* if parsing failed */
 	restore_globstate(saved);
 	if (unset(BADPATTERN)) {
-	    untokenize(ostr);
+	    if (!nountok)
+		untokenize(ostr);
 	    insertlinknode(list, node, ostr);
 	    return;
 	}
@@ -1578,7 +1580,7 @@
     prefork(fake, isset(MULTIOS) ? 0 : PF_SINGLE);
     /* Globbing is only done for multios. */
     if (!errflag && isset(MULTIOS))
-	globlist(fake);
+	globlist(fake, 0);
     if (errflag)
 	return 0;
     if (nonempty(fake) && !nextnode(firstnode(fake))) {
diff -ru ../z.old/Src/subst.c Src/subst.c
--- ../z.old/Src/subst.c	Thu Feb 17 14:57:48 2000
+++ Src/subst.c	Thu Feb 17 15:22:11 2000
@@ -212,14 +212,14 @@
 
 /**/
 mod_export void
-globlist(LinkList list)
+globlist(LinkList list, int nountok)
 {
     LinkNode node, next;
 
     badcshglob = 0;
     for (node = firstnode(list); !errflag && node; node = next) {
 	next = nextnode(node);
-	glob(list, node);
+	glob(list, node, nountok);
     }
     if (badcshglob == 1)
 	zerr("no match", NULL, 0);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
@ 2000-02-16 15:39 Sven Wischnowsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-02-16 15:39 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> } No. Seems like the (e) flag makes the thing be quoted as in double
> } quotes. I.e. with a='${~^arr}*', ${(e)a} gives `[sS] Src/M ../*', but
> } a='${(@)~^arr}' gives what we would have expected. The patch below
> } changes the calls to parsestr() to calls to parse_subst_string() to
> } get that. Hm, should we call that only conditionally, e.g. if the
> } ${(e)...} is not inquotes and has no (@) or something?
> 
> My first reaction would be to answer "yes," and a little fooling around
> with 9757 applied seems to bear it out:
> 
>  a='*'
>  print -l "${(e)a}"
> 
> Would you really expect to get one file name per line in that case?

First: no. Second: it shouldn't have done globbing -- that should
happen only with ${~...}.

So, next try: always use parsestr() but sometimes turn the `Qstring's
into `String's. This gives:

  % a=(a b) b='$a/'
  % print -l ${(e)b}
  a/
  b/
  % print -l "${(e)b}"
  a b/
  % print -l "${(e@)b}"
  a/
  b/

Which seems quite sensible, right?


Bye
 Sven

diff -ru ../z.old/Src/subst.c Src/subst.c
--- ../z.old/Src/subst.c	Wed Feb 16 12:40:05 2000
+++ Src/subst.c	Wed Feb 16 16:32:12 2000
@@ -694,6 +694,22 @@
     return ret < 0 ? -ret : ret;
 }
 
+/* Parsing for the (e) flag. */
+
+static int
+subst_parse_str(char *s, int single)
+{
+    if (!parsestr(s)) {
+	if (!single) {
+	    for (; *s; s++)
+		if (*s == Qstring)
+		    *s = String;
+	}
+	return 0;
+    }
+    return 1;
+}
+
 /* parameter substitution */
 
 #define	isstring(c) ((c) == '$' || (char)(c) == String || (char)(c) == Qstring)
@@ -1766,7 +1782,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && parse_subst_string(x))
+		if (eval && subst_parse_str(x, (qt && !nojoin)))
 		    return NULL;
 		xlen = strlen(x);
 		for (tn = firstnode(tl);
@@ -1801,7 +1817,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && parse_subst_string(x))
+	    if (eval && subst_parse_str(x, (qt && !nojoin)))
 		return NULL;
 	    xlen = strlen(x);
 	    strcatsub(&y, ostr, aptr, x, xlen, NULL, globsubst);
@@ -1816,7 +1832,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && parse_subst_string(x))
+		if (eval && subst_parse_str(x, (qt && !nojoin)))
 		    return NULL;
 		if (qt && !*x && isarr != 2)
 		    y = dupstring(nulstring);
@@ -1832,7 +1848,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && parse_subst_string(x))
+	    if (eval && subst_parse_str(x, (qt && !nojoin)))
 		return NULL;
 	    xlen = strlen(x);
 	    *str = strcatsub(&y, aptr, aptr, x, xlen, fstr, globsubst);
@@ -1851,7 +1867,7 @@
 	if (prenum || postnum)
 	    x = dopadding(x, prenum, postnum, preone, postone,
 			  premul, postmul);
-	if (eval && parse_subst_string(x))
+	if (eval && subst_parse_str(x, (qt && !nojoin)))
 	    return NULL;
 	xlen = strlen(x);
 	*str = strcatsub(&y, ostr, aptr, x, xlen, fstr, globsubst);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-16 10:38     ` Oliver Kiddle
@ 2000-02-16 11:52       ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2000-02-16 11:52 UTC (permalink / raw)
  To: Zsh workers

On Feb 16, 10:38am, Oliver Kiddle wrote:
} Subject: Re: help with _match, globcomplete etc. (with a PATCH)
}
} The reason I wanted this is basically that I use a number of associative
} arrays to point to different areas of the system I work on. [...]
} 
} [...] This leads me to make a suggestion which may or may not be easy
} but would solve my problems: in the same way as a variable whose
} value is a directory can be refered to with ~, could the same be made
} to work for associative arrays (and arrays in general I suppose),
} allowing me to use stuff like ~code[ai] and ~test[$area]?

Hrm.  You can already manually stuff things into the nameddir hash:

zagzig% unsetopt glob
zagzig% typeset -A xx 
zagzig% xx=($(print -l $path | cat -n))
zagzig% echo $xx[9]
/usr/etc
zagzig% for x in ${(k)xx}; hash -d xx[$x]=$xx[$x]
zagzig% cd ~xx[9]<TAB>
zagzig% cd ~xx[9]/

Well, would you look at that.  But if there I press return, I get:

cd: no such file or directory: ~xx[9]

That's because the [ and ] are tokenized most of the time, so they don't
match what has been added to the hash even if the typtab is modified to
treat them as IUSER.  It's probably an accident that the trailing slash
gets added that first time; you can't complete any further after it.

So it may be possible to make this work by using a more sophisticated
parse than simply scanning past all the IUSER characters, and then
throwing in a few calls to untokenize(); but I don't think I'm going to
attempt it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-16 10:11 Sven Wischnowsky
  2000-02-16 10:57 ` Bart Schaefer
@ 2000-02-16 11:18 ` Oliver Kiddle
  1 sibling, 0 replies; 9+ messages in thread
From: Oliver Kiddle @ 2000-02-16 11:18 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:

> Err, substitution is done in lines 30/31, so your new style only says
> that it should offer expansion only if attempting globbing did change
> the word resulting from substitution (given that I don't really
> understand the style name but maybe I'm the only one). I think it's
> fine to have that configurable.

Globbing wouldn't work without substitution being done first where there are variables etc in the line. The option allows me to have the benefit of globbing (at the expense of substition) in these cases without having substition for everything. So the effect is that only globbed things are substituted hence the name subst-only-globs. If anyone can think of a better name, its easily changed.

> Well, I'd say since the completion code normally adds slashes for
> directories we probably don't need a style for it as long as we add it
> with `-qS/', i.e. auto-removable.

A patch for this follows then.

--- Completion/Core/_expand.bak2        Wed Feb 16 10:58:09 2000
+++ Completion/Core/_expand     Wed Feb 16 10:58:18 2000
@@ -7,7 +7,7 @@
 # the expansions done produce no result or do not change the original
 # word from the line.
 
-local exp word="$PREFIX$SUFFIX" sort expr expl subd
+local exp word="$PREFIX$SUFFIX" sort expr expl subd suf=" "
 local curcontext="${curcontext/:[^:]#:/:expand:}"
 
 # First, see if we should insert all *completions*.
@@ -41,7 +41,7 @@
 zstyle -s ":completion:${curcontext}:" glob expr &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( ${~exp}(N) )
- 
+
 # If we don't have any expansions or only one and that is the same
 # as the original string, we let other completers run.
 
@@ -60,16 +60,19 @@
 
 [[ "$sort" = (yes|true|1|on) ]] && exp=( "${(@o)exp}" )
 
+# If there is only one expansion, add a suitable suffix
+(($#exp == 1)) && suf='' && [[ -d $exp ]] && suf='/'  
+
 if [[ -z "$compstate[insert]" ]] ;then
   _description all-expansions expl 'all expansions' "o:$word"
 
-  compadd "$expl[@]" -UQ - "$exp"
+  compadd "$expl[@]" -UQ -qS "$suf" - "$exp"
 else
   _tags all-expansions expansions original
 
 
   _requested all-expansions expl 'all expansions' "o:$word" &&
-      compadd "$expl[@]" -UQ "$exp"
+      compadd "$expl[@]" -UQ -qS "$suf" - "$exp"
 
   if _requested expansions; then
     if [[ "$sort" = menu ]]; then


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-16 10:11 Sven Wischnowsky
@ 2000-02-16 10:57 ` Bart Schaefer
  2000-02-16 11:18 ` Oliver Kiddle
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2000-02-16 10:57 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Feb 16, 11:11am, Sven Wischnowsky wrote:
} Subject: Re: help with _match, globcomplete etc. (with a PATCH)
}
} Bart Schaefer wrote:
} 
} > 	zsh% arr=('[sS]' Src/M ../)
} > 	zsh% print -l ${~^arr}*
} > 
} > (I note that on that example expand-word produces a list of files but
} > the _expand completer (with substitute and glob styles set to 1) only
} > beeps, with or without 9752 applied.  Is that the right behavior?)
} 
} No. Seems like the (e) flag makes the thing be quoted as in double
} quotes. I.e. with a='${~^arr}*', ${(e)a} gives `[sS] Src/M ../*', but
} a='${(@)~^arr}' gives what we would have expected. The patch below
} changes the calls to parsestr() to calls to parse_subst_string() to
} get that. Hm, should we call that only conditionally, e.g. if the
} ${(e)...} is not inquotes and has no (@) or something?

My first reaction would be to answer "yes," and a little fooling around
with 9757 applied seems to bear it out:

 a='*'
 print -l "${(e)a}"

Would you really expect to get one file name per line in that case?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-16  6:47   ` Bart Schaefer
@ 2000-02-16 10:38     ` Oliver Kiddle
  2000-02-16 11:52       ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2000-02-16 10:38 UTC (permalink / raw)
  To: Zsh workers

Bart Schaefer wrote:
> 
> On Feb 15,  7:53pm, Oliver Kiddle wrote:
> } Subject: Re: help with _match, globcomplete etc. (with a PATCH)
> } echo $code[ai]/{a,<tab>
>
> All I get from that is a beep, before Sven's 9749, and
> 
> zagzig% echo foo/\{a,
>                       ^note trailing space added
> with 9749 applied.
> Of course that seems wrong, too.  I didn't want the brace to be quoted.
> What output do you see?

Firstly, I meant <Ctrl-X,*> not <tab> above, as I said in the original
post but I think you probably used that. I see:

risc8% echo foo\[/\{a, 
also with a trailing space added.

> Hmm.  This would almost have to be done in C code; if you have more
> than one of the three forms in the same "word", it'd get pretty messy
> to dismantle it to expand only the appropriate substring(s).

Thats roughly what I imagined was the case after messing with _expand
more. It would probably never work too well with the various things I
had in mind for the scripts anyway.

> } Also, I can't see a way of doing globbing, while preserving variable
> } references.
> 
> This strikes me as nigh impossible in the general case.  What would you
> expect to see if you invoked the "glob but preserve variables" expansion
> in a case like:
> 
>         zsh% arr=('[sS]' Src/M ../)
>         zsh% print -l ${~^arr}*
> 
> ??  Or do I completely misunderstand what you're asking?

You're probably right, I was thinking of simple cases where the
variables used were single values not arrays. What I meant was that the
variable reference would remain in place of its expansion in the full
glob expansion. Anyway I take your point about why it isn't all that
simple.

The reason I wanted this is basically that I use a number of associative
arrays to point to different areas of the system I work on. The path to
most of these areas are stupidly long so I don't generally want my
variable references expanded on the command-line because I end up with a
mess spanning several lines with the things I want to look back at
buried deep amoung the long path names.

Normally for referencing directories, I'd be able to use the named
directory hash table - expand-or-complete never expanded tildes. In fact
the general handling of ~something in completion is exactly what I
wanted for my assocaitive array variables. This leads me to make a
suggestion which may or may not be easy but would solve my problems: in
the same way as a variable whose value is a directory can be refered to
with ~, could the same be made to work for associative arrays (and
arrays in general I suppose), allowing me to use stuff like ~code[ai]
and ~test[$area]?

Oliver Kiddle


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
@ 2000-02-16 10:11 Sven Wischnowsky
  2000-02-16 10:57 ` Bart Schaefer
  2000-02-16 11:18 ` Oliver Kiddle
  0 siblings, 2 replies; 9+ messages in thread
From: Sven Wischnowsky @ 2000-02-16 10:11 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> X-Seq: 9752
> 
> Sven Wischnowsky wrote:
> 
> > I couldn't reproduce your `[' problem, unless that was a typo and you
> > meant a quoted `{'. In this case it's the same as for the quoted
> > globbing characters.
> 
> It wasn't a typo. It only occurs when the referenced associative array is set. I can reproduce it as follows:
> zsh -f
> bindkey -me
> unsetopt glob
> typeset -A code
> code[ai]=foo
> echo $code[ai]/{a,<tab>

Hm, this stilll gives me only the `echo foo/\{a,' I was talking about.

> and, in a separate message: 
> > You can bind expand-word to ^X$. Expansion of parameter substitutions
> > is a problem, because the completion (shell) code doesn't get the
> > whole string. We only get the stuff after the $, so we can't really
> > change such things.
> 
> I don't quite understand what you mean here. _expand seems to get the whole thing including the '$'. The main limiting factor on my configuration is that I can't do parameter expansion, command substitution and arithmetic expansion independantly. Maybe the e parameter expansion flag could allow options to select them. Also, I can't see a way of doing globbing, while preserving variable references.

The completion code only gets it if it can find out that we are
*after* the parameter expression. I.e. it gets the `$...' in cases
like `${foo}<TAB>' and `$foo/<TAB>', but not with `$foo<TAB>'.

> In general, I don't like the substitution in _expand but the trouble with not having it enabled is that glob expansion will not work on lines with parameters. My solution is the following patch to _expand which adds the style subst-globs-only which if used with substitute and glob, only does expansion if globbing was able to do something meaningful. If you (Sven) are happy with this addition, I'll do a doc patch aswell.

Err, substitution is done in lines 30/31, so your new style only says
that it should offer expansion only if attempting globbing did change
the word resulting from substitution (given that I don't really
understand the style name but maybe I'm the only one). I think it's
fine to have that configurable.

> and elsewhere:
> > > Another thing which I would like to configure with expansion is when
> > > there is only one match, I'd prefer if the space suffix was not added -
> > > this is one of the things that makes the variable expansion annoying.
> > > Ideally, the suffix would be as if normal completion was used so
> > > directories would get a '/'.
> > When speaking about variables: see above. When speaking about other
> > expansions: _match does that and _expand could be made to do it
> > (adding a loop that appends slashes to directory names).
> 
> It is only really when the globbing results in only one match that I am concerned about the suffix because my cursor is at the end of that match and I'm likely to go on adding more to it and doing more completion. I'll add a patch for this. Should I make it depend on a zstyle thing? Will it be needed for both of the compadds in _expand?

Well, I'd say since the completion code normally adds slashes for
directories we probably don't need a style for it as long as we add it 
with `-qS/', i.e. auto-removable.

> Out of interest, why does the check in _expand need to check against "$word"(|\(N\)) as opposed to just "$word": under what circumstances can the (N) find its way into $exp?

I added this in 6945: `echo [:(N)' gives `[:(N)' (completion for
character-classes).


Bart Schaefer wrote:

> On Feb 15,  7:53pm, Oliver Kiddle wrote:
> } Subject: Re: help with _match, globcomplete etc. (with a PATCH)
> }
> } zsh -f
> } bindkey -me
> } unsetopt glob
> } typeset -A code
> } code[ai]=foo
> } echo $code[ai]/{a,<tab>
> 
> All I get from that is a beep, before Sven's 9749, and
> 
> zagzig% echo foo/\{a, 
>                       ^note trailing space added
> with 9749 applied.
> 
> Of course that seems wrong, too.  I didn't want the brace to be quoted.

As I said: I guess, this was intentional. If you have `a="foo bar"' or 
the words from globbing contain special characters, you want them to
be quoted. There may be a possibility to fix this by changing the
tokenization stuff in doexpansion().

> ...
> 
> } Also, I can't see a way of doing globbing, while preserving variable
> } references.
> 
> This strikes me as nigh impossible in the general case.  What would you
> expect to see if you invoked the "glob but preserve variables" expansion
> in a case like:
> 
> 	zsh% arr=('[sS]' Src/M ../)
> 	zsh% print -l ${~^arr}*
> 
> ??  Or do I completely misunderstand what you're asking?

;-) I was wondering, too.

> (I note that on that example expand-word produces a list of files but
> the _expand completer (with substitute and glob styles set to 1) only
> beeps, with or without 9752 applied.  Is that the right behavior?)

No. Seems like the (e) flag makes the thing be quoted as in double
quotes. I.e. with a='${~^arr}*', ${(e)a} gives `[sS] Src/M ../*', but
a='${(@)~^arr}' gives what we would have expected. The patch below
changes the calls to parsestr() to calls to parse_subst_string() to
get that. Hm, should we call that only conditionally, e.g. if the
${(e)...} is not inquotes and has no (@) or something?

(And of course, to get only all expansion, making it behave like
expand-word, one also needs to set the tag-order style for the expand
completer to `all-expansions'.)

Bye
 Sven

diff -ru ../z.old/Src/subst.c Src/subst.c
--- ../z.old/Src/subst.c	Tue Feb 15 13:21:36 2000
+++ Src/subst.c	Wed Feb 16 10:56:58 2000
@@ -1766,7 +1766,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && parsestr(x))
+		if (eval && parse_subst_string(x))
 		    return NULL;
 		xlen = strlen(x);
 		for (tn = firstnode(tl);
@@ -1801,7 +1801,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && parsestr(x))
+	    if (eval && parse_subst_string(x))
 		return NULL;
 	    xlen = strlen(x);
 	    strcatsub(&y, ostr, aptr, x, xlen, NULL, globsubst);
@@ -1816,7 +1816,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && parsestr(x))
+		if (eval && parse_subst_string(x))
 		    return NULL;
 		if (qt && !*x && isarr != 2)
 		    y = dupstring(nulstring);
@@ -1832,7 +1832,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && parsestr(x))
+	    if (eval && parse_subst_string(x))
 		return NULL;
 	    xlen = strlen(x);
 	    *str = strcatsub(&y, aptr, aptr, x, xlen, fstr, globsubst);
@@ -1851,7 +1851,7 @@
 	if (prenum || postnum)
 	    x = dopadding(x, prenum, postnum, preone, postone,
 			  premul, postmul);
-	if (eval && parsestr(x))
+	if (eval && parse_subst_string(x))
 	    return NULL;
 	xlen = strlen(x);
 	*str = strcatsub(&y, ostr, aptr, x, xlen, fstr, globsubst);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-15 19:53 ` help with _match, globcomplete etc. (with a PATCH) Oliver Kiddle
@ 2000-02-16  6:47   ` Bart Schaefer
  2000-02-16 10:38     ` Oliver Kiddle
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2000-02-16  6:47 UTC (permalink / raw)
  To: Zsh workers

On Feb 15,  7:53pm, Oliver Kiddle wrote:
} Subject: Re: help with _match, globcomplete etc. (with a PATCH)
}
} zsh -f
} bindkey -me
} unsetopt glob
} typeset -A code
} code[ai]=foo
} echo $code[ai]/{a,<tab>

All I get from that is a beep, before Sven's 9749, and

zagzig% echo foo/\{a, 
                      ^note trailing space added
with 9749 applied.

Of course that seems wrong, too.  I didn't want the brace to be quoted.

What output do you see?

} The main limiting factor on my configuration is that I can't do
} parameter expansion, command substitution and arithmetic expansion
} independantly.

Hmm.  This would almost have to be done in C code; if you have more
than one of the three forms in the same "word", it'd get pretty messy
to dismantle it to expand only the appropriate substring(s).

} Also, I can't see a way of doing globbing, while preserving variable
} references.

This strikes me as nigh impossible in the general case.  What would you
expect to see if you invoked the "glob but preserve variables" expansion
in a case like:

	zsh% arr=('[sS]' Src/M ../)
	zsh% print -l ${~^arr}*

??  Or do I completely misunderstand what you're asking?

(I note that on that example expand-word produces a list of files but
the _expand completer (with substitute and glob styles set to 1) only
beeps, with or without 9752 applied.  Is that the right behavior?)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: help with _match, globcomplete etc. (with a PATCH)
  2000-02-15 16:08 help with _match, globcomplete etc Sven Wischnowsky
@ 2000-02-15 19:53 ` Oliver Kiddle
  2000-02-16  6:47   ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Kiddle @ 2000-02-15 19:53 UTC (permalink / raw)
  To: Zsh workers

Sven Wischnowsky wrote:

> I couldn't reproduce your `[' problem, unless that was a typo and you
> meant a quoted `{'. In this case it's the same as for the quoted
> globbing characters.

It wasn't a typo. It only occurs when the referenced associative array is set. I can reproduce it as follows:
zsh -f
bindkey -me
unsetopt glob
typeset -A code
code[ai]=foo
echo $code[ai]/{a,<tab>

and, in a separate message: 
> You can bind expand-word to ^X$. Expansion of parameter substitutions
> is a problem, because the completion (shell) code doesn't get the
> whole string. We only get the stuff after the $, so we can't really
> change such things.

I don't quite understand what you mean here. _expand seems to get the whole thing including the '$'. The main limiting factor on my configuration is that I can't do parameter expansion, command substitution and arithmetic expansion independantly. Maybe the e parameter expansion flag could allow options to select them. Also, I can't see a way of doing globbing, while preserving variable references.

In general, I don't like the substitution in _expand but the trouble with not having it enabled is that glob expansion will not work on lines with parameters. My solution is the following patch to _expand which adds the style subst-globs-only which if used with substitute and glob, only does expansion if globbing was able to do something meaningful. If you (Sven) are happy with this addition, I'll do a doc patch aswell.

and elsewhere:
> > Another thing which I would like to configure with expansion is when
> > there is only one match, I'd prefer if the space suffix was not added -
> > this is one of the things that makes the variable expansion annoying.
> > Ideally, the suffix would be as if normal completion was used so
> > directories would get a '/'.
> When speaking about variables: see above. When speaking about other
> expansions: _match does that and _expand could be made to do it
> (adding a loop that appends slashes to directory names).

It is only really when the globbing results in only one match that I am concerned about the suffix because my cursor is at the end of that match and I'm likely to go on adding more to it and doing more completion. I'll add a patch for this. Should I make it depend on a zstyle thing? Will it be needed for both of the compadds in _expand?

Out of interest, why does the check in _expand need to check against "$word"(|\(N\)) as opposed to just "$word": under what circumstances can the (N) find its way into $exp?

Thanks for your help

Oliver

--- Completion/Core/_expand.bak Tue Feb 15 19:25:20 2000
+++ Completion/Core/_expand     Tue Feb 15 19:26:24 2000
@@ -7,7 +7,7 @@
 # the expansions done produce no result or do not change the original
 # word from the line.
 
-local exp word="$PREFIX$SUFFIX" sort expr expl
+local exp word="$PREFIX$SUFFIX" sort expr expl subd
 local curcontext="${curcontext/:[^:]#:/:expand:}"
 
 # First, see if we should insert all *completions*.
@@ -34,17 +34,25 @@
 
 [[ -z "$exp" ]] && exp=("$word")
 
+subd="$exp"
+
 # Now try globbing.
 
 zstyle -s ":completion:${curcontext}:" glob expr &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( ${~exp}(N) )
-
+ 
 # If we don't have any expansions or only one and that is the same
 # as the original string, we let other completers run.
 
 [[ $#exp -eq 0 ||
    ( $#exp -eq 1 && "$exp[1]" = "$word"(|\(N\)) ) ]] && return 1
+
+# With subst-globs-only we bail out if there were no glob expansions,
+# regardless of any substitutions
+zstyle -s ":completion:${curcontext}:" subst-globs-only expr &&
+    [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
+    [[ "$subd" = "$exp"(|\(N\)) ]] && return 1
 
 # Now add as matches whatever the user requested.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-02-17 14:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-17 14:43 help with _match, globcomplete etc. (with a PATCH) Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
2000-02-16 15:39 Sven Wischnowsky
2000-02-16 10:11 Sven Wischnowsky
2000-02-16 10:57 ` Bart Schaefer
2000-02-16 11:18 ` Oliver Kiddle
2000-02-15 16:08 help with _match, globcomplete etc Sven Wischnowsky
2000-02-15 19:53 ` help with _match, globcomplete etc. (with a PATCH) Oliver Kiddle
2000-02-16  6:47   ` Bart Schaefer
2000-02-16 10:38     ` Oliver Kiddle
2000-02-16 11:52       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).