Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 679
namin Avatar asked Jan 18 '09 12:01

namin


2 Answers

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 
like image 128
polyglot Avatar answered Oct 08 '22 19:10

polyglot


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\"" 
like image 37
NeilMonday Avatar answered Oct 08 '22 18:10

NeilMonday