简体   繁体   English

在现有emacs框架中打开文件(Windows)

[英]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. 我在Windows 8上使用Emacs 24.3。我希望能够右键单击一个文件并选择“使用Emacs编辑”并在现有的emacs框架中打开该文件。 All steps I have done so far are listed below. 我到目前为止所做的所有步骤都列在下面。 Most of it was taken direction from the Emacs documentation page for Windows . 其中大部分内容都来自WindowsEmacs文档页面

The following are the registry keys I used to add "Edit with Emacs" to my context menu: 以下是我用于在我的上下文菜单中添加“使用Emacs编辑”的注册表项:

[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 我还将ALTERNATE_EDITOR环境变量设置为C:\\\\path\\\\to\\\\runemacs.exe

At the beginning of my .emacs I have added the following code per this answer . 在我的.emacs开头,我根据这个答案添加了以下代码。

(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? 那么我缺少什么让emacs在现有框架中打开新文件?

I accidentally figured this out while trying to fix synctex with SumatraPDF. 我试图用SumatraPDF修复synctex时偶然synctex了这个问题。 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). 看起来除了指向runemacs.exeALTERNATE_EDITOR环境变量runemacs.exe ,还必须创建指向服务器文件的EMACS_SERVER_FILE环境变量(我的存储在.emacs.d\\server目录中)。 Once I did that, files that I tell to Open with Emacs opened in the existing frame rather than creating their own. 一旦我这样做,我告诉Open with Emacs的文件在现有框架中打开而不是创建自己的文件。

It seems that emacsclient is failing to connect with the server and starting a new instance of emacs each time. 似乎emacsclient无法与服务器连接并且每次都无法启动emacs的新实例。 You may need to unblock something in any software firewall you have installed. 您可能需要在已安装的任何软件防火墙中取消阻止某些内容。

This worked for me. 这对我有用。

Create C:\\Program Files\\runemacs.bat with the following contents: 使用以下内容创建C:\\Program Files\\runemacs.bat

@echo off

:: Set the path to where the Emacs binaries are
set binpath=C:\Program Files\emacs-26.1-x86_64\bin

:: If no arg is given edit this file
if "%~1"=="" (
  set filename="C:\Program Files\runemacs.bat"
) else (
  set filename="%~1"
)

:: Run Emacsclient
"%binpath%\emacsclientw.exe" --no-wait --alternate-editor="%binpath%\runemacs.exe" %filename%

And open all files via C:\\Program Files\\runemacs.bat instead of C:\\Program Files\\emacs-26.1-x86_64\\bin\\runemacs.exe . 并通过C:\\Program Files\\runemacs.bat而不是C:\\Program Files\\emacs-26.1-x86_64\\bin\\runemacs.exe打开所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM