Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file in existing emacs frame (Windows)

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?

like image 364
Ryan Avatar asked Mar 25 '13 01:03

Ryan


People also ask

How do you open a file from within Emacs?

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.

How do I open Emacs in separate windows?

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.

How do I open a second file in Emacs?

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.

How do I open a read only file in Emacs?

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.


1 Answers

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.

like image 51
Ryan Avatar answered Nov 15 '22 04:11

Ryan