Errors in ZSH syntax highlighting

152 views
Skip to first unread message

Richard Hartmann

unread,
Jul 17, 2008, 6:30:39 AM7/17/08
to vim-dev
Hi all,

I will try to look at this myself, but my time is extremely short, atm.
Thus, this is both a reminder to $self and an invitation for others to
look at it.

Syntax elements are detected & highlighted in the wrong places.
Two examples I have known for some time but never got around to
do much about them are:

for do (foo bar); do; echo $do; done
foreach do (foo bar); do; echo $do; done

/do/not/highlight

In the first case, I assign values to a variable named do, in the
second, I am using it in a path. Of course, the same happens for
the other usual suspects. functions, case, if, you name it.


Thanks,
Richard

Nikolai Weibull

unread,
Jul 17, 2008, 8:27:56 AM7/17/08
to vim...@googlegroups.com, vim-dev
On Thu, Jul 17, 2008 at 12:30, Richard Hartmann
<richih.ma...@gmail.com> wrote:

> Syntax elements are detected & highlighted in the wrong places.

> Two examples I have known for some time but never got around to
> do much about them are:

Posting sooner rather than later is always better. That almost rhymes.

> for do (foo bar); do; echo $do; done
> foreach do (foo bar); do; echo $do; done

Fixed. for and foreach now have a nextgroup=zshVariable that takes
care of this.

However, why would you name a variable do?

Also, why are you putting semicolons after do?

> /do/not/highlight

This particular case can be solved by matching paths, but how about
arguments to commands in general, for example:

grep do *.zsh?

To not highlight keywords in this situation would require us (and by
that I mean me) to implement the whole Zsh grammar. Please take a
look at Src/parse.c before asking me to do that.

Overall I think that syntax/zsh.vim does a very good job of
highlighting Zsh source files. I can live with a few blemishes if
they require substantial complexity to fix.

Richard Hartmann

unread,
Jul 17, 2008, 9:12:22 AM7/17/08
to vim...@googlegroups.com, vim-dev
On Thu, Jul 17, 2008 at 14:27, Nikolai Weibull <n...@bitwi.se> wrote:


> Posting sooner rather than later is always better. That almost rhymes.

True. I simply always forgot by the time I was finished fiddling with my
scripts.


> However, why would you name a variable do?

I wouldn't. I named one variable test, but do was shorter to write in my
email :)


> Also, why are you putting semicolons after do?

I am using shortloops 99% of the time and thus always forget where
to put the semi-colons. Slobbering the thing with them works, so I
adapted that 'style'.


> This particular case can be solved by matching paths, but how about
> arguments to commands in general, for example:

Indeed. That is (almost) the only situations I saw the issue rear its
head, too. In that case it was ~/.zsh/functions, but again, 'do' is
faster to read & write. The other situation woud be

echo yes I do


> To not highlight keywords in this situation would require us (and by
> that I mean me) to implement the whole Zsh grammar. Please take a
> look at Src/parse.c before asking me to do that.

I know that this is not feasible or at least not worthwhile in terms
of work and gain. I only mailed the list because I knew they would
be easy to fix.


> Overall I think that syntax/zsh.vim does a very good job of
> highlighting Zsh source files. I can live with a few blemishes if
> they require substantial complexity to fix.

Agreed :)


Thanks for your work,
Richard

James Vega

unread,
Jul 17, 2008, 9:33:09 AM7/17/08
to vim-dev
On Thu, Jul 17, 2008 at 02:27:56PM +0200, Nikolai Weibull wrote:
>
> On Thu, Jul 17, 2008 at 12:30, Richard Hartmann
> <richih.ma...@gmail.com> wrote:
>
> > Syntax elements are detected & highlighted in the wrong places.
>
> > Two examples I have known for some time but never got around to
> > do much about them are:
>
> Posting sooner rather than later is always better. That almost rhymes.

I'll jump in here and post a problem I've been meaning to contact you
about, as well.

somecommand <<< $somevar
othercommand

Zsh's "here-string" is triggering the here-doc syntax highlighting and
therefore causes all of the remaining script to be highlighted as a
string. The attached patch fixes the problem.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@jamessan.com>

zsh.vim.diff
signature.asc

Nikolai Weibull

unread,
Jul 17, 2008, 5:27:24 PM7/17/08
to vim...@googlegroups.com
2008/7/17 James Vega <jame...@jamessan.com>:

> I'll jump in here and post a problem I've been meaning to contact you
> about, as well.
>
> somecommand <<< $somevar
> othercommand
>
> Zsh's "here-string" is triggering the here-doc syntax highlighting and
> therefore causes all of the remaining script to be highlighted as a
> string. The attached patch fixes the problem.

Fixed, although not using that exact patch. See attached for complete
patch. Bram, if you feel up to it, please apply. I've tested every
possible combination. I think. Damn I hate testing exponential
cases.

syntax.zsh.vim.here-doc.here-string.patch
Reply all
Reply to author
Forward
0 new messages