In c-mode, I would like all lines beginning with

exec sql

to have that expression grey and the rest of the line in the default face. How might I achieve that?

1 Answer 1


The following will do something similar to what you asked for.

(let ((re "^[   ]*\\(exec sql\\)\\(.*\\)$"))
    (font-lock-add-keywords 'c-mode `((,re 1 font-lock-preprocessor-face t)))
    (font-lock-add-keywords 'c-mode `((,re 2 font-lock-string-face t))))

The numbers represent subexpression matches, and the t mean that already present fontification should be overridden. Have a look at the documentation of font-lock-keywords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.