Shading alternating patterns.

2006-10-10 Thread Aaron
I've been swapping my subscribed addresses, so I apologize if this got 
posted more than once.


My question is casual, but I wasn't able to find anything on the FAQs or
Google, so I hope someone here can tell me if I'm nuts or not.

In my ideal world (which, so far, Vim has done an excellent job creating
for me), CSS definitions would be lightly, alternatingly shaded. Here at
work, we format our CSS files like so:

.selector { property: value; property: value;
property: value; }
.selector { property: value; }
.selector { property: value; property: value;
property: value; property: value; }

You can see immediately that it is easy enough to scan down the left
column to find the selector you're interested in, but it's a bit more
difficult to see where one definition's property list starts and
another's ends (especially with syntax highlighting in there).

Is there some way, perhaps through a syntax rule, or rules, to have Vim
shade the background of *alternating* CSS definitions, assuming this
file format?

I'm handy with regex but I don't know if Vim's syntax system is even up
to the task. A function that ran against the buffer would be fine, too.

Thanks!

--
Aaron


Re: Shading alternating patterns.

2006-10-10 Thread Tim Chase

 Is there some way, perhaps through a syntax rule, or
 rules, to have Vim shade the background of *alternating*
 CSS definitions, assuming this file format?

While I'm not sure the below will solve it, I've pasted in
some dialog from Benji Fisher and Tony Mechelynck (from back
in February of this year, which I saved as I thought it was
a nifty stunt) regarding the highlighting of alternate
*lines*.  One might be able to use this as a foundation for
doing alternate CSS-rule-blocks:

BF I have not used syntax much either, but I decided to test
BF this.  I think what you want is (two :hi lines and)
BF something like this:
BF
BF :syn match Oddlines ^.*$ contains=ALL nextgroup=Evenlines 
skipnl
BF :syn match Evenlines ^.*$ contains=ALL nextgroup=Oddlines 
skipnl

BF
BF In other words, drop transparent and add skipnl.  I
BF tested it with
BF
BF :syn clear
BF
BF first; I am not sure how well it will work without that.
AM
AM I agree about skipnl.
AM
AM Got it to work on text files, as follows (on W32)
AM
AM  ~/vimfiles/after/syntax/text.vim
AM hi default Oddlines ctermbg=grey guibg=#808080
AM hi default Evenlines cterm=NONE gui=NONE
AM
AM syn match Oddlines ^.*$ contains=ALL nextgroup=Evenlines skipnl
AM syn match Evenlines ^.*$ contains=ALL nextgroup=Oddlines skipnl
AM
AM  $VIM/vimfiles/after/filetype.vim
AM augroup filetypedetect
AM  au BufRead,BufNewFile *.txt setf text
AM augroup END
AM
AM  ~/vimfiles/colors/almost-default.vim
AM [...]
AM hi Oddlines ctermbg=yellow guibg=#99
AM hi Evenlines ctermbg=magenta guibg=#FFCCFF
AM [...]
AM
AM Notes:
AM 1. filetype.vim in an after-directory and with :setf
AM to avoid overriding already-detected special .txt files.
AM 2. With default before the highlight name in the syntax
AM file (but not without it) the colors from the colorscheme
AM (invoked from the vimrc) are used. (Without a colorscheme,
AM the default colors from the syntax file are still used.)
AM 3. Haven't succeeded (but haven't much tried) to make it
AM work for a more complex filetype with an already defined
AM syntax like HTML
AM 4. After entering the above changes, Vim must be restarted
AM for them to take effect.

Hope it helps give you some grounds from which to find a
solution (even if I think Tony's a tad messed-in-the-head for 
choosing yellow/magenta for alternating colors ;-)


-tim







Re: Shading alternating patterns.

2006-10-10 Thread A.J.Mechelynck

Aaron wrote:
I've been swapping my subscribed addresses, so I apologize if this got 
posted more than once.


My question is casual, but I wasn't able to find anything on the FAQs or
Google, so I hope someone here can tell me if I'm nuts or not.

In my ideal world (which, so far, Vim has done an excellent job creating
for me), CSS definitions would be lightly, alternatingly shaded. Here at
work, we format our CSS files like so:

.selector { property: value; property: value;
property: value; }
.selector { property: value; }
.selector { property: value; property: value;
property: value; property: value; }

You can see immediately that it is easy enough to scan down the left
column to find the selector you're interested in, but it's a bit more
difficult to see where one definition's property list starts and
another's ends (especially with syntax highlighting in there).

Is there some way, perhaps through a syntax rule, or rules, to have Vim
shade the background of *alternating* CSS definitions, assuming this
file format?

I'm handy with regex but I don't know if Vim's syntax system is even up
to the task. A function that ran against the buffer would be fine, too.

Thanks!



I don't know, but there is an easy way to find where one particular definition 
starts and ends:


1. Place the cursor on the opening brace (e.g. with /{ )
2. Hit V (i.e. shift-v) to enter linewise Visual mode
3. Hit % to move the cursor to the closing brace.

The whole selector and property list is now highlighted. You can even hit Esc 
to quit Visual mode and go back to it later with gv



Best regards,
Tony.


Re: Shading alternating patterns.

2006-10-10 Thread Aaron

Tim Chase wrote:
   Is there some way, perhaps through a syntax rule, or
   rules, to have Vim shade the background of *alternating*
   CSS definitions, assuming this file format?

 While I'm not sure the below will solve it, I've pasted in
 some dialog from Benji Fisher and Tony Mechelynck (from back
 in February of this year, which I saved as I thought it was
 a nifty stunt) regarding the highlighting of alternate
 *lines*.  One might be able to use this as a foundation for
 doing alternate CSS-rule-blocks:

 BF I have not used syntax much either, but I decided to test
 BF this.  I think what you want is (two :hi lines and)
 BF something like this:
 BF
 BF :syn match Oddlines ^.*$ contains=ALL nextgroup=Evenlines skipnl
 BF :syn match Evenlines ^.*$ contains=ALL nextgroup=Oddlines skipnl
 BF
 BF In other words, drop transparent and add skipnl.  I
 BF tested it with
 BF
 BF :syn clear
 BF
 BF first; I am not sure how well it will work without that.
 AM
 AM I agree about skipnl.
 AM
 AM Got it to work on text files, as follows (on W32)
 AM
 AM  ~/vimfiles/after/syntax/text.vim
 AM hi default Oddlines ctermbg=grey guibg=#808080
 AM hi default Evenlines cterm=NONE gui=NONE
 AM
 AM syn match Oddlines ^.*$ contains=ALL nextgroup=Evenlines skipnl
 AM syn match Evenlines ^.*$ contains=ALL nextgroup=Oddlines skipnl
 AM
 AM  $VIM/vimfiles/after/filetype.vim
 AM augroup filetypedetect
 AM au BufRead,BufNewFile *.txt setf text
 AM augroup END
 AM
 AM  ~/vimfiles/colors/almost-default.vim
 AM [...]
 AM hi Oddlines ctermbg=yellow guibg=#99
 AM hi Evenlines ctermbg=magenta guibg=#FFCCFF
 AM [...]
 AM
 AM Notes:
 AM 1. filetype.vim in an after-directory and with :setf
 AM to avoid overriding already-detected special .txt files.
 AM 2. With default before the highlight name in the syntax
 AM file (but not without it) the colors from the colorscheme
 AM (invoked from the vimrc) are used. (Without a colorscheme,
 AM the default colors from the syntax file are still used.)
 AM 3. Haven't succeeded (but haven't much tried) to make it
 AM work for a more complex filetype with an already defined
 AM syntax like HTML
 AM 4. After entering the above changes, Vim must be restarted
 AM for them to take effect.

 Hope it helps give you some grounds from which to find a
 solution (even if I think Tony's a tad messed-in-the-head for choosing
 yellow/magenta for alternating colors ;-)

 -tim

Thanks much, Tim, I will experiment with some of this and see what
happens! Thanks also to Tony and Benji for coming up with this in the
first place.

--
Aaron
The Dude abides.


Re: Shading alternating patterns.

2006-10-10 Thread A.J.Mechelynck

Peter Hodge wrote:

Hello Aaron,

You could do something like this:

  syn match Sel1 /^\.selector/ nextgroup=Items1 skipwhite
  syn region Items1 start=/{/ end=/}/ contained keepend
\ nextgroup=Sel2 skipwhite skipempty

  hi Sel1 guibg=#44
  hi Items1 guibg=#44

  syn match Sel2 /^\.selector/ contained nextgroup=Items2 skipwhite
  syn region Items2 start=/{/ end=/}/ contained keepend

  hi Sel2 guibg=#004400
  hi Items2 guibg=#004400

That will get you started.

regards,
Peter



Black on dark blue, or black on dark green, won't be very visible. I'm 
throwing no bird names around though; if Aaron doesn't like the colours, he 
can change them.


See also :help :hi-default: Highlight colours defined in a syntax script 
should have the default keyword, otherwise they will override anything a 
colorscheme might already have set for those same groups.



Best regards,
Tony.