Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would know if it is possible to set C/C++ macros to be a specific color when the files are opened in emacs.

share|improve this question
Why do you link to the Wikipedia article for SANs with the label emacs? – N.N. Mar 4 '12 at 19:12

Put this code in your .emacs startup file:

(require 'font-lock)

(defun my-c-and-c++-mode-hook ()
  "Added to c-mode-hook and c++-mode-hook.  This function runs when you visit
a C or C++ file."
  (set-face-foreground 'font-lock-constant-face "blue")

(add-hook 'c++-mode-hook 'my-c-and-c++-mode-hook)
(add-hook 'c-mode-hook 'my-c-and-c++-mode-hook)

You can change the color "blue" to a RGB specification, such as "#f88", if you want to get a color that Emacs doesn't have a predefined name for.

share|improve this answer
Unfortunately, the face font-lock-constant-face applies to more than just macros. Any numeric literal, such as 123 or 3.14, will appear in that face also. – Fran May 2 '12 at 18:10
You could define your own custom face to use in the above code, like this: (set-face-foreground (make-face 'my-macro-face) "blue"). Then change font-lock-constant-face above to my-macro-face. – Fran May 14 '12 at 16:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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