@Part(Compile, root "more.mss") @Chapter(Scribing and Compiling) People often use Emacs inefficiently when writing a program or Scribe manuscript. They edit the file, exit Emacs, compile the file, reenter Emacs, search for errors, fix them, then start the whole cycle over again. Never more! There are many facilities to speed up the whole process of compilation and debugging for both programming languages and the Scribe text formatter. @Section(Compiling) @Label(Compile) Emacs has a command which allows you to compile files without ever leaving Emacs. It is called, simply enough, @b[compile]. When executed, it first saves all the files. Next it asks you what command you want to execute. The default command is @b[make -k], which simply uses the makefile in the current directory to compile the requisite file, usually the one you were working on. If you don't have (or don't wish to use) a makefile, you can specify any command you like: @b[cc], @b[f77], @b[scribe], etc. Say you were editing the file @i{report.mss}. You want to Scribe a preliminary draft of it to see what it looks like. Since you will want to edit it again, you decide to use @b[compile] to do the entire process from within Emacs. Also, you don't want to hunt through the file manually to look for any errors that may occur. The first thing you type is: @Begin(Example) M-x compile @End(Example) This starts off the compilation process. Now the minibuffer shows: @Begin(Example) Compile command: make -k @End(Example) If you had already used another command with @b[compile], it would show that instead of @b[make -k]. As it is, you want to delete the current command and run @b[scribe] instead. Just use the standard Emacs delete and kill keys, then enter the command of your choice. For the above situation, just type: @Begin(Example) Compile command: make -k @b[C-a C-k] @i{Move to beginning, then delete.} Compile command: @b[scribe report.mss] <@b[RET]> @End(Example) If that is indeed what you want, you can type @b[RET] to accept that command. If you have modified the file @i{report.mss}, it will ask you if you want to save that file. Just type "y" for yes. Emacs now splits the screen, creating a second window, and runs the specified command in the buffer @i{*compile*}. You can continue working in the first window, if you like. If you need to abort the compilation, use the command @b[kill-compilation]. Also, if you start up a new compilation, it will offer to kill off the old one. Otherwise, be sure to stay in two-window mode so you can use the error-finding routines. @Section(Finding Compilation Errors) @Label(FindError) Unless you are lucky, you now have a buffer full of errors. Each error has a file name and line number associated with it. For program compilers (not Scribe), Emacs can use this information to move directly to those errors. The command to do that is: @Begin(Description) C-x ` @\@b{[next-error]} Moves to the next error listed in @i{*compile*}. A numeric argument starts over from the first error. @End(Description) To start, just type @b[C-x `]. Notice that @b[`] is the backquote, or grave accent, not the apostrophe. This will move you to the first error listed in @i{*compile*}. Emacs will move backwards and forwards, and even load in new files if necessary. Once there, you can move around, insert and delete, and do whatever is necessary to fix the error. When you are ready, just type @b[C-x `] again to move on. The second window scrolls to follow which error you are on. You can stop at any time. To get rid of the second window, just type @b[C-x 1] or click @b[C-SHIFT-RIGHT], as described in Chapter @Ref(Window). For more information about compiling and debugging files within Emacs, consult Chapter 22 of the @p[GNU Emacs Manual]. @Section(Running Things Outside Emacs) Hopefully, after only a few edit/compile cycles, your file will be free of compilation errors. Now you must start checking for runtime errors. This can result in your jumping back and forth between running the program and editing it (again and again . . .). For ways to avoid this, see the shell commands described earlier in Section @Ref(Shell).