I'm using Emacs 24.3 on Windows 8. I want to be able to right-click a file and select "Edit with Emacs" and have the file open in an existing emacs frame. All steps I have done so far are listed below. Most of it was taken direction from the Emacs documentation page for Windows.
The following are the registry keys I used to add "Edit with Emacs" to my context menu:
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\openwemacs]
@="&Edit with Emacs"
[HKEY_CLASSES_ROOT\*\shell\openwemacs\command]
@="C:\\Portable Software\\emacs-24.3\\bin\\emacsclientw.exe -n \"%1\""
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs]
@="Edit &with Emacs"
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs\command]
@="C:\\Portable Software\\emacs-24.3\\bin\\emacsclientw.exe --alternate-editor=\"C:\\Portable Software\\emacs-24.3\\bin\\runemacs.exe\" -n \"%1\""
I also set the ALTERNATE_EDITOR
environment variable to C:\\path\\to\\runemacs.exe
At the beginning of my .emacs
I have added the following code per this answer.
(require 'server)
(or (server-running-p)
(server-start))
Adding that got rid of the "server already running" error when opening a second file, but it still opens in a new frame.
So what am I missing to get emacs to open new files in the existing frame?
I accidentally figured this out while trying to fix synctex
with SumatraPDF. It would appear that in addition to the ALTERNATE_EDITOR
environment variable pointing to runemacs.exe
, you must also create an EMACS_SERVER_FILE
environment variable that points to the server file (mine was stored in the .emacs.d\server
directory). Once I did that, files that I tell to Open with Emacs opened in the existing frame rather than creating their own.