Different highlighting on identical syntax stacks

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

Different highlighting on identical syntax stacks

Benjamin Fritz

I use the standard C syntax rules, but I have added a couple of rules
in my after/syntax/c.vim file to add some additional syntax folding. I
have narrowed my problem down to the following addition:

" add folding of multiline () groups
syn region SynFoldParen
      \ start="(" end=")"
      \ skip=+"\%(\\"\|[^"]\)\{-}\\\@<!"\|'[^']\{-}'\|'\\''\|//.*+
      \ transparent fold keepend extend
      \ containedin=ALLBUT,cComment,cCommentL,cString,cCppString

Using this addition, with this code::

void foo()
{
  printf("look how {braces} break highlighting!\n");
}

makes the "Constant" highlighting go away after the closing brace
('}') in the printf statement.

Without the additional fold rule, the highlighting is fine.

I have the following mapping to display the current syntax stack:

  nmap <F10>
        \ :echo '<'.synIDattr(synIDtrans(synID(line('.'),col('.'),
1)),'name').'> from:' <bar>
        \ let indent = '' <bar>
        \ for syn_id in synstack(line('.'), col('.')) <bar>
        \   echo indent.'<'.synIDattr(syn_id,"name").'>' <bar>
        \   let indent .= ' ' <bar>
        \ endfor <bar>
        \ unlet indent<CR>

Using this command, I get for the syntax stack, between the opening
double-quote and the closing brace:

<Constant> from:
<cBlock>
 <SynFoldParen>
  <cParen>
   <cString>

After the closing brace until the end quote, I get:

<> from:
<cBlock>
 <SynFoldParen>
  <cParen>
   <cString>

Even the \n gets the correct "cSpecial" highlight group:

<> from:
<cBlock>
 <SynFoldParen>
  <cParen>
   <cString>
    <cSpecial>

Everything seems correct in these last two syntax stacks, except that
highlight group that is linked to the final item in the syntax stack
does not get applied. I'm completely baffled as to why.

I thought at first that maybe the cBlock group from the function body
was ending prematurely, but this is not the case, as I can see from
the fold column (since cBlock is folded).

Syntax stacks for the places above using just the standard rules are
identical, except for the fact that SynFoldParen is missing, and the
correct linked highlight group is applied.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Different highlighting on identical syntax stacks

Ben Schmidt

Ben Fritz wrote:

> I use the standard C syntax rules, but I have added a couple of rules
> in my after/syntax/c.vim file to add some additional syntax folding. I
> have narrowed my problem down to the following addition:
>
> " add folding of multiline () groups
> syn region SynFoldParen
>       \ start="(" end=")"
>       \ skip=+"\%(\\"\|[^"]\)\{-}\\\@<!"\|'[^']\{-}'\|'\\''\|//.*+
>       \ transparent fold keepend extend
>       \ containedin=ALLBUT,cComment,cCommentL,cString,cCppString
>
> Using this addition, with this code::
>
> void foo()
> {
>   printf("look how {braces} break highlighting!\n");
> }
>
> makes the "Constant" highlighting go away after the closing brace
> ('}') in the printf statement.

Where is the 'Constant' highlighting meant to be? I don't get it. Is it
a custom syntax rule too? Or maybe some setting in your vimrc enables
it? Perhaps check your syntax/c.vim is up to date, and send us your
custom file to see if we can reproduce it? Also quote your Vim version,
perhaps, in case it's relevant.

Ben.

> Without the additional fold rule, the highlighting is fine.
>
> I have the following mapping to display the current syntax stack:
>
>   nmap <F10>
>         \ :echo '<'.synIDattr(synIDtrans(synID(line('.'),col('.'),
> 1)),'name').'> from:' <bar>
>         \ let indent = '' <bar>
>         \ for syn_id in synstack(line('.'), col('.')) <bar>
>         \   echo indent.'<'.synIDattr(syn_id,"name").'>' <bar>
>         \   let indent .= ' ' <bar>
>         \ endfor <bar>
>         \ unlet indent<CR>
>
> Using this command, I get for the syntax stack, between the opening
> double-quote and the closing brace:
>
> <Constant> from:
> <cBlock>
>  <SynFoldParen>
>   <cParen>
>    <cString>
>
> After the closing brace until the end quote, I get:
>
> <> from:
> <cBlock>
>  <SynFoldParen>
>   <cParen>
>    <cString>
>
> Even the \n gets the correct "cSpecial" highlight group:
>
> <> from:
> <cBlock>
>  <SynFoldParen>
>   <cParen>
>    <cString>
>     <cSpecial>
>
> Everything seems correct in these last two syntax stacks, except that
> highlight group that is linked to the final item in the syntax stack
> does not get applied. I'm completely baffled as to why.
>
> I thought at first that maybe the cBlock group from the function body
> was ending prematurely, but this is not the case, as I can see from
> the fold column (since cBlock is folded).
>
> Syntax stacks for the places above using just the standard rules are
> identical, except for the fact that SynFoldParen is missing, and the
> correct linked highlight group is applied.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Different highlighting on identical syntax stacks

Tony Mechelynck

On 30/01/09 01:02, Ben Schmidt wrote:

> Ben Fritz wrote:
>> I use the standard C syntax rules, but I have added a couple of rules
>> in my after/syntax/c.vim file to add some additional syntax folding. I
>> have narrowed my problem down to the following addition:
>>
>> " add folding of multiline () groups
>> syn region SynFoldParen
>>        \ start="(" end=")"
>>        \ skip=+"\%(\\"\|[^"]\)\{-}\\\@<!"\|'[^']\{-}'\|'\\''\|//.*+
>>        \ transparent fold keepend extend
>>        \ containedin=ALLBUT,cComment,cCommentL,cString,cCppString
>>
>> Using this addition, with this code::
>>
>> void foo()
>> {
>>    printf("look how {braces} break highlighting!\n");
>> }
>>
>> makes the "Constant" highlighting go away after the closing brace
>> ('}') in the printf statement.
>
> Where is the 'Constant' highlighting meant to be? I don't get it. Is it
> a custom syntax rule too? Or maybe some setting in your vimrc enables
> it? Perhaps check your syntax/c.vim is up to date, and send us your
> custom file to see if we can reproduce it? Also quote your Vim version,
> perhaps, in case it's relevant.
>
> Ben.

something (such as cConstant maybe) which is linked to Constant, I suppose.

>
>> Without the additional fold rule, the highlighting is fine.
>>
>> I have the following mapping to display the current syntax stack:
>>
>>    nmap<F10>
>>          \ :echo '<'.synIDattr(synIDtrans(synID(line('.'),col('.'),
>> 1)),'name').'>  from:'<bar>
>>          \ let indent = ''<bar>
>>          \ for syn_id in synstack(line('.'), col('.'))<bar>
>>          \   echo indent.'<'.synIDattr(syn_id,"name").'>'<bar>
>>          \   let indent .= ' '<bar>
>>          \ endfor<bar>
>>          \ unlet indent<CR>
>>
>> Using this command, I get for the syntax stack, between the opening
>> double-quote and the closing brace:
>>
>> <Constant>  from:
>> <cBlock>
>>   <SynFoldParen>
>>    <cParen>
>>     <cString>
>>
>> After the closing brace until the end quote, I get:
>>
>> <>  from:
>> <cBlock>
>>   <SynFoldParen>
>>    <cParen>
>>     <cString>
>>
>> Even the \n gets the correct "cSpecial" highlight group:
>>
>> <>  from:
>> <cBlock>
>>   <SynFoldParen>
>>    <cParen>
>>     <cString>
>>      <cSpecial>
>>
>> Everything seems correct in these last two syntax stacks, except that
>> highlight group that is linked to the final item in the syntax stack
>> does not get applied. I'm completely baffled as to why.
>>
>> I thought at first that maybe the cBlock group from the function body
>> was ending prematurely, but this is not the case, as I can see from
>> the fold column (since cBlock is folded).
>>
>> Syntax stacks for the places above using just the standard rules are
>> identical, except for the fact that SynFoldParen is missing, and the
>> correct linked highlight group is applied.
>
> >
>

Best regards,
Tony.
--
TIM: To the north there lies a cave,  the cave of Caerbannog, wherein,
carved
      in mystic runes, upon the very living rock, the last words of Olfin
      Bedwere of Rheged make plain the last resting place of the most Holy
      Grail.
                  "Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Different highlighting on identical syntax stacks

Ben Schmidt

>> Where is the 'Constant' highlighting meant to be? I don't get it. Is it
>> a custom syntax rule too? Or maybe some setting in your vimrc enables
>> it? Perhaps check your syntax/c.vim is up to date, and send us your
>> custom file to see if we can reproduce it? Also quote your Vim version,
>> perhaps, in case it's relevant.
>
> something (such as cConstant maybe) which is linked to Constant, I
> suppose.

No, I meant in the actual text. I don't see anything highlighted with my
colour settings, even without the modification, except for the 'int'
type, and placing the cursor in various places and using Dr. Chip's
hilinks plugin to show the syntax and highlight stacks doesn't show me
anything even vaguely resembling 'constant' either. So I'm not convinced
that anything is highlighted as Constant by default anyway.

(Agreeably, I am using a modified c.vim, but as I made the
modifications, I know that they shouldn't be relevant to this.)

Cheers,

Ben.




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Different highlighting on identical syntax stacks

Benjamin Fritz
In reply to this post by Ben Schmidt



On Jan 29, 6:02 pm, Ben Schmidt <[hidden email]> wrote:

> Ben Fritz wrote:
> > I use the standard C syntax rules, but I have added a couple of rules
> > in my after/syntax/c.vim file to add some additional syntax folding. I
> > have narrowed my problem down to the following addition:
>
> > " add folding of multiline () groups
> > syn region SynFoldParen
> >       \ start="(" end=")"
> >       \ skip=+"\%(\\"\|[^"]\)\{-}\\\@<!"\|'[^']\{-}'\|'\\''\|//.*+
> >       \ transparent fold keepend extend
> >       \ containedin=ALLBUT,cComment,cCommentL,cString,cCppString
>
> > Using this addition, with this code::
>
> > void foo()
> > {
> >   printf("look how {braces} break highlighting!\n");
> > }
>
> > makes the "Constant" highlighting go away after the closing brace
> > ('}') in the printf statement.
>
> Where is the 'Constant' highlighting meant to be? I don't get it. Is it
> a custom syntax rule too? Or maybe some setting in your vimrc enables
> it? Perhaps check your syntax/c.vim is up to date, and send us your
> custom file to see if we can reproduce it? Also quote your Vim version,
> perhaps, in case it's relevant.
>
> Ben.
>

I'm using Vim 7.2.88 from the "Cream" page.

My c.vim syntax file has the following heading:

" Vim syntax file
" Language: C
" Maintainer: Bram Moolenaar <[hidden email]>
" Last Change: 2008 Mar 19

I'm using the following c.vim options:

let g:c_syntax_for_h = 1
let g:c_ansi_typedefs = 1
let g:c_ansi_constants = 1

I'm sorry about the confusion of the "Constant" group...my colorscheme
has the following line:

hi link String  Constant

c.vim links the cString group to String at line 358.

Everything between the double-quotes in the printf statement except
for the "\n", on my build with just the standard syntax rules, is
highlighted as Constant. The "\n" is highlighted as "Special". But,
the highlighting changes if I introduce that one fold rule so that
*all* highlighting ends at the closing brace inside the quotes,
resuming on the next line.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Different highlighting on identical syntax stacks

Benjamin Fritz



On Jan 30, 11:38 am, Ben Fritz <[hidden email]> wrote:

> > > I use the standard C syntax rules, but I have added a couple of rules
> > > in my after/syntax/c.vim file to add some additional syntax folding. I
> > > have narrowed my problem down to the following addition:
>
> > > " add folding of multiline () groups
> > > syn region SynFoldParen
> > >       \ start="(" end=")"
> > >       \ skip=+"\%(\\"\|[^"]\)\{-}\\\@<!"\|'[^']\{-}'\|'\\''\|//.*+
> > >       \ transparent fold keepend extend
> > >       \ containedin=ALLBUT,cComment,cCommentL,cString,cCppString
>
> > > Using this addition, with this code::
>
> > > void foo()
> > > {
> > >   printf("look how {braces} break highlighting!\n");
> > > }
>
> > > makes the "Constant" highlighting go away after the closing brace
> > > ('}') in the printf statement.
>

> I'm using Vim 7.2.88 from the "Cream" page.
>
> My c.vim syntax file has the following heading:
>
> " Vim syntax file
> " Language:        C
> " Maintainer:      Bram Moolenaar <[hidden email]>
> " Last Change:     2008 Mar 19
>
> I'm using the following c.vim options:
>
> let g:c_syntax_for_h = 1
> let g:c_ansi_typedefs = 1
> let g:c_ansi_constants = 1
>
> I'm sorry about the confusion of the "Constant" group...my colorscheme
> has the following line:
>
> hi link String  Constant
>
> c.vim links the cString group to String at line 358.
>
> Everything between the double-quotes in the printf statement except
> for the "\n", on my build with just the standard syntax rules, is
> highlighted as Constant. The "\n" is highlighted as "Special". But,
> the highlighting changes if I introduce that one fold rule so that
> *all* highlighting ends at the closing brace inside the quotes,
> resuming on the next line.

So, anyone able to reproduce it now? I'm still very confused by this
behavior.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---