How to create a right-click context shell shortcut “edit with Emacs”?

前端 未结 8 814
离开以前
离开以前 2021-01-30 11:22

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 w

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 12:00

    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.

提交回复
热议问题