CC-mode's job is fundamentally impossible.
Hey, don't be like that! ;-) Yes, people can deliberately break it with
the likes of HELLO and WORLD, but the more modest aim of CC Mode, to deal
properly with anything reasonable, is doable.
I think I can fix this by setting a neutral syntax-table property on
anything obtrusive in a CPP construct. Here's a first shot at doing
that:
;; Set syntax table properties on a CPP (logical) line, so that it becomes
;; "syntactically neutral". This means that lines such as:
;;
;; #warning for isn't a keyword.
;; ^
;; and
;;
;; #define RBRACE }
;; ^
;; won't interact syntactically with the rest of the file.
(defun c-neutralize-CPP-line (beg end)
(let (s)
(while
(progn
(setq s (parse-partial-sexp beg end -1))
(cond
((< (nth 0 s) 0) ; found an unmated ),},]
(c-put-char-property (1- (point)) 'syntax-table '(1)) ;
"punctuation".
t)
((or (nth 3 s) (nth 4 s)) ; In a string or comment.
(c-put-char-property (nth 8 s) 'syntax-table '(1))
t)
((> (nth 0 s) 0) ; In a (,{,[
(c-put-char-property (nth 1 s) 'syntax-table '(1))
t)
(t nil))))))