Compiling Programs

As mentioned at the beginning of this chapter, Emacs’ support for programmers does not end when you are done writing the code. A typical strategy for using Emacs when working on a large programming project is to log in, go to the directory where your source files reside, and invoke Emacs on all source files (e.g., emacs Makefile *.[ch] for C programmers). While you are editing your code, you can compile it using the commands described later—as you will see, you need not even worry about saving your changes. You can also test your compiled code in a shell window using shell mode (described in Chapter 5). The bottom line is that you should rarely--if ever—have to leave Emacs throughout your login session.

Emacs provides a way to interface to compilers and the UNIX make utility that is more direct and powerful than shell mode. At the heart of this facility is the command ESC x compile RETURN. This command causes a series of events to occur. First, it prompts you for a compilation command. The default command is make -k, [73]but if you type in another command, that new command becomes the default for subsequent invocations during your Emacs session. You can change the default by setting the variable compile-command in your .emacs file.

Once you have typed the command, Emacs offers to save all unsaved file buffers, thus relieving you of the responsibility of making sure your changes have been saved. Then it creates a buffer called *compilation* and an associated window. ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.