Search code examples
emacssyntaxhighlighting

Customizing emacs syntax coloring


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.


Solution

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