Highlighting c-like for-loops in bash

瀏覽次數:25 次
跳到第一則未讀訊息

Hakim Benoudjit

未讀,
2020年5月13日 下午4:28:262020/5/13
收件者:vim_use

Hi,


I wasn't sure if this was a bug or not, so I've updated my Vim version to 8.2 on Ubuntu 18.04.

And, as you can see below, the variables in the standard for-loop aren't highlighted as they are in the following for loop:


screenshot.png


Charles Campbell

未讀,
2020年5月20日 下午1:49:492020/5/20
收件者:Hakim Benoudjit、vim...@googlegroups.com
Hakim Benoudjit wrote:
> Hi,
>
> Thanks for your email.
> Please find attached the small script bash I tested where the
> variables i, j, limit_t, limit_j are unfortunately not highlighted in
> the standard for-loop, in contrast to the label variable in the
> for-each-like loop.
>
> Hakim.
>
> On Wed, May 20, 2020 at 4:47 AM Charles Campbell <camp...@drchip.org
> <mailto:camp...@drchip.org>> wrote:
>
> Hakim Benoudjit wrote:
> >
> > Hi,
> >
> >
> > I wasn't sure if this was a bug or not, so I've updated my Vim
> version
> > to 8.2 on Ubuntu 18.04.
> >
> > And, as you can see below, the variables in the standard for-loop
> > aren't highlighted as they are in the following for loop:
> >
> >
> Hello:
>
> I'm the maintainer of syntax/sh.vim ; would you please send me an
> attachment of the code snippet you're having a problem with?
>
With the script you sent I can use hilinks.vim
(http://www.drchip.org/astronaut/vim/index.html#HILINKS) to see what's
happening.

In the for (( ... )) loop, the items inside are highlighted as shForPP ;
ie. as inside a region.  The variables themselves are not individually
identified.  The "<=" and other operators are highlighted as shTestOpr
(ie. operators).  All is normal.

In the first echo ... the variables are, again, not identified as
variables; instead, they're being shown as
shDo->shDo->shEcho->shDoubleQuote ; ie. regular string highlighting.

In the second outside loop (ie. the one with "label"), label is not
recognized as a variable.  Instead, its being recognized as being inside
a for loop (shFor), so its being highlighted correctly for that
situation.  Copying the echo "i:..." into the body of the "label" for
loop shows its highlighted the same as in the other place.

Generally, I try not to identify variables because of the potential
problems (is it really an alias? a function? etc); remember, the syntax
highlighter isn't a parser.  I do have a shVar; I'll have to see if
including it in the for loops' containment lists causes problems.

So, insofar as the variables are concerned, the highlighting is
performing nominally.

That said, there seems to be some unwanted highlighting associated with
the double quotes, and I'll look into that.

Regards,
Chip Campbell
回覆所有人
回覆作者
轉寄
0 則新訊息