Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Emacs syntax highlighting colors

I'm running Emacs, editing files in C++ mode and PHP mode. I love syntax highlighting as a concept, but the default colors are a travesty. I can barely read some of them: way too dark. What is the easiest way to change their values? I can't seem to find anything about this on the web. I don't even mind changing the binary as I'm compiling my own Emacs. I just want to find the place where it says blue is #0000FF and change it to #AAAAFF for example.

like image 584
adum Avatar asked Jul 02 '09 20:07

adum


People also ask

How to change the highlight color in Emacs?

To customize colors for color syntax highlighting, see the section on font-lock . To change the foreground or background color in Emacs through the windowing interface, you can use the menu commands Foreground Color->Other and Background Color->Other in the Edit->Text Properties menu.

Does Emacs have syntax highlighting?

font-lock-mode is the standard way to have Emacs perform syntax highlighting in the current buffer. It is enabled by default. With font-lock-mode turned on, different types of text will appear in different colors.

How do I change the color of my Emacs theme?

You can enable a specific Custom theme in the current Emacs session by typing M-x load-theme . This prompts for a theme name, loads the theme from the theme file, and enables it. If a theme file has been loaded before, you can enable the theme without loading its file by typing M-x enable-theme .


2 Answers

I find it easiest to use color-theme for this sort of thing.

But if you don't want to do that, put the cursor over the offending text, and hit M-x customize-face. It should default to the face that the cursor is over.

See 49.1.6 Customizing Specific Items.

like image 54
seth Avatar answered Nov 14 '22 00:11

seth


Two ways - you can install the package color-theme, which has lots of nice schemes to select and is easier to do it by hand. The by-hand looks like this (in your .emacs file)

(custom-set-faces    custom-set-faces was added by Custom.    If you edit it by hand, you could mess it up, so be careful.    Your init file should contain only one such instance.    If there is more than one, they won't work right.   '(default ((t (:inherit nil :stipple nil :background "lightyellow2" :foreground "gray20" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :width normal :family "liberation mono"))))   '(background "blue")   '(font-lock-builtin-face ((((class color) (background dark)) (:foreground "Turquoise"))))   '(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))   '(font-lock-constant-face ((((class color) (background dark)) (:bold t :foreground "DarkOrchid"))))   '(font-lock-doc-string-face ((t (:foreground "green2"))))   '(font-lock-function-name-face ((t (:foreground "SkyBlue"))))   '(font-lock-keyword-face ((t (:bold t :foreground "CornflowerBlue"))))   '(font-lock-preprocessor-face ((t (:italic nil :foreground "CornFlowerBlue"))))   '(font-lock-reference-face ((t (:foreground "DodgerBlue"))))   '(font-lock-string-face ((t (:foreground "LimeGreen")))) 

...

etc. etc.

You can also type

`M-x customize-face RET` 

which will give you all the customizations to set, ultimately end up in your .emacs file.

like image 40
Steve B. Avatar answered Nov 13 '22 22:11

Steve B.