How to create a right-click context shell shortcut

2019-03-08 05:42发布

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.

8条回答
Deceive 欺骗
2楼-- · 2019-03-08 06:12

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\""
查看更多
Evening l夕情丶
3楼-- · 2019-03-08 06:13

Here's is another way to do the same thing. Works in WinXP and Vista.

Add this to your registery:

edit-with-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:

launch-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 installer runs a similar script on installation.

查看更多
戒情不戒烟
4楼-- · 2019-03-08 06:22

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:

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!

查看更多
一纸荒年 Trace。
5楼-- · 2019-03-08 06:23

This site explains 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.

查看更多
我命由我不由天
6楼-- · 2019-03-08 06:25

Check out an Emacs distribution with Windows integration: http://ourcomments.org/Emacs/EmacsW32.html

Its installer creates an Explorer menu entry which does what you want.

查看更多
做自己的国王
7楼-- · 2019-03-08 06:26

With a little addition, also opening the current directory in emacs by clicking on the background becomes possible.

<<<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.

查看更多
登录 后发表回答