[Yakov -- ignore a similar email I mistakenly
sent to you only an hour or so ago.]
Yakov Lerner sent on 5 May 2006
> On 5/5/06, Yakov Lerner wrote:
>> On 5/5/06, Suresh Govindachar wrote:
>>>
>>> I would like to color a file as follows:
>>>
>>> Everything is "normal" except for lines whose
>>> foldlevel is different from the foldlevel of both
>>> the line above and the line below. For such lines,
>>> the color should be Color_N where N is
>>> (foldlevel/2)%7 (wherein Color_0 could be red,
>>> Color_1 could be blue etc.).
>>>
>>> I would appreciate any help toward creating a
>>> syntax file to achieve such coloring.
>>
>> I'm not big expert on syntax coloring, but I think this would
>> require expression-based syntax coloring (which does not exist
>> now, but probably would be cool).
>>
>> Alternatively, the "static" coloring would be possible. By this
>> I mean: if the file is readonly, it would be possible to
>> generate (and source) the specific syntax script specific for
>> this unique contents. (The coloring would become off when
>> contents changes).
>>
>> I don't think better solution exist for now; let someone
>> correct me.
>
> What I wrote above applies to the most generic solution
> (solution that would work for any possible folding rules).
>
> But if you don't need it super-generic, and if you have the
> specific folding specification in mind, then if you tell us your
> folding rules, then it's different. Then it might be much
> easier problem. For the specific folding, it might be possible
> to create the syntax coloring tuned for this specific folding
> setup. (Unless it's some complex expr folding, I'm afraid).
Here's what I came up with. Have tested it for the gui and found
that it works. But it stills would need to be adapted to one's
working style.
1) Run the following command to mark lines that need to be
highlighted. The marker is _____N at the end of the line,
where N is the highlight color number.
Although the command needs to be all in one line, it is written
below in multiple lines to make it easy to read.
%g/./let i = line('.') |
if((foldlevel(i) != foldlevel(i-1)) &&
(foldlevel(i) != foldlevel(i+1))) |
if(getline('.') !~ '____\d$')|
exec 'normal A_____'.foldlevel(i)/2|
endif |
endif
2) Use the following syntax file:
syn match marker /_____\d$/ contained
let i = 0
while i < 10
exec 'syn match level'.i. ' /.*_____'.i.'$/ contains=marker,todoo'
let i = i + 1
endwhile
syn match todoo /\<\(TODO\|XXX\|NOTE\|2do\)\c\>/ contained
if &background == "dark"
hi def todoo ctermbg=3 guibg=lightyellow guifg=black
hi def marker guifg=black ctermfg=7
else
hi def todoo ctermbg=3 guibg=lightyellow
hi def marker guifg=white ctermfg=7
endif
if &background == "dark"
hi def level0 ctermfg=4 cterm=bold gui=bold guifg=lightcyan
term=reverse
hi def level1 ctermfg=3 cterm=bold gui=bold guifg=lightblue
term=reverse
hi def level2 ctermfg=6 cterm=bold gui=bold guifg=lightgray
term=reverse
hi def level3 ctermfg=1 cterm=bold gui=bold guifg=wheat
term=reverse
hi def level4 ctermfg=1 cterm=bold gui=bold guifg=lightyellow
term=reverse
hi def level5 ctermfg=2 cterm=bold gui=bold guifg=lightred
term=reverse
hi def level6 ctermfg=5 cterm=bold gui=bold guifg=white
term=reverse
hi def level7 ctermfg=4 cterm=bold gui=bold guifg=lightcyan
term=reverse
hi def level8 ctermfg=2 cterm=bold gui=bold guifg=lightgreen
term=reverse
hi def level9 ctermfg=3 cterm=bold gui=bold guifg=lightblue
term=reverse
endif
if &background == "light"
hi def level0 ctermfg=1 cterm=bold gui=bold guifg=red
term=reverse
hi def level1 ctermfg=4 cterm=bold gui=bold guifg=blue
term=reverse
hi def level2 ctermfg=2 cterm=bold gui=bold guifg=darkgreen
term=reverse
hi def level3 ctermfg=3 cterm=bold gui=bold guifg=brown
term=reverse
hi def level4 ctermfg=5 cterm=bold gui=bold guifg=darkmagenta
term=reverse
hi def level5 ctermfg=6 cterm=bold gui=bold guifg=darkcyan
term=reverse
hi def level6 ctermfg=1 cterm=bold gui=bold guifg=red
term=reverse
hi def level7 ctermfg=4 cterm=bold gui=bold guifg=blue
term=reverse
hi def level8 ctermfg=2 cterm=bold gui=bold guifg=darkgreen
term=reverse
hi def level9 ctermfg=3 cterm=bold gui=bold guifg=brown
term=reverse
endif
That's it! Tested to work on the gui, but needs to be adapted to
one's style.
--Suresh