capt
capt

Reputation: 159

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.

Upvotes: 1

Views: 1033

Answers (2)

deprecated
deprecated

Reputation: 5252

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

Upvotes: 0

event_jr
event_jr

Reputation: 17717

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)

Upvotes: 5

Related Questions