Highlighting c-like for-loops in bash

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Highlighting c-like for-loops in bash

Hakim Benoudjit

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:


<a imageanchor="1" href="about:invalid#zClosurez" style="clear: left; margin-bottom: 1em; margin-right: 1em; float: left;">screenshot.png


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/90f2172a-314c-4155-9d58-fac57d3650d9%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Highlighting c-like for-loops in bash

Charles Campbell-2
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 <[hidden email]
> <mailto:[hidden email]>> 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

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/8937bba7-1ece-8d2e-31c4-8731e37474fc%40drchip.org.