Notepad++ 会自动添加一个 shell 快捷方式,这样当您在 Windows 资源管理器中时,您可以右键单击文件并选择“使用 Notepad++ 编辑”。我怎样才能对 emacs 做同样的事情?我正在为 Windows 使用 GNU Emacs 22.3。
8 回答
这就是我所拥有的 - 类似于其他一些答案。在某处创建一个名为 emacs-conextmenu.reg(或任何你想要的.reg)的新文本文件,并将以下内容粘贴到:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\openwemacs]
@="&Edit with Emacs"
[HKEY_CLASSES_ROOT\*\shell\openwemacs\command]
@="Absolute\\Path\\to\\your\\emacs\\bin\\emacsclientw.exe -n \"%1\""
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs]
@="Edit &with Emacs"
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs\command]
@="Absolute\\Path\\to\\your\\emacs\\bin\\emacsclientw.exe -n \"%1\""
将路径更改为您的 emacs 安装路径;记住要转义“\”(只要有 \,就将其更改为 \\)。
现在您需要做的就是在资源管理器中双击这个 *.reg 文件,您将拥有一个适用于任何文件和任何目录的 emacs 上下文菜单条目(如果您是一个狂热的粉丝!)。
请注意,要使其正常工作,必须启动 emacs 并且还必须启动 emacs-server (Mx server-start)。我建议使用 Windows 启动 emacs 并将 (server-start) 放入您的 .emacs 文件中。
作为奖励,当您在 Windows 资源管理器中按 ctrl-shift-enter 时,自动热键 ( http://www.autohotkey.com/ ) 的以下代码段将启动在 emacs 中选择的文件。如果您在 emacs 中编辑大量文件但不一定要导航到 emacs 本身中的文件,这可能会更方便。
#IfWinActive ahk_class CabinetWClass
^+Enter::
GetText(tmpvar)
If (tmpvar != "")
Run, d:/path/to/your/emacs/bin/dir/emacsclientw.exe -n "%tmpvar%"
Return
Return
就像多语言的答案一样,但不需要启动服务器或任何混乱。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\openwemacs]
@="&Edit with Emacs"
[HKEY_CLASSES_ROOT\*\shell\openwemacs\command]
@="C:\\Program Files (x86)\\Emacs\\bin\\emacsclientw.exe --alternate-editor=\"C:\\Program Files (x86)\\Emacs\\bin\\runemacs.exe\" -n \"%1\""
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs]
@="Edit &with Emacs"
[HKEY_CLASSES_ROOT\Directory\shell\openwemacs\command]
@="C:\\Program Files (x86)\\Emacs\\bin\\emacsclientw.exe --alternate-editor=\"C:\\Program Files (x86)\\Emacs\\bin\\runemacs.exe\" -n \"%1\""
如果您不喜欢研究注册表,您可以从 Windows 资源管理器中执行此操作(任何编辑器的说明,而不仅仅是 Emacs):
打开 Windows 资源管理器并选择
Tools\Folder Options...
菜单项。单击
File Types
选项卡并选择要与编辑器关联的文件类型的扩展名。对于此示例,我将使用 TXT 扩展名。单击
Advanced
详细信息框中的按钮以显示Edit File Type
对话框。您可以更改当前
open
操作,也可以指定一个新操作,例如Open with MyEditor
.如果您选择编辑,请单击
Edit...
按钮并在Application used to peform action
文本框中输入编辑器的完整路径,然后添加"%1"
. 例如,C:\SciTe\wscite\SciTE.exe "%1"
。如果要创建新动作,请单击
New...
按钮,为动作命名,并提供编辑器的完整路径,后跟"%1"
.如果您想将某个操作设为该文件类型的默认操作,请选择该操作,然后单击该
Set Default
按钮。OK
在所有对话框中。
另一种选择是在您的Send To
文件夹中放置编辑器可执行文件的快捷方式,%USERSPROFILE%\SendTo
. 我通常在这里创建一个名为“Editors”的新文件夹,并为我使用的各种编辑器放置快捷方式。
稍加添加,也可以通过单击背景在 emacs 中打开当前目录。
<<<Code as posted by polyglot>>>
[HKEY_CLASSES_ROOT\Directory\Background\shell\openwemacs]
@="Open &with Emacs"
[HKEY_CLASSES_ROOT\Directory\Background\shell\openwemacs\command]
@="C:\\Program Files\\emacs-24.2\\bin\\runemacs.exe \"%V\""
这%V
是当前目录。在这种情况下使用%1
不起作用。
这是做同样事情的另一种方法。适用于 WinXP 和 Vista。
将此添加到您的注册表:
用 emacs.reg 编辑
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Emacs]
@="Edit With &Emacs"
[HKEY_CLASSES_ROOT\*\shell\Emacs\command]
@="Wscript.exe C:\\emacs\\emacs-22.3\\bin\\launch-emacs-client.vbs \"%1\""
将此文件放在您的 emacs bin 目录中:
启动-emacs-client.vbs
Set objShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count = 1 Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
Dim isRunning
isRunning = False
For Each objItem in colItems
If InStr(objItem.CommandLine, "emacs.exe") Then
isRunning = True
End If
Next
If isRunning Then
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) & "/emacsclientw.exe -n """ & WScript.Arguments(0) & """")
Else
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) & "/runemacs.exe """ & WScript.Arguments(0) & """")
End If
Else
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) & "/runemacs.exe")
End If
注意:W32 安装程序在安装时运行类似的脚本。
查看带有 Windows 集成的 Emacs 发行版:http: //ourcomments.org/Emacs/EmacsW32.html
它的安装程序会创建一个资源管理器菜单条目,它可以满足您的需求。
我想在上面的 polyglot 的答案中添加 - 他提到的 AutoHotkey 快捷方式非常方便,但代码不完整:GetText() 函数是由 AutoHotkey 论坛上的某个人编写的(http://www.autohotkey.com/forum /viewtopic.php?p=279576#279576),它是:
GetText(ByRef MyText = "")
{
SavedClip := ClipboardAll
Clipboard =
Send ^c
ClipWait 0.1
If ERRORLEVEL
{
Clipboard := SavedClip
MyText =
ERRORLEVEL := 1
Return
}
MyText := Clipboard
Clipboard := SavedClip
Return MyText
}
;to test:
#k::
GetText(FileName)
msgbox clipboard=%FileName%
return
请注意,可能需要修改 ClipWait 延迟:我必须将其设置为 2!