How to create a right-click context shell shortcut "edit with Emacs"? How to create a right-click context shell shortcut "edit with Emacs"? windows windows

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


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%"ReturnReturn


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\""


If you're not up for spelunking the registry, you can do this from the Windows Explorer (instructions for any editor, not just Emacs):

  1. Open the Windows Explorer and select the Tools\Folder Options... menu item.

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

  3. Click the Advanced button in the details frame to bring up the Edit File Type dialog.

  4. You can either change the current open action, or specify a new action like Open with MyEditor.

    If you choose to edit, click the Edit... button and in the Application 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".

  5. If you want to make an action the default for that file type, select the action, then click the Set Default button.

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