syntax: highlighting part of the file based on line number ?

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

syntax: highlighting part of the file based on line number ?

Sylvain Viart
Hi,

here is my sample of text :

68 func! PopUpBoxClear(name)" {{{
69     " clear box area content
70     call PopUpBoxVse+----------+ 1)
71     exe "norm r "   |un        |
72                     |deux      |
73     " the cursor is |trois     |insided the box at the top left corner
74 endf" }}}           |4         |
75 " PopUpBoxVselect() |          |ox visual area " {{{
76 "  inside  0 or 1, i+----------+e want the box to be selected with
the border or not
77 func! PopUpBoxVselect(name, inside)
78     let top_l = b:pbox_{a:name}_line + (a:inside ? 1 : 0)

I want to colorize specialy, lines 70 to 76.  Making the code in gray,
as disabled text, and do some more highlighting in the text box, drawn
above the text. The rest of the code, other lines, should keep its
syntax highlighting.

I don't expect you give me the solution, I just want to know if its
possible to use the syntax engine for that, and get some hints. :-)

I've already found :
    :match GroupName /\%nl/
to highlight a specific line number

I almost never used highlighting programming in vim, and the help
chapter on this topic, is an huge part, I don't want to spend 4 hours
testing and reading just to face an engine limitation. :-\

I suppose I can do a region with  lines number range, wrapping the lines
of the box, and do some more syntax rules inside that region, right ?

Regards,
Sylvain.

Reply | Threaded
Open this post in threaded view
|

Re: syntax: highlighting part of the file based on line number ?

Aaron Griffin
On 8/3/05, Sylvain Viart <[hidden email]> wrote:

> 70     call PopUpBoxVse+----------+ 1)
> 71     exe "norm r "   |un        |
> 72                     |deux      |
> 73     " the cursor is |trois     |insided the box at the top left corner
> 74 endf" }}}           |4         |
> 75 " PopUpBoxVselect() |          |ox visual area " {{{
> 76 "  inside  0 or 1, i+----------+e want the box to be selected with
>
> I want to colorize specialy, lines 70 to 76.  Making the code in gray,
> as disabled text, and do some more highlighting in the text box, drawn
> above the text. The rest of the code, other lines, should keep its
> syntax highlighting.

If there is any indication that these lines are disabled (the
"+--------+" stuff maybe?) you can use syntax highlighting from C
style comments to make your own rule... other than that I don't think
it can be done based on line numbers as it matches text
Reply | Threaded
Open this post in threaded view
|

Re: syntax: highlighting part of the file based on line number ?

Sylvain Viart
Aaron Griffin wrote:

>On 8/3/05, Sylvain Viart <[hidden email]> wrote:
>  
>
>>70     call PopUpBoxVse+----------+ 1)
>>71     exe "norm r "   |un        |
>>72                     |deux      |
>>73     " the cursor is |trois     |insided the box at the top left corner
>>74 endf" }}}           |4         |
>>75 " PopUpBoxVselect() |          |ox visual area " {{{
>>76 "  inside  0 or 1, i+----------+e want the box to be selected with
>>
>>I want to colorize specialy, lines 70 to 76.  Making the code in gray,
>>as disabled text, and do some more highlighting in the text box, drawn
>>above the text. The rest of the code, other lines, should keep its
>>syntax highlighting.
>>

Ok, After some testing it seems that line and column numbered pattern
are working well. :-)
Here is my sample text :

      1 " popup_box.vim
      2 " vim: set fdm=marker cms=\"\ %s:
      3 "
      4 " Vim primitive for drawing a popup box above the current textarea
      5 " Author: Sylvain Viart ([hidden email])
      6 "
      7 "        +------------+
      8 "        |une         |
      9 "        |Deux        |
     10 "        |3           |
     11 "        |quatre      |
     12 "        |            |
     13 "        +------------+
     14 " call PopUpBoxDraw(6,10, 5)

And my highlighting rules :

syntax clear pboxBox pboxBoxBorder pboxBoxBorderL pboxBoxBorderR
pboxBoxOuterL pboxBoxOuterR

syntax region pboxBox start="\%6l" end="\%14l"
contains=pboxBoxBorder,pboxBoxBorderL,pboxBoxBorderR,pboxBoxOuterL,pboxBoxOuterR
containedin=ALL

syntax match pboxBoxBorderL /\%10v./ contained
syntax match pboxBoxBorderR /\%23v./ contained
syntax match pboxBoxBorder /+-\++/ contained
syntax match pboxBoxOuterL /.*\%<10v/ contained
syntax match pboxBoxOuterR /\%>23v.*/ contained

hi link pboxBoxBorder Type
hi link pboxBoxBorderL Constant
hi link pboxBoxBorderR Keyword
hi link pboxBoxOuterL Error
hi link pboxBoxOuterR Error

I still have some boundary glitch, for example pboxBoxOuterL doesn't
match the virtual column 9 witch should be part of the match pattern to
my opinion.

And also with the region which I should start one line above the boxed
area to have the pboxBoxBorder matching the starting box pattern.

Regards,
Sylvain.