Hello.
I'm continuing my investigation on Vim's syntax highlight for the
following syntax rules:
:syn cluster Top contains=Block,String,Identifier
:syn region Block start=+{+ end=+}+ keepend extend [EMAIL PROTECTED]
:syn region String start=+"+ end=+"+ contains=Identifier
:syn region Identifier start=+\${+ end=+}+ extend
and I've found that this code
{ block "string } extra
is highlighted not exactly as I want it to be. Highlight is as follows:
{ block "string } extra
SSSSSSSSS
The problem is that closing brace '}' is highlighted as a String because
Block does not have any kind of highlight and contained String region is
forcefully terminated at the same character as enclosing Block is.
So, I thought, that it would be logical that if I would limit Block
highlight to be completely inside braces then String would not highlight
brace character itself. It appears to be not the case. Here is a new
matching rule for Block:
:syn region Block start=+{+hs=e end=+}+he=s-1 keepend extend [EMAIL PROTECTED]
Problem is that when a region is terminated because an enclosing keepend
region is terminated, then the contained region highlight end is at the
same point as the keepend region match end is, while, from my point of
view, it should be where the keepend region highlight end is.
Here is a patch that makes Vim do as I want. Version 1 is for an
original syntax.c as it is in CVS now. Version 2 is for syntax.c that
was modified by my previous patch from "extend inside normal inside
keepend" e-mail.
Ilya Bobir
Index: syntax.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/syntax.c,v
retrieving revision 1.62
diff -c -r1.62 syntax.c
*** syntax.c 26 Apr 2006 23:58:59 -0000 1.62
--- syntax.c 22 Sep 2006 19:38:24 -0000
***************
*** 2564,2569 ****
--- 2564,2570 ----
{
int i;
lpos_T maxpos;
+ lpos_T maxpos_h;
stateitem_T *sip;
/*
***************
*** 2583,2595 ****
break;
maxpos.lnum = 0;
for ( ; i < current_state.ga_len; ++i)
{
sip = &CUR_STATE(i);
if (maxpos.lnum != 0)
{
limit_pos_zero(&sip->si_m_endpos, &maxpos);
! limit_pos_zero(&sip->si_h_endpos, &maxpos);
limit_pos_zero(&sip->si_eoe_pos, &maxpos);
sip->si_ends = TRUE;
}
--- 2584,2597 ----
break;
maxpos.lnum = 0;
+ maxpos_h.lnum = 0;
for ( ; i < current_state.ga_len; ++i)
{
sip = &CUR_STATE(i);
if (maxpos.lnum != 0)
{
limit_pos_zero(&sip->si_m_endpos, &maxpos);
! limit_pos_zero(&sip->si_h_endpos, &maxpos_h);
limit_pos_zero(&sip->si_eoe_pos, &maxpos);
sip->si_ends = TRUE;
}
***************
*** 2600,2605 ****
--- 2602,2614 ----
|| (maxpos.lnum == sip->si_m_endpos.lnum
&& maxpos.col > sip->si_m_endpos.col)))
maxpos = sip->si_m_endpos;
+ if (sip->si_ends
+ && (sip->si_flags & HL_KEEPEND)
+ && (maxpos_h.lnum == 0
+ || maxpos_h.lnum > sip->si_h_endpos.lnum
+ || (maxpos_h.lnum == sip->si_h_endpos.lnum
+ && maxpos_h.col > sip->si_h_endpos.col)))
+ maxpos_h = sip->si_h_endpos;
}
}
*** syntax.c Fri Sep 22 22:39:57 2006
--- syntax.c.new Fri Sep 22 22:26:23 2006
***************
*** 2574,2579 ****
--- 2574,2580 ----
{
int i;
lpos_T maxpos;
+ lpos_T maxpos_h;
stateitem_T *sip;
/*
***************
*** 2593,2605 ****
break;
maxpos.lnum = 0;
for ( ; i < current_state.ga_len; ++i)
{
sip = &CUR_STATE(i);
if (maxpos.lnum != 0)
{
limit_pos_zero(&sip->si_m_endpos, &maxpos);
! limit_pos_zero(&sip->si_h_endpos, &maxpos);
limit_pos_zero(&sip->si_eoe_pos, &maxpos);
sip->si_ends = TRUE;
}
--- 2594,2607 ----
break;
maxpos.lnum = 0;
+ maxpos_h.lnum = 0;
for ( ; i < current_state.ga_len; ++i)
{
sip = &CUR_STATE(i);
if (maxpos.lnum != 0)
{
limit_pos_zero(&sip->si_m_endpos, &maxpos);
! limit_pos_zero(&sip->si_h_endpos, &maxpos_h);
limit_pos_zero(&sip->si_eoe_pos, &maxpos);
sip->si_ends = TRUE;
}
***************
*** 2610,2615 ****
--- 2612,2624 ----
|| (maxpos.lnum == sip->si_m_endpos.lnum
&& maxpos.col > sip->si_m_endpos.col)))
maxpos = sip->si_m_endpos;
+ if (sip->si_ends
+ && (sip->si_flags & HL_KEEPEND)
+ && (maxpos_h.lnum == 0
+ || maxpos_h.lnum > sip->si_h_endpos.lnum
+ || (maxpos_h.lnum == sip->si_h_endpos.lnum
+ && maxpos_h.col > sip->si_h_endpos.col)))
+ maxpos_h = sip->si_h_endpos;
}
}