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?
Use Ctrl-x f to open a file from within Emacs. Create a new file in the same way as opening a file by specifying the new filename.
Splitting WindowsThe command C-x 2 ( split-window-vertically ) breaks the selected window into two windows, one above the other. Both windows start out displaying the same buffer, with the same value of point.
Much better to use the multiple buffer feature of emacs. If you are editing the first file and want to start editing the second file, simply use the hot key C-x C-f or the menu selection File->Open File to start the second file. The second file is loaded into its own buffer.
To change the read-only status of a buffer, use C-x C-q (toggle read-only-mode ). To change file permissions, you can run dired on the file's directory ( C-x d ), search for the file by C-s and use M to change its mode.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With