I'm generating a C source file from a Mako template. Mako templates have directives similar to C preprocessor directives, except that they start with % instead of #. For example:
%if some_condition:
/* Condition is true */
%else:
/* Condition is false */
%endif
When editing the template source, those directives play havoc with cc-mode's font locking and automatic indentation.
Is there a way to tell cc-mode that it should handle lines that start with a % in the same way as preprocessor lines (that start with a #)?
There is probably a simpler way, but since cc-mode prepares the fontification stuff at compile time, I'm not sure how you would get the fontification without declaring a derived cc-mode (without simply adding them all via
font-lock-add-keywords).The indentation could be modified alone by just setting the
c-opt-*variables below in yourc-mode-hook, I believe, and not bothering with the rest. But, here is an example derived mode that will fontify your preprocessor statements and provide the proper indentation (hopefully), after callingmako-modefrom your buffer.