Customizing emacs syntax coloring

萝らか妹 提交于 2020-01-24 21:25:05

问题


I can't figure out how to set emacs to use just two colors, one for comments and the other for the regular code across all language modes. There is, of course the possibility to set the colors of each block except comment to the second color, but I'm not sure what ALL available blocks are.

Until now all I found is (setq-default global-font-lock-mode nil) but this also kills coloring for comments.

I guess this must be fairly easy for time-proven emacs warriors.


回答1:


See the angry fruit salad wiki page to wash out font-lock faces. You can modify the code slightly to exempt comments.

If you really must remove all colors this code will do it for all faces except warning and comment:

(defun decolorize-font-lock ()
  "remove all colors from font-lock faces except comment and warning"
  (let ((fg (face-attribute 'default :foreground))
        (bg (face-attribute 'default :background)))
    (mapc (lambda (face)
            (when face
              (set-face-attribute face nil
                                  :foreground fg
                                  :background bg)))
          (mapcar (lambda (f)
                    (if (and (string-match "^font-lock" (symbol-name f))
                             (not (string-match "-comment\\|-warning" (symbol-name f))))
                        f
                      nil))
                  (face-list)))))

(decolorize-font-lock)



回答2:


color-theme is a handy "framework" for defining syntax and windows coloring in a language-agnostic manner.

Getting started with it is as easy as hacking one of is default themes. One typical passage of them goes like this:

 (font-lock-builtin-face ((t (:foreground "#000080"))))
 (font-lock-keyword-face ((t (:bold t :foreground "#000080")))) 
 (font-lock-function-name-face ((t (:foreground "#000080"))))
 (font-lock-variable-name-face ((t (:bold t :foreground "#000080"))))
 (font-lock-string-face ((t (:foreground "#177A12"))))
 (font-lock-comment-face ((t (:italic t :foreground "#716F6F"))))
 (font-lock-constant-face ((t (:italic t :foreground "#660E7A"))))
 (font-lock-doc-string-face ((t (:foreground "DarkOrange"))))


来源:https://stackoverflow.com/questions/9620613/customizing-emacs-syntax-coloring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!