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

Re: Command expansion failure in for loops



On Jun 12,  8:50pm, Mike Brown wrote:
}
} Now for the issue.  Command expansion is no longer working in for loops.

This works if "compinit" has been run, but possibly for the wrong reason:
if there is a completion function defined, it is called so that it can
make the decision about whether to complete a word or insert a TAB (see
"usetab()" mention below).

It fails with "native" completion (compctl et al.).

}     for name in x y z
}     for> do
}     for> ftp_s<TAB>

The reason appears to have something to do with workers/36025.  When
complete-word is done on the same line as the "do" everything is fine;
it's only when on the new line after "do" that it gets confused.  At
this test --

1189            lincmd = !inredir &&
1190                ((incmdpos && !ins && !incond) ||
1191                 (oins == 2 && wordpos == 2) ||
1192                 (ins == 3 && wordpos == 1) ||
1193                 (cmdtok == NULLTOK && !incond));

-- when completing on the same line as "do", cmdtok == NULLTOK, but when
completing on the next line, cmdtok == FOR, and so lincmd becomes false
and command names are not completed (instead file names are).

I haven't tracked down why the lexical analysis changes with the extra
newline.  Probably "do" isn't being treated as a reserved word, i.e.,
lexing thinks it is "for name in x y z do;" ?

There's one additional oddity, which is that with expand-or-complete
instead of complete-word, if the line following "do" is empty then
usetab() returns true and no completion is done at all; instead a TAB
is inserted.  However, that's been that way since sometime in 4.x.

} It worked before version 5.2.

Broken for me as far back as zsh-5.0.2-dev-0 (so perhaps not directly
related to 36025 after all, but seems to be in that part of the code).



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