zsh-workers
 help / color / mirror / code / Atom feed
* Re: cdablevars and cd completion in 3.1.5
@ 1998-12-07 11:58 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1998-12-07 11:58 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> ... [ message 4698 ]

The patch in this message contained a `fix' for quoting words
resulting from completion. This looked good until I tried completion
on a parameter name. So the patch below removes the corresponding
changes again.

Sorry!

Bye
 Sven

*** os/Zle/zle_tricky.c	Thu Dec  3 11:18:40 1998
--- Src/Zle/zle_tricky.c	Mon Dec  7 12:23:14 1998
***************
*** 2281,2289 ****
      int l, r = 0, ocs, a = cs;
  
      if (m->ipre) {
! 	char *p = quotename(m->ipre, NULL, NULL, NULL);
! 
! 	inststrlen(p, 1, (l = strlen(p)));
  	r += l;
      } 
      if (m->pre) {
--- 2281,2287 ----
      int l, r = 0, ocs, a = cs;
  
      if (m->ipre) {
! 	inststrlen(m->ipre, 1, (l = strlen(m->ipre)));
  	r += l;
      } 
      if (m->pre) {
***************
*** 4814,4820 ****
  	 * to insert any unambiguous prefix and suffix, if possible.         */
  
  	if (ainfo->iprefix && *ainfo->iprefix) {
! 	    inststrlen(quotename(ainfo->iprefix, NULL, NULL, NULL), 1, -1);
  	    inststrlen(ainfo->pprefix, 1, -1);
  	    ps = ainfo->iaprefix;
  	    lc = ainfo->ilinecl;
--- 4812,4818 ----
  	 * to insert any unambiguous prefix and suffix, if possible.         */
  
  	if (ainfo->iprefix && *ainfo->iprefix) {
! 	    inststrlen(ainfo->iprefix, 1, -1);
  	    inststrlen(ainfo->pprefix, 1, -1);
  	    ps = ainfo->iaprefix;
  	    lc = ainfo->ilinecl;


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


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

* Re: cdablevars and cd completion in 3.1.5
@ 1998-12-03 10:17 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1998-12-03 10:17 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> If the current word can't be completed because of the position of the
> cursor, then shouldn't the position of the cursor also determine whether
> the pattern matches the word in the first place?  Why would you ever
> WANT a pattern to match and then NOT call the corresponding completion?

Not wanting to reply `yes, I agree' without being able to offer you a
patch, I waited until now...

The patch below makes `-x'-patterns match only if the cursor is not in 
the ignored part of the current word. This affect only `s[...]',
`S[...]', `n[...]', and `N[...]'. It does NOT affect `c[0,...]' or
`w[...]'.
The patch also fixes re-inserting ignored prefixes that need quoting.

This one goes on top of the patch (4697) I just send (and you'll need
that one).

Bye
 Sven

*** os/Zle/zle_tricky.c	Thu Dec  3 09:17:12 1998
--- Src/Zle/zle_tricky.c	Thu Dec  3 11:04:31 1998
***************
*** 2281,2287 ****
      int l, r = 0, ocs, a = cs;
  
      if (m->ipre) {
! 	inststrlen(m->ipre, 1, (l = strlen(m->ipre)));
  	r += l;
      } 
      if (m->pre) {
--- 2281,2289 ----
      int l, r = 0, ocs, a = cs;
  
      if (m->ipre) {
! 	char *p = quotename(m->ipre, NULL, NULL, NULL);
! 
! 	inststrlen(p, 1, (l = strlen(p)));
  	r += l;
      } 
      if (m->pre) {
***************
*** 2718,2735 ****
  
  /**/
  static int
! getcpat(char *wrd, int cpatindex, char *cpat, int class)
  {
!     char *str, *s, *t, *p;
      int d = 0;
  
!     if (!wrd || !*wrd)
  	return -1;
  
      cpat = rembslash(cpat);
  
-     str = ztrdup(wrd);
-     untokenize(str);
      if (!cpatindex)
  	cpatindex++, d = 0;
      else if ((d = (cpatindex < 0)))
--- 2720,2735 ----
  
  /**/
  static int
! getcpat(char *str, int cpatindex, char *cpat, int class)
  {
!     char *s, *t, *p;
      int d = 0;
  
!     if (!str || !*str)
  	return -1;
  
      cpat = rembslash(cpat);
  
      if (!cpatindex)
  	cpatindex++, d = 0;
      else if ((d = (cpatindex < 0)))
***************
*** 2740,2762 ****
  	 d ? s-- : s++) {
  	for (t = s, p = cpat; *t && *p; p++) {
  	    if (class) {
! 		if (*p == *s && !--cpatindex) {
! 		    zsfree(str);
  		    return (int)(s - str + 1);
- 		}
  	    } else if (*t++ != *p)
  		break;
  	}
! 	if (!class && !*p && !--cpatindex) {
! 	    zsfree(str);
! 	    t += wrd - str;
! 	    for (d = 0; --t >= wrd;)
! 		if (! INULL(*t))
! 		    d++;
! 	    return d;
! 	}
      }
-     zsfree(str);
      return -1;
  }
  
--- 2740,2753 ----
  	 d ? s-- : s++) {
  	for (t = s, p = cpat; *t && *p; p++) {
  	    if (class) {
! 		if (*p == *s && !--cpatindex)
  		    return (int)(s - str + 1);
  	    } else if (*t++ != *p)
  		break;
  	}
! 	if (!class && !*p && !--cpatindex)
! 	    return t - str;
      }
      return -1;
  }
  
***************
*** 3322,3329 ****
  			break;
  		    case CCT_CURSUF:
  		    case CCT_CURPRE:
! 			s = ztrdup(clwpos < clwnum ? clwords[clwpos] : "");
  			untokenize(s);
  			sc = rembslash(cc->u.s.s[i]);
  			a = strlen(sc);
  			if (!strncmp(s, sc, a)) {
--- 3313,3321 ----
  			break;
  		    case CCT_CURSUF:
  		    case CCT_CURPRE:
! 			s = ztrdup(clwpos < clwnum ? os : "");
  			untokenize(s);
+ 			if (isset(COMPLETEINWORD)) s[offs] = '\0';
  			sc = rembslash(cc->u.s.s[i]);
  			a = strlen(sc);
  			if (!strncmp(s, sc, a)) {
***************
*** 3336,3342 ****
  			if (clwpos < 0 || clwpos >= clwnum)
  			    t = 0;
  			else {
! 			    a = getcpat(clwords[clwpos],
  					cc->u.s.p[i],
  					cc->u.s.s[i],
  					cc->type == CCT_CURSUBC);
--- 3328,3337 ----
  			if (clwpos < 0 || clwpos >= clwnum)
  			    t = 0;
  			else {
! 			    s = ztrdup(os);
! 			    untokenize(s);
! 			    if (isset(COMPLETEINWORD)) s[offs] = '\0';
! 			    a = getcpat(s,
  					cc->u.s.p[i],
  					cc->u.s.s[i],
  					cc->type == CCT_CURSUBC);
***************
*** 4819,4825 ****
  	 * to insert any unambiguous prefix and suffix, if possible.         */
  
  	if (ainfo->iprefix && *ainfo->iprefix) {
! 	    inststrlen(ainfo->iprefix, 1, -1);
  	    inststrlen(ainfo->pprefix, 1, -1);
  	    ps = ainfo->iaprefix;
  	    lc = ainfo->ilinecl;
--- 4814,4820 ----
  	 * to insert any unambiguous prefix and suffix, if possible.         */
  
  	if (ainfo->iprefix && *ainfo->iprefix) {
! 	    inststrlen(quotename(ainfo->iprefix, NULL, NULL, NULL), 1, -1);
  	    inststrlen(ainfo->pprefix, 1, -1);
  	    ps = ainfo->iaprefix;
  	    lc = ainfo->ilinecl;


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


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

* Re: cdablevars and cd completion in 3.1.5
  1998-12-01 12:52 Sven Wischnowsky
@ 1998-12-01 18:09 ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 1998-12-01 18:09 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Dec 1,  1:52pm, Sven Wischnowsky wrote:
} Subject: Re: cdablevars and cd completion in 3.1.5
}
} Bart Schaefer wrote:
} > ...
} >     compctl -x 'S[/][~][./][../]' -/ \
} > 	    - 'n[-1,/], s[]' -K cdmatch -S '/' -q \
} > 	    -- cd pushd
} > ...
} > zsh% cd HE/zshfun
} >          ^
} > 	 With the cursor here, pressing tab does NOT call cdmatch!
} > 	 Why not?
} 
} The reason was that the `n[-1,/]' makes the part before the `/' be
} ignored so that the cursor isn't in a part that is considered for
} completion.

If the current word can't be completed because of the position of the
cursor, then shouldn't the position of the cursor also determine whether
the pattern matches the word in the first place?  Why would you ever
WANT a pattern to match and then NOT call the corresponding completion?

}     compctl -x 'S[/][~][./][../]' -/ \
} 	    - 'n[-1,/] s[], s[]' -K cdmatch -S '/' -q \
} 	    -- cd pushd
} 
} The interesting bit is the `s[]' before the comma. It makes the
} completion code use the prefix specified by `s[]' be ignored instead
} of the prefix specified by `n[-1,/]'.

Hm; I'd have expected them to be cumulative (though possibly overlapping),
but I can see where that'd be a mess particularly for something strange
like
	compctl -x 'n[1,/] n[-1,/]' ...

However, that doesn't work, because it stops ignoring the stuff up to
the last /, so now all the completions cdmatch puts in $reply have to
include that prefix when completing anything *after* that slash.  I.e.

zsh% cd HOME/z<TAB>

feeps because reply=(zshfun) and the code wants reply=(HOME/zshfun).

Your alternate compctl has the same problem.  It's probably possible to
fix my cdmatch to handle that, but it isn't straightforward, as it can't
simply use tilde-expansion and then lop off the path tail; instead it
has to convert the path head back into the corresponding named dir.  I
suppose a trick with print -P could be used, but that's another $().

(The other possibility would be to use the -U option and thus expand the
variable name into the full path it represents.)

} So with this the function will
} be called and we only have to change it accordingly, i.e.:
} 
}     reply=( ${${${(M)$(set):#${pref:-[A-Za-z]}*${2:h}*\=/*}:#*(PWD|:)*}%\=/*}${(M)2%%/*} )
} 
} (adding the last `${(M)...}').

That can complete to impossible paths because it doesn't check whether
the stuff in $2 really is a subdirectory of the named dir in $pref.  To
check correctly again requires tilde-expanding and then converting back
into a named dir.

So I think, all things considered, I'd give up completeinword on cdable
variables and take my original function and compctl.

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


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

* Re: cdablevars and cd completion in 3.1.5
@ 1998-12-01 12:52 Sven Wischnowsky
  1998-12-01 18:09 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 1998-12-01 12:52 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

>
> ...
>
>     compctl -x 'S[/][~][./][../]' -/ \
> 	    - 'n[-1,/], s[]' -K cdmatch -S '/' -q \
> 	    -- cd pushd
>
> ...
> 
> Now the obligatory bit of zsh arcana that still confuses me:
> 
> zsh% echo ~/zshfun
> /home/schaefer/zshfun
> zsh% cd HE
>          ^
> 	 With cursor here, this calls cdmatch and completes HOME/.
> 	 But if instead I have
> zsh% cd HE/zshfun
>          ^
> 	 With the cursor here, pressing tab does NOT call cdmatch!
> 	 Why not?  I have completeinword set.  The word under the
> 	 cursor contains a /, so it should match n[-1,/].  I expected
> 	 it to call cdmatch with 1=H 2=E/zshfun and to be able to
> 	 read HE/zshfun into $pref.  If Instead I have
> zsh% cd HOME/zn
>               ^
> 	      with the cursor here, I can complete to HOME/zshfun.
> 
> I have the feeling this is something I once knew, but maybe it needs to
> be written down somewhere.

The reason was that the `n[-1,/]' makes the part before the `/' be
ignored so that the cursor isn't in a part that is considered for
completion.
Interestingly I first parsed your compctl wrongly and that led me to a 
nice little workaround for this:

    compctl -x 'S[/][~][./][../]' -/ \
	    - 'n[-1,/] s[], s[]' -K cdmatch -S '/' -q \
	    -- cd pushd

The interesting bit is the `s[]' before the comma. It makes the
completion code use the prefix specified by `s[]' be ignored instead
of the prefix specified by `n[-1,/]'. So with this the function will
be called and we only have to change it accordingly, i.e.:

    reply=( ${${${(M)$(set):#${pref:-[A-Za-z]}*${2:h}*\=/*}:#*(PWD|:)*}%\=/*}${(M)2%%/*} )

(adding the last `${(M)...}').

Btw. I would use this compctl instead:

    compctl -/ -K cdmatch -S/ -q -x 'S[/][~][./][../]' -/ -- cd pushd


Bye
 Sven

P.S.: Yes, we probably should document the above, but I'm terribly
      busy the next few days...

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


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

end of thread, other threads:[~1998-12-07 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-07 11:58 cdablevars and cd completion in 3.1.5 Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1998-12-03 10:17 Sven Wischnowsky
1998-12-01 12:52 Sven Wischnowsky
1998-12-01 18:09 ` 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).