Wednesday, September 15, 2010

Re: can't highlight background of entire region, only where text is

On Thu, September 16, 2010 12:10 am, hsitz wrote:
> I have Vim documents that have codeblock areas that use 'syntax
> include' regions to have different syntax highlighting from the main
> document. For example, I have a syntax region named 'pyregion' defined
> that I use when I input Python code. The pyregion areas of the
> document are then highlighted using setup in Python's syntax file,
> while the area outside the region uses the syntax file of the main
> document.
>
> I want to have the entire background in the Python region be shaded a
> different color to distinguish it from the non-Python areas of the
> document. I can get part of the way there by entering a background for
> the entire python region:
>
> :highlight pyregion guibg=#555555
>
> But the command above changes the background only for areas that have
> text characters on them, not for entire background of the region,
> which seems still to be governed like rest of document by the
> background color defined for the 'Normal' group. This is okay -- it
> does draw attention to the region, but it has a blotchy look because
> only the code characters themselves have different background, not the
> entire band of the region across the screen.
>
> Is there some way to get a uniform band of a different background
> color across the whole region, not just portion of region where there
> are characters?

I think, syntax highlighting is restricted only to areas, that are filled
with text. A simple way would be to append trailing spaces in your pyregion
so that the "whole" line will be colord.

Another way of doing this would be with the help of signs. However, I
don't know a pragmatic way of doing so for certain syntax regions.

Long ago, I created a plugin called BackgroundColor, that uses signs for
coloring whole lines. That could be useful in your case. However this
has some drawbacks:
- you have to manually color each region
- it won't grow, if the region changes
The first point could be applied by using some autocommand like this:
g/^./:if (synIDtrans(synID(line('.'),1,1))==hlID('pyregion'))|exe
":Yellow"|endif
(one line)
which checks for each line in the buffer, whether the first column belongs
to the pyregion syntax region and if so, colors the line yellow.
But as I said, this will get out of sync, as soon as you enter linebreaks
in your region. So I think, this plugin is not particular well suited for
your case.

I hear a lot about the txtfmt plugin, which seems to be very advanced.
But I don't know, whether it can help in your scenario, when you want
to color whole lines. Brett, probably knows better.

regards,
Christian

--
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

No comments: