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.
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.
If you're not up for spelunking the registry, you can do this from the Windows Explorer (instructions for any editor, not just 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.
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.
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:
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 \\).
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!).
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.
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.
#IfWinActive ahk_class CabinetWClass
^+Enter::
GetText(tmpvar)
If (tmpvar != "")
Run, d:/path/to/your/emacs/bin/dir/emacsclientw.exe -n "%tmpvar%"
Return
Return
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.
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.
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!