zsh-workers
 help / color / mirror / code / Atom feed
* Re: help with _match, globcomplete etc.
@ 2000-02-15 11:34 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-02-15 11:34 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> Sven Wischnowsky wrote:
> 
> > You can bind expand-word to ^X$.
> 
> True though I was mainly after not having variable expansion ever when I
> press tab.
> 
> Incidentally, I tried creating:
> expand-variables() {
>   setopt localoptions noglob
>   zle expand-word
> }
> zle -N expand-variables

Why use expand-word at all then? Modified from a widget that appeared
on the users list some time ago:

  expand-variables() {
    local skip="${(M)LBUFFER%%[ 	\;\|\{\}]##}"
    local word="${(M)${LBUFFER%${skip}}%%[^ 	\;\|\{\}]##}" exp

    exp=${(e)word}

    [[ -n "$exp" ]] && LBUFFER="${LBUFFER%${word}${skip}}${exp}${skip}"
  }
  zle -N expand-variables

Or some such.

> so that ^X$ wouldn't also glob complete but it comes back with any glob
> characters quoted. It seems that expand-word always does this when
> noglob is set. Surely this isn't right? In the process, I also noticed
> that the quoting can go slightly wrong if there are opened but not
> closed braces: $code[ai]/{a,b<Ctrl-X,*> comes back with a quoted '[' in
> the middle.

Maybe I'll have a look some time...

> > Have you had a look at the _expand completer? And the _expand_word
> 
> I have now but I can't get it to work. I've probably missed something
> but this won't work:
> 
> zsh -f
> autoload -U compinit
> compinit
> bindkey '^I' complete-word
> zstyle -d
> zstyle ':completion:*::::' completer _expand
> echo *<tab>
> 
> I was expecting the last line to glob expand (as if tab was still bound
> to expand-or-complete) but all I can get is a beep. I've tried changing
> the related styles without any effect.

Setting `zstyle ':completion:*:expand:*' glob 1' works for me.

It is a bit irritating that you have to switch on at least one style
to make _expand do anything...


Bye
 Sven


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


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

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


Oliver Kiddle wrote:

> ...
>
> so that ^X$ wouldn't also glob complete but it comes back with any glob
> characters quoted. It seems that expand-word always does this when
> noglob is set. Surely this isn't right? In the process, I also noticed
> that the quoting can go slightly wrong if there are opened but not
> closed braces: $code[ai]/{a,b<Ctrl-X,*> comes back with a quoted '[' in
> the middle.

Hm. It's the call to quotename() in zle_tricky.c:1649. I'm pretty sure 
this is intended to make things work when the words resulting from
parameter expansion or globbing contains characters that need to be
quoted.

Trying to fix that would be very hard... we would have to find out
which part comes from the expansion and which doesn't or maybe being
more careful with (un)tokenization()... so, no patch for this.

However, it also removed parts of the string in cases like the example --
brace expansions. That's due to the in-brace completion stuff. The
patch fixes this in the simplest way I could thnik of: keep a
unaltered copy of the word an let expansion work on that.

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.

Bye
 Sven

P.S.:   The difference between the not-fixed and the fixed part is
        that I didn't write the former and hence don't really feel
        responsible ;-)

P.P.S.: Yes, there are parts of zle_tricky.c I didn't write.

diff -ru ../z.old/Src/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- ../z.old/Src/Zle/zle_tricky.c	Tue Feb 15 13:21:40 2000
+++ Src/Zle/zle_tricky.c	Tue Feb 15 16:55:11 2000
@@ -108,6 +108,10 @@
 
 static char *qword;
 
+/* This holds the word we are working on without braces removed. */
+
+static char *origword;
+
 /* The quoted prefix/suffix and a flag saying if we want to add the
  * closing quote. */
 
@@ -685,17 +689,17 @@
 	    inwhat = IN_CMD;
 
 	if (lst == COMP_SPELL) {
-	    char *x, *q, *ox;
+	    char *w = dupstring(origword), *x, *q, *ox;
 
-	    for (q = s; *q; q++)
+	    for (q = w; *q; q++)
 		if (INULL(*q))
 		    *q = Nularg;
 	    cs = wb;
 	    foredel(we - wb);
 	    HEAPALLOC {
-		untokenize(x = ox = dupstring(s));
-		if (*s == Tilde || *s == Equals || *s == String)
-		    *x = *s;
+		untokenize(x = ox = dupstring(w));
+		if (*w == Tilde || *w == Equals || *w == String)
+		    *x = *w;
 		spckword(&x, 0, lincmd, 0);
 		ret = !strcmp(x, ox);
 	    } LASTALLOC;
@@ -708,7 +712,7 @@
 	    int ocs = cs, ne = noerrs;
 
 	    noerrs = 1;
-	    ret = doexpansion(s, lst, olst, lincmd);
+	    ret = doexpansion(origword, lst, olst, lincmd);
 	    lastambig = 0;
 	    noerrs = ne;
 
@@ -1329,6 +1333,9 @@
 		chuck(p--);
 	    }
 
+	zsfree(origword);
+	origword = ztrdup(s);
+
 	if (!isset(IGNOREBRACES)) {
 	    /* Try and deal with foo{xxx etc. */
 	    char *curs = s + (isset(COMPLETEINWORD) ? offs : strlen(s));
@@ -1353,8 +1360,8 @@
 			    break;
 			}
 			i += tp - p;
-			p = tp;
 			dp += tp - p;
+			p = tp;
 		    } else {
 			char *tp = p + 1;
 
@@ -1385,8 +1392,8 @@
 			    }
 			    tp--;
 			    i += tp - p;
-			    p = tp;
 			    dp += tp - p;
+			    p = tp;
 			}
 		    }
 		} else if (p < curs) {

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


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

* Re: help with _match, globcomplete etc.
  2000-02-14 13:03 help with _match, globcomplete etc. (with PATCH) Sven Wischnowsky
@ 2000-02-15 11:09 ` Oliver Kiddle
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2000-02-15 11:09 UTC (permalink / raw)
  To: Zsh workers

Sven Wischnowsky wrote:

> You can bind expand-word to ^X$.

True though I was mainly after not having variable expansion ever when I
press tab.

Incidentally, I tried creating:
expand-variables() {
  setopt localoptions noglob
  zle expand-word
}
zle -N expand-variables

so that ^X$ wouldn't also glob complete but it comes back with any glob
characters quoted. It seems that expand-word always does this when
noglob is set. Surely this isn't right? In the process, I also noticed
that the quoting can go slightly wrong if there are opened but not
closed braces: $code[ai]/{a,b<Ctrl-X,*> comes back with a quoted '[' in
the middle.

> Have you had a look at the _expand completer? And the _expand_word

I have now but I can't get it to work. I've probably missed something
but this won't work:

zsh -f
autoload -U compinit
compinit
bindkey '^I' complete-word
zstyle -d
zstyle ':completion:*::::' completer _expand
echo *<tab>

I was expecting the last line to glob expand (as if tab was still bound
to expand-or-complete) but all I can get is a beep. I've tried changing
the related styles without any effect.

Thanks

Oliver


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

* help with _match, globcomplete etc.
  2000-02-08 14:28 Problem with completion after a variable with globcomplete Sven Wischnowsky
@ 2000-02-14 12:23 ` Oliver Kiddle
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2000-02-14 12:23 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:

> (there is almost no real reason to use
> GLOB_COMPLETE nowadays, the _match completer should be better -- and
> configurable).

I've just been trying to fathom out what is going on with respect to
when zsh expands, menu completes expansions and doesn't expand. It all
is a little bit complicated, especially as the behaviour is controlled
by a mix of options, styles and the choice of widget that tab is bound
to.

Part of the trouble is the way zsh's shell expansion works. If you use
expand-or-complete, I can't see any way of customising what is and isn't
expanded - variables, globs and history are, tildes are not. The
behaviour which I would like is that variables are not expanded unless I
specifically use a widget bound to '^X$' - like tcsh's expand-variables
widget. Would it be possible for the shell expansion used in completion
to be controlled by a style?

The reason I still use glob_complete is that it allows some action when
completing glob patterns (menu completion though I'd prefer expansion in
the case of files) while not expanding variables.

I can however see that the _match completer is better, mainly in that I
can choose menu completion where only one argument is required and
expansion where many are required.

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 '/'.

Oliver Kiddle

PS. Sorry about sending the wrapped patch before - I forgot to disable
wrapping in my mailer. I can resend it if that would be useful to
anyone.


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

end of thread, other threads:[~2000-02-15 16:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-15 11:34 help with _match, globcomplete etc Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
2000-02-15 16:08 Sven Wischnowsky
2000-02-14 13:03 help with _match, globcomplete etc. (with PATCH) Sven Wischnowsky
2000-02-15 11:09 ` help with _match, globcomplete etc Oliver Kiddle
2000-02-08 14:28 Problem with completion after a variable with globcomplete Sven Wischnowsky
2000-02-14 12:23 ` help with _match, globcomplete etc Oliver Kiddle

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).