tags:

views:

121

answers:

4

I have been using emacs for a while for mainly python programming, and have started C++ coding with it. When I open a c++ file, it opens without problems with c++-mode. The background and foreground colors are normal for the theme I have with color-theme, but keywords and strings are not colored differently. Below is the code in my .emacs to initialize color-theme.

(add-to-list 'load-path "D:\\emacs\\color-theme-6.6.0")
(require 'color-theme)
(color-theme-initialize)
(setq color-theme-is-global t)
(color-theme-hober)

I have not put in any code for c++. Any ideas?

Edit: I tried turning off color-theme to see if at least then there would be some coloring, and there was not, even after ensuring font-lock-mode was on. Also, this is GNU Emacs 23.1.1

A: 

(font-lock-mode) should help (with non negative argument to make sure it's turned on)

stefaanv
I tried C-u 2 M-x font-lock-mode, got a message that font-lock-mode was enabled and saw no difference. I also tried placing (font-lock-mode t) in my .emacs file, and that changed nothing.
Nikwin
I have (font-lock-fontify-buffer) attached to a key, but I never use this. It's font-lock-mode for me. Maybe you find something in options->"Syntax Highlighting".
stefaanv
BTW, this is xemacs21, although I used it in gnu-emacs too.
stefaanv
Thank you for font-lock-fontify-buffer. I have added (add-hook 'c++-mode-hook 'font-lock-fontify-buffer) to my .emacs, which highlights strings and comments, but keywords are still untouched. I don't know why font-lock-fontify-buffer works, and not font-lock-mode.
Nikwin
A: 

Generally this should work straight out of the box on a standard install - to verify start emacs with the "-q" option to avoid loading stuff from your init file. I have verified this with a quick install (on XP Pro) of the offical 23.2 binaries. Here's the output: (apparently can't post images due to low reputation - the link is img444.imageshack.us/img444/2680/46117077.png).

If this displays code as you expect, then there's an issue with your init file - I suggest using the standard approach of commenting everything out and selectively adding things back in, until you come across the offending line(s).

cristobalito
Nope, even with -q there is no difference in the way it loads. Maybe I will just try moving to 23.2 and see if that fixes this.
Nikwin
+1  A: 

Place the cursor over a keyword and do M-x describe-face. The face should be identified as font-lock-keyword-face and the description of the face given. At that point it should be easier to determine whether the keyword has the wrong face, or the face just has a default appearance. You could also double-check that font-lock-mode is on with describe-mode.

0x4b
A: 

I finally got syntax highlighting by removing a folder called site-lisp from the folder d:/emacs. My Emacs installation is in d:/emacs/emacs-23.1, and somehow it was reading from these files. So, removing this folder forced Emacs to use the correct ones, I think.

Nikwin