Color-Coding Source Code in Emacs

Emacs can color-code different parts of your C and C++ source code and header files while you are viewing and editing them. Below you can follow either the easy or harder method of setting up your account to color code in Emacs.

Easy Way

For this method, just type the following command at the UNIX prompt:

(That's a slash at the beginning and hyphens in the program name.) It should tell you if it installed the colors.

Harder Way

For this method, you need to edit the "dot file" called .emacs that exists in your home directory. You may edit this file with:
emacs ~/.emacs

At the very end of this file, place the line:

(load "/cs/course/cs113/emacs/c-colors")

Then, save the buffer and exit Emacs. The next time you start up Emacs and edit a .c, .cpp or .h file, it should be color-coded.

Testing Color-Coding

To see how color-coding can help you find mistypings in your code, download the program sum.cpp. Then, load it into Emacs with:
emacs sum.cpp &

Now, go to line 39 where there is an error. Does the color-coding help you recognize the error?

BU CAS CS - Color-Coding Source Code in Emacs
Copyright © 1993-2000 by Robert I. Pitts <rip at bu dot edu>. All Rights Reserved.