windows 如何创建右键单击上下文外壳快捷方式“使用 Emacs 编辑”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/455077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a right-click context shell shortcut "edit with Emacs"?
提问by namin
Notepad++ automatically adds a shell shortcut so that when you're in Windows Explorer, you can right-click on a file and select "edit with Notepad++". How can I do the same with emacs? I am using GNU Emacs 22.3 for Windows.
Notepad++ 会自动添加一个 shell 快捷方式,这样当您在 Windows 资源管理器中时,您可以右键单击文件并选择“使用 Notepad++ 编辑”。我怎样才能用 emacs 做同样的事情?我在 Windows 上使用 GNU Emacs 22.3。
回答by polyglot
Here's what I have - similar to some other answer. Create a new text file somewhere called emacs-conextmenu.reg (or anything-you-want.reg) and paste the following in:
这就是我所拥有的 - 类似于其他一些答案。在某处创建一个名为 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\""
Change the path to your emacs installation path; remember to escape the "\" (whenever you have \, change that to \\).
把路径改成你的emacs安装路径;记住要转义“\”(只要有 \,就将其更改为 \\)。
Now all you need to do is double-click this *.reg file in the explorer and you shall have a context menu entry for emacs for any file and any directory (if you are a dired fan!).
现在您需要做的就是在资源管理器中双击这个 *.reg 文件,您将拥有一个适用于任何文件和任何目录的 emacs 上下文菜单条目(如果您是一个狂热的粉丝!)。
Note that for this to work, emacs has to be started and emacs-server also has to be started (M-x server-start). I would suggest starting emacs with Windows and put (server-start) in your .emacs file.
请注意,要使其正常工作,必须启动 emacs 并且还必须启动 emacs-server (Mx server-start)。我建议使用 Windows 启动 emacs 并将 (server-start) 放入您的 .emacs 文件中。
As a bonus, the following snippet for autohotkey (http://www.autohotkey.com/) will start the file selected in emacs when you press ctrl-shift-enter in windows explorer. This might be more handy if you edit lots of files in emacs but does not necessarily want to navigate to the file in emacs itself.
作为奖励,当您在 Windows 资源管理器中按 ctrl-shift-enter 时,autohotkey ( 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
回答by NeilMonday
Just like polyglot's answer, but no need to start a server or any of that mess.
就像多语言的答案一样,但不需要启动服务器或任何混乱。
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\""
回答by Patrick Cuff
If you're not up for spelunking the registry, you can do this from the Windows Explorer (instructions for any editor, not just Emacs):
如果您不准备探索注册表,您可以从 Windows 资源管理器中执行此操作(针对任何编辑器的说明,而不仅仅是 Emacs):
Open the Windows Explorer and select the
Tools\Folder Options...
menu item.Click on the
File Types
tab and select the extension for the type of file you want to associate with your editor. For this example, I'll use the TXT extension.Click the
Advanced
button in the details frame to bring up theEdit File Type
dialog.You can either change the current
open
action, or specify a new action likeOpen with MyEditor
.If you choose to edit, click the
Edit...
button and in theApplication used to peform action
textbox, put the full path to your editor, followed by"%1"
. For example,C:\SciTe\wscite\SciTE.exe "%1"
.If you want to create a new action, click the
New...
button, give the action a name, and give the full path to your editor, followed by"%1"
.If you want to make an action the default for that file type, select the action, then click the
Set Default
button.OK
out of all dialogs.
打开 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
在所有对话框中。
Another option would be to put a shortcut to your editor's executable in your Send To
folder, %USERSPROFILE%\SendTo
. I usually create a new folder in here called "Editors" and put shortcuts to the various editors I use.
另一种选择是将编辑器可执行文件的快捷方式放在Send To
文件夹中%USERSPROFILE%\SendTo
。我通常会在此处创建一个名为“Editors”的新文件夹,并为我使用的各种编辑器添加快捷方式。
回答by kdb
With a little addition, also opening the current directory in emacs by clicking on the background becomes possible.
添加一点点,也可以通过单击背景在 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\""
Here %V
is the current directory. Using %1
doesn't work in this case.
这%V
是当前目录。%1
在这种情况下使用不起作用。
回答by Justin Tanner
Here's is another way to do the same thing. Works in WinXP and Vista.
这是做同样事情的另一种方法。适用于 WinXP 和 Vista。
Add this to your registery:
将此添加到您的注册表中:
edit-with-emacs.reg
用-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\""
Place this file in your emacs bin directory:
将此文件放在您的 emacs bin 目录中:
launch-emacs-client.vbs
启动-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
Note: the W32 installerruns a similar script on installation.
回答by Michael Haren
This siteexplains how to do it with another app. Just change the path and you should be all set.
该站点解释了如何使用其他应用程序进行操作。只需更改路径,您就应该准备就绪。
Create this key/value:
创建此键/值:
[HKEY_CLASSES_ROOT\*\shell\Edit with AppName\command]
@=”\”C:\Program Files\Notepad2\Notepad2.exe\” \”%1\”"
Here's another reference, which is a little easier to follow.
这是另一个参考,它更容易理解。
回答by js.
Check out an Emacs distribution with Windows integration: http://ourcomments.org/Emacs/EmacsW32.html
查看与 Windows 集成的 Emacs 发行版:http: //ourcomments.org/Emacs/EmacsW32.html
Its installer creates an Explorer menu entry which does what you want.
它的安装程序会创建一个资源管理器菜单条目,可以执行您想要的操作。
回答by Leo Alekseyev
I want to add to polyglot's answer above -- the AutoHotkey shortcut he mentions is very handy, but the code is incomplete: the GetText() function was written by somebody on the AutoHotkey forum (http://www.autohotkey.com/forum/viewtopic.php?p=279576#279576), and it is:
我想添加到上面的多语言答案中——他提到的 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
Note that ClipWait delay might need to be modified: I had to set it to 2!
请注意,可能需要修改 ClipWait 延迟:我必须将其设置为 2!