emacs tweak

In my old project there used to be many #if 0 .. #endif which does not fall in to the comment-face of the c-mode. This always confuses me. It would be good if that block is colored like a comment. So that i can just ignore that place.

I wrote the following elisp code which adds the #if 0 section to the comment section keywords of the c-mode.
(font-lock-add-keywords
'c-mode
'(("\s-*#\s-*if\s-*0\s-*n\(.*n\)*?\s-*#\s-*endif\s-*" 0 font-lock-comment-face append)))

I have left \s-* in many places as it is because even using back reference does not improve any readability.

~ by skalyanasundaram on January 23, 2009.

3 Responses to “emacs tweak”

  1. or u can use gvim and get all these out of the box ;-)

  2. Nice one !

  3. Sankar: Oh really? vim supports this? what happens if the macro has to be processed first.

    For example I have,
    #define FALSE 0
    and
    #if FALSE
    ..
    #endif
    what will happen, would vim interpret all of this?

    And to answer your question, I am not interested to operate my fingers just because my slippers are slightly not fit. ;)
    or even,
    Just to get the cool air to my room, i would fix a AC, i wont remove my ceiling. ;)

Leave a Reply