Author Topic: Color coding lexer for unix diff files  (Read 7286 times)

LBCEi

  • Senior Community Member
  • Posts: 269
  • Hero Points: 21
Color coding lexer for unix diff files
« on: August 11, 2007, 12:31:14 AM »
Has anyone out there successfully set up a color coding lexer for files containing Unix style diff listings?

I started one but without much success.

I'd like to color all lines starting with '<' red and all lines starting with '>' blue.  Seems simple enough but I can't figure out how to do it.

I'd appreciate any help or suggestions you all can provide.

Thanks
Les

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: Color coding lexer for unix diff files
« Reply #1 on: August 11, 2007, 09:40:53 AM »
I afraid that's not so easy. AFAIK only the 'line comment' item of a lexer supports full line colorization.
However, there is a certain demand for diff/patch file built-in support. So maybe one day...
You could use the attached macro stuff to get 'manual' colorization. It's better than nothing ;)
I hope the code is not too difficult and self-explaining.
Basically you could abuse the 'hilite match' feature or the lineflags to 'colorize' lines in a (diff) file besides one (1) appropriate line comment setting in your diff lexer.
The hillite match variant also provides 'find-next/prev' support to step thru the corresponding lines which could be helpful.

Have fun,
HS2

LBCEi

  • Senior Community Member
  • Posts: 269
  • Hero Points: 21
Re: Color coding lexer for unix diff files
« Reply #2 on: August 14, 2007, 01:04:23 AM »
That's exactly what I found (not so easy) -- I set the line comment character to '>' and achieved part of what I wanted but couldn't figure a way to do the '<'.

It looks like the macro will do what I want -- I'll play with the different options you suggested and see what works best for me.

This should be lots more convenient than the way I've been doing it (with a Word macro) since, when I'm working with code, I almost always have SE open but not always Word.  The possibility of making it "automatic" with a _buffer_add_* callback is also intriguing.  This should also help me get a little bit more of my toe in the water of SE macros. 

Would you recommend using the macro instead of a lexer or in addition to the lexer?

Thanks
Les
« Last Edit: August 14, 2007, 01:11:16 AM by LBCEi »

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: Color coding lexer for unix diff files
« Reply #3 on: August 14, 2007, 01:36:24 AM »
Hmm - when using the MODIFIED/INSERTED lineflag hack I think I'd use the line comment color in addition b/c it provides full line colorization.
When using the search hilite method I'd use it anyway to get a 2nd color.
So I'd use the macro as 'extension' to the lexer.

A better solution would be if there is another 'User Line Comment' item in the comment setup incl. associated color coding.
This would allow to setup a simple lexer for diff/patch files and - very cool - I could get my 'private' line comments (e.g. using a special prefix) in a C-file colorized differently...

HS2

LBCEi

  • Senior Community Member
  • Posts: 269
  • Hero Points: 21
Re: Color coding lexer for unix diff files
« Reply #4 on: August 14, 2007, 03:29:20 AM »
Thanks for the additional insights.

A "user" line comment -- with a different coloring than the "normal" line comment would be a cool feature (e.g. for stuff commented out with "//TEST", "//TODO", etc.).

It would also be nice to be able to define multiple line comments especially for the "user" line comment.  Even a single "user" line comment would be OK -- one could just use (for example):  "//LB TODO", "//LB TEST", etc.

Perhaps an even more useful (i.e., general) approach would be allowing multiple "User" tokens, on the Color Coding Setup Tokens tab instead of the Comments tab, with options for "color token only" or "color entire line" or "color until other token found" (with a place to select the "other token").

Of course the oft requested ability to use general expressions to define tokens would be REALLY great. 

I guess this is morphing into a feature request -- hopefully the SE team will take notice.  :)

Regards and thanks again
Les