参考链接, In C/C++ mode in Emacs, change face of code in #if 0...#endif block to comment face
我尝试了代码,但似乎没有用。我的emacs版本是Linux上的GNU Emacs 21.3.1。
请你让我知道我哪里出错了。
TIA
答案 0 :(得分:2)
cpp-highlight-mode
可以在没有用户互动的情况下工作。这就是我设置的方式:
(defun cpp-highlight-if-0/1 ()
"Modify the face of text in between #if 0 ... #endif."
(interactive)
(setq cpp-known-face '(background-color . "dim gray"))
(setq cpp-unknown-face 'default)
(setq cpp-face-type 'dark)
(setq cpp-known-writable 't)
(setq cpp-unknown-writable 't)
(setq cpp-edit-list
'((#("1" 0 1
(fontified nil))
nil
(background-color . "dim gray")
both nil)
(#("0" 0 1
(fontified nil))
(background-color . "dim gray")
nil
both nil)))
(cpp-highlight-buffer t))
(defun jpk/c-mode-hook ()
(cpp-highlight-if-0/1)
(add-hook 'after-save-hook 'cpp-highlight-if-0/1 'append 'local)
)
(add-hook 'c-mode-common-hook 'jpk/c-mode-hook)
关键是要弄清楚cpp-highlight-mode
关注cpp-edit-list
。我按照我想要的方式设置了交互方式,然后查看cpp-edit-list
产生的C-h v
。