4

参考链接, 在 Emacs 的 C/C++ 模式下,将 #if 0...#endif 块中的代码面更改为注释面

我尝试了代码,但它似乎不起作用。我的 emacs 版本是 Linux 上的 GNU Emacs 21.3.1。

请你让我知道我哪里出错了。

TIA

4

1 回答 1

3

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-modecpp-edit-list。我按照我想要的交互方式进行了设置,然后查看了cpp-edit-list结果C-h v

于 2011-08-27T16:52:56.627 回答