How do I add color syntax highlighting to GNU emacs?

5

I have two versions of emacs available to me on a locked workstation:

$ /usr/local/bin/emacs --version
GNU Emacs 22.3.1

$ /usr/bin/emacs --version
GNU Emacs 21.4.1

In both cases, my terminal type is xterm when I run either version of emacs.

When I run the v21 version of emacs, I get syntax coloring for Perl, HTML, and other modes.

When I run the v22 version, I do not get syntax coloring.

I would like to migrate from the v21 version because the combination of v21 emacs, GNOME Terminal and GNU Screen is eating Ctrl-arrow key chords, which prevents me from moving quickly between words. (OS X Terminal and GNU Screen do not have this issue.) The v22 version allows use of Ctrl-arrow key combinations with GNOME Terminal and GNU Screen.

How do I fix the v22 version (or ask my sys admin to fix) so that it once again highlights syntax and allows me to use Ctrl-arrow key combinations?

Alex Reynolds

Posted 2010-05-21T22:20:10.197

Reputation: 601

have you managed to resolve this? I'm having a similar problem. – bstpierre – 2010-08-07T02:29:43.593

Answers

5

Add this line

(global-font-lock-mode 1)

to your .emacs file.

goedson

Posted 2010-05-21T22:20:10.197

Reputation: 896

This had no effect, I'm afraid. – Alex Reynolds – 2010-05-21T23:31:03.413

Try to activate it manually, with M-x font-lock-mode, making sure you are in some programming language mode (like c-mode) first. – goedson – 2010-05-22T01:03:57.800

2

I was having the same problem, but only with c and c++ modes. Thanks to the hints above from @goedson I tracked it down.

Doing M-x font-lock-mode when in these modes showed me that it was already enabled. (The message I got back when running this was "Font-Lock mode disabled".)

Digging around through help (and my memory), I remembered that you have to apply the colors to the buffer ("fontify"). To test it manually, first make sure font-lock-mode is on and that you're in a programming language mode (e.g. perl, c). Then do font-lock-fontify-buffer. If you get colors, then you'll want to apply the change to your .emacs. Add something like this:

(add-hook 'c-mode-hook
          (function (lambda ()
                      (font-lock-fontify-buffer)
                      )))

You'll want to replace c-mode-hook with whatever mode is relevant for you, and you may want to repeat this for other modes. (I've done it for c and c++.)

bstpierre

Posted 2010-05-21T22:20:10.197

Reputation: 1 232

0

I would try to change my TERM to something like xtermc, or xterm-256 or somehting like that.

Also, does M-x list-colors-display work for you ?

Xavier Maillard

Posted 2010-05-21T22:20:10.197

Reputation: 153