开发者

change color of code within #if 0 ... #endif block in C/C++ mode in Emacs 21.3.1

开发者 https://www.devze.com 2023-03-30 11:51 出处:网络
With refe开发者_Go百科rence to the link, In C/C++ mode in Emacs, change face of code in #if 0...#endif block to comment face.

With refe开发者_Go百科rence to the link, In C/C++ mode in Emacs, change face of code in #if 0...#endif block to comment face.

I tried the code but it doesnot seem to be working. My emacs version is GNU Emacs 21.3.1 on Linux.

Please can you let me know where I am going wrong.

TIA


cpp-highlight-mode can be made to work without user interaction. This is how I have mine set up:

(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)

The key is figuring out that cpp-highlight-mode looks at cpp-edit-list. I set things up the way I wanted the interactive way and then looked at the cpp-edit-list that resulted with C-h v.

0

精彩评论

暂无评论...
验证码 换一张
取 消