Next: , Previous: Text and Utility modes, Up: Top


10 Developing with Emacs

10.1 How do I use Emacs with Microsoft Visual C++

There are two ways you can use Emacs in conjunction with MSVC. You can use Emacs as the editor, and do everything else in the DevStudio IDE. Or you can use Emacs as an IDE, calling the MSVC command line tools to build your project.

10.1.1 Emacs as the text editor for DevStudio

Christopher Payne wrote a Visual Studio add-in that makes Emacs the default text editor, this has now been taken over by Jeff Paquette. See the following two URLS for details:

10.1.2 Using MSVC command line tools from Emacs

This is an app note on how to use Microsoft Visual C++ with Emacs. The experiments done below were done with Emacs 19.34.1 on Windows 95, using Visual C++ 4.0 Standard Edition. Your mileage may vary.

This writeup assumes minimal knowledge of Emacs hacking on the part of the reader.

10.1.2.1 VC++ Environment Variables

There is a batch file in your VC++ installation's bin directory called vcvars32.bat, which sets up the environment variables needed to run the VC++ command line tools. Arrange for those same environment variables to be set in your Emacs session. You can do this on Windows 9x by calling the vcvars32.bat script from autoexec.bat. On other versions of Windows you can set the environment variables globally using the System control panel.

For all versions of Windows you can alternatively set the variables just inside Emacs by using setenv calls in your init file. See Where do I put my init file?.

You should now be able to compile from Emacs. Load a source file from a VC++ project. Type M-x compile. Replace the proposed command line with:

     nmake -f ProjectName.mak

You will find that this defaults to a debug build. You can change it to a release build with:

     nmake -f ProjectName.mak CFG="ProjectName - Win32 Release"
10.1.2.2 Setting the default compile command

Now set the default value for the compile command line. Add the following to your init file:

     ;; Set up for Visual C++ compiling
     (setq compile-command "nmake -f ")

If you work on the same project long term, you can add the project makefile to the string.

David Biesack suggests that perhaps it's easy to write a Makefile in the project directory which does

     PROJECT=MyProject
     all: debug
     debug: FORCE
             nmake /f $(PROJECT).mak CFG="$(PROJECT) - Win32 Debug"
     release: FORCE
             nmake /f $(PROJECT).mak CFG="$(PROJECT) - Win32 Release"
     FORCE:

and then you can simply change compile-command to nmake.

Caleb T. Deupree reports that on VC++ 5.0 and up, "You can also set an option in Options/Build to export a makefile every time the project is saved, which you can then use to compile with ‘nmake -f project.mak’." VC++ 4.0 builds the make file every time, and there is no option.

10.1.2.3 Reverting Buffers

It is recommended that you use auto-revert-mode in buffers that you have open in both Emacs and MSVC++ at the same time. Then if you mistakenly edit the file in MSVC++, Emacs will pick up your changes immediately, rather than after you have written lots more code and attempt to save.

10.1.2.4 Edit with Emacs function for MSVC

You can also set up VC++ to import a file into Emacs for you, all ready for editing. In VC++, go to the Tools pull-down menu, and click on Customize.... In the Tools tab, click on Add. Use Browse to locate the emacsclientw.exe file in your Emacs bin directory, and select it. For arguments, use +$(CurLine) "$(FilePath)" and for the directory use the $(WkspDir) (the quotes around FilePath handle paths with spaces in them). Set the Menu Text to say "Em&acs". The +$(CurLine) will set point in Emacs to the same line as the cursor position in VC++. The ampersand in the word Em&acs allows you to select emacs from the keyboard. (E is already used for the OLE control test container.)

You should now be able to go to any source file in your project. Then, use the pull-down menu Tools->Emacs. The active file in your VC++ IDE should now be front and center in Emacs, all ready to edit as you wish. If you use keystrokes to work the menus, try Alt-T A to move the file into Emacs. Binding this tool to a keystroke will be left as an exercise for the student.

If you have the option of saving files before running tools, make sure this option is set. (I don't see it on VC++ 4.0.)

10.2 Emacs and Borland C++ Builder

Jonathan Arnold has written an EmacsEdit “expert” for interfacing C++ Builder and Emacs.

10.3 Is there a version of my VC software I can use with Emacs?

If you are using a graphical revision control tool already, check if it comes with command-line tools. Many such GUI tools are just wrappers for the same command line tools that Emacs requires for its VC integration. Most of the supported VC systems have well supported Free native Windows binaries. For those that don't Cygwin may be an option. See Other useful ports.

10.4 How do I use the Perl debugger with Emacs?

From Jay Rogers

Some versions of the perl debugger itself need to be patched to work with emacs. They are perl versions 5.001 and less, and version 5.004_01. To fix, locate and change the code similar to the following code in lib/perl5db.pl

             if (-e "/dev/tty") {
                 $console = "/dev/tty";
                 $rcfile=".perldb";
             }
             elsif (-e "con") {
                 $console = "";                 <---- change "con" to ""
                 $rcfile="perldb.ini";
             }
             else {
                 $console = "sys\$command";
                 $rcfile="perldb.ini";
             }

Doug Campbell also has some suggestions for improving the interaction of perldb and Emacs.