Monday, September 19, 2011

How to highlight #if 0 in emacs

In vim, the editor can highlight the #if 0 ... #endif block, which emacs lacks. I did some digs in the web, and find a solution, with some slight modifications.
Here are the Original Post.
Just add the below code snippet to your ~/.emacs:
(defun my-cpp-highlight ()
  "highlight c/c++ #if 0 #endif macros"
  ;; (interactive)
  (setq cpp-known-face 'default)
  (setq cpp-unknown-face 'default)
  (setq cpp-known-writable 't)
  (setq cpp-unknown-writable 't)
  (setq cpp-edit-list '(("0" font-lock-comment-face default both)
                        ("1" default font-lock-comment-face both)))
  (cpp-highlight-buffer t))

(add-hook 'c-mode-common-hook 'my-cpp-highlight)

And your emacs will highlight the #if 0 ... #endif block for you.:)

No comments: