* \## -> x when completing @ 2012-02-08 22:37 Mikael Magnusson 2012-02-09 15:37 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Mikael Magnusson @ 2012-02-08 22:37 UTC (permalink / raw) To: zsh workers zsh -f touch xenon autoload compinit; compinit setopt globcomplete cat \##<tab> -> cat xenon -- Mikael Magnusson ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: \## -> x when completing 2012-02-08 22:37 \## -> x when completing Mikael Magnusson @ 2012-02-09 15:37 ` Bart Schaefer 2012-02-09 16:16 ` Mikael Magnusson 0 siblings, 1 reply; 4+ messages in thread From: Bart Schaefer @ 2012-02-09 15:37 UTC (permalink / raw) To: zsh workers This gets a bit stream-of-consciousness but maybe that's helpful. On Feb 8, 11:37pm, Mikael Magnusson wrote: } Subject: \## -> x when completing } } zsh -f } touch xenon } autoload compinit; compinit } setopt globcomplete } cat \##<tab> -> cat xenon Hmm. This is probably happening because the completion internals use an "x" as a place-holder in some instances. See the functions comptils.c:comp_quote, compcore.c:tildequote, and zle_tricky.c:addx, the latter of which has a big comment explaining what's going on. However, I think it's more likely compcore.c:set_comp_sep that is the culprit. We can find out by changing the 'x' to something else in one of addx or set_comp_sep and then trying the completion again. Which reveals that it's neither of those; rather compcore.c:addmatches is playing funny with us, at line 2302: 2293 if (comppatmatch && *comppatmatch) { 2294 int is = (*comppatmatch == '*'); 2295 char *tmp = (char *) zhalloc(2 + llpl + llsl + gfl); 2296 2297 if (gfl) { 2298 strcpy(tmp, globflag); 2299 strcat(tmp, lpre); 2300 } else 2301 strcpy(tmp, lpre); 2302 tmp[llpl + gfl] = 'x'; 2303 strcpy(tmp + llpl + gfl + is, lsuf); 2304 2305 tokenize(tmp); 2306 remnulargs(tmp); 2307 if (haswilds(tmp)) { 2308 if (is) 2309 tmp[llpl + gfl] = Star; 2310 if ((cp = patcompile(tmp, 0, NULL))) 2311 haspattern = 1; 2312 } 2313 } The problem seems to be that remnulargs() has shortened tmp so that the count (llpl + gfl) is no longer correct. I believe we can fix that by moving remnulargs to after line 2309. Index: Src/Zle/compcore.c =================================================================== --- Src/Zle/compcore.c 20 Dec 2011 17:13:38 -0000 1.29 +++ Src/Zle/compcore.c 9 Feb 2012 15:33:44 -0000 @@ -2303,10 +2303,10 @@ strcpy(tmp + llpl + gfl + is, lsuf); tokenize(tmp); - remnulargs(tmp); if (haswilds(tmp)) { if (is) tmp[llpl + gfl] = Star; + remnulargs(tmp); if ((cp = patcompile(tmp, 0, NULL))) haspattern = 1; } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: \## -> x when completing 2012-02-09 15:37 ` Bart Schaefer @ 2012-02-09 16:16 ` Mikael Magnusson 2012-02-09 18:22 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Mikael Magnusson @ 2012-02-09 16:16 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh workers On 9 February 2012 16:37, Bart Schaefer <schaefer@brasslantern.com> wrote: > This gets a bit stream-of-consciousness but maybe that's helpful. > > On Feb 8, 11:37pm, Mikael Magnusson wrote: > } Subject: \## -> x when completing > } > } zsh -f > } touch xenon > } autoload compinit; compinit > } setopt globcomplete > } cat \##<tab> -> cat xenon > > Hmm. This is probably happening because the completion internals use > an "x" as a place-holder in some instances. See the functions > comptils.c:comp_quote, compcore.c:tildequote, and zle_tricky.c:addx, > the latter of which has a big comment explaining what's going on. > > However, I think it's more likely compcore.c:set_comp_sep that is the > culprit. We can find out by changing the 'x' to something else in one > of addx or set_comp_sep and then trying the completion again. > > Which reveals that it's neither of those; rather compcore.c:addmatches > is playing funny with us, at line 2302: > > 2293 if (comppatmatch && *comppatmatch) { > 2294 int is = (*comppatmatch == '*'); > 2295 char *tmp = (char *) zhalloc(2 + llpl + llsl + gfl); > 2296 > 2297 if (gfl) { > 2298 strcpy(tmp, globflag); > 2299 strcat(tmp, lpre); > 2300 } else > 2301 strcpy(tmp, lpre); > 2302 tmp[llpl + gfl] = 'x'; > 2303 strcpy(tmp + llpl + gfl + is, lsuf); > 2304 > 2305 tokenize(tmp); > 2306 remnulargs(tmp); > 2307 if (haswilds(tmp)) { > 2308 if (is) > 2309 tmp[llpl + gfl] = Star; > 2310 if ((cp = patcompile(tmp, 0, NULL))) > 2311 haspattern = 1; > 2312 } > 2313 } > > The problem seems to be that remnulargs() has shortened tmp so that > the count (llpl + gfl) is no longer correct. I believe we can fix > that by moving remnulargs to after line 2309. > > Index: Src/Zle/compcore.c > =================================================================== > --- Src/Zle/compcore.c 20 Dec 2011 17:13:38 -0000 1.29 > +++ Src/Zle/compcore.c 9 Feb 2012 15:33:44 -0000 > @@ -2303,10 +2303,10 @@ > strcpy(tmp + llpl + gfl + is, lsuf); > > tokenize(tmp); > - remnulargs(tmp); > if (haswilds(tmp)) { > if (is) > tmp[llpl + gfl] = Star; > + remnulargs(tmp); > if ((cp = patcompile(tmp, 0, NULL))) > haspattern = 1; > } This fix seems to work for me, I have barely tried anything but my test case so far though :). cat \##g<tab> now works in an irclogs dir to complete both files starting with g and #g though. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: \## -> x when completing 2012-02-09 16:16 ` Mikael Magnusson @ 2012-02-09 18:22 ` Bart Schaefer 0 siblings, 0 replies; 4+ messages in thread From: Bart Schaefer @ 2012-02-09 18:22 UTC (permalink / raw) To: zsh workers On Thu, Feb 9, 2012 at 8:16 AM, Mikael Magnusson <mikachu@gmail.com> wrote: >> tokenize(tmp); >> - remnulargs(tmp); >> if (haswilds(tmp)) { >> if (is) >> tmp[llpl + gfl] = Star; >> + remnulargs(tmp); >> if ((cp = patcompile(tmp, 0, NULL))) >> haspattern = 1; >> } > > This fix seems to work for me, I have barely tried anything but my > test case so far though :). cat \##g<tab> now works in an irclogs dir My new worry is that tokenize() might make the string *longer*, thus causing the Star to be inserted too far to the left. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-02-09 18:22 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-02-08 22:37 \## -> x when completing Mikael Magnusson 2012-02-09 15:37 ` Bart Schaefer 2012-02-09 16:16 ` Mikael Magnusson 2012-02-09 18:22 ` 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).