Windows – Starting Emacs only once with different files on Windows

emacsemacsw32windows

I want to have emacs registered with file extensions on windows, but only one emacs instance should be open, even if I open several files through their extensions.

I have installed emacs from emacs-22.3-bin-i386.zip by unpacking to c:\bin\emacs on a windows server 2003 system (32 bit)

I created a script c:\bin\emacs\bin\emacs-filetarget.cmd

@echo off
"%~dp0emacsclientw.exe" -na "%~dp0runemacs.exe" "%1"

When I open the first file *.el with c:\bin\emacs\bin\emacs-filetarget.cmd it gets opened in a new emacs instance which is fine.

But the second file *.el gets opened in a second emacs instance. I am looking for a way to have only one emacs instance where all subsequent files are opened.

Best Answer

You need to make sure the emacs server is started. Add the following to your .emacs file:

(server-start)

And then always use emacsclientw.exe to start emacs.

For reference, I use an emacs.cmd file which looks like this:

@echo off
if "%1"=="" goto nofile

start "" "c:\emacs\bin\emacsclientw.exe" -n %*
goto end

:nofile
start "" "c:\emacs\bin\runemacs.exe

:end

The "runemacs" instance is because emacsclientw requires that you specify a filename.

Related Question