I would like to set emacs as the default editor for text files when I double-click open them in Windows. However I would like to open them asa buffer in the same running instance of emacs (i.e. frame) , if any. Right now the behaviour will open another instance of emacs (i.e. another emacs frame).
Does anyone know which specification in init.el would allow this behaviour?
I've been using this guy's approach, which is an alternative to adding entries to the registry. I've reproduced his steps here:
:::::::::::::::::::::::::::::::::::::::::::::::::: ::: ::: Emacsclient startup script runemacsclientw.bat ::: Robert Adesam, [email protected] ::: http://www.adesam.se/robert/ ::: ::: N.B. Alot of this is reused from other Emacs ::: users that have published stuff on the ::: Internet. Thank you! :) :::::::::::::::::::::::::::::::::::::::::::::::::: @echo off :: Emacs binaries... set binpath=c:\Program Files\emacs\bin :: If no arg is given set filename to c:\ if "%~1"=="" ( set filename=c:\ ) else ( set filename=%~1 ) :: Run Emacsclient "%binpath%\emacsclientw.exe" --no-wait --alternate-editor="%binpath%\runemacs.exe" "%filename%"
First have a quick look at emacsclient documentation.
Then in your init.el file start the emacsclient server by running:
(server-start)
Next we'll add some keys to the registry which gives an "Edit with Emacs" option in the context menu for all files.
Add the following keys:
[HKEY_CLASSES_ROOT*\shell\Emacs]
@="Edit with Emacs"
[HKEY_CLASSES_ROOT*\shell\Emacs\command] @="c:\Program Files (x86)\emacs-23.2\bin\emacsclientw.exe" --no-wait --alternate-editor="c:/Program Files (x86)/emacs-23.2/bin/runemacs.exe" "%1"
The quotes are literal and should be included. You may have to play with the paths a bit so that they fit your environment.
As for the double-click behavior it's a matter of knowing which registry keys to add. If you know that they you should be able to generalize this answer to the behavior you want.
The program emacsclient will blast the file into a running copy of emacs (provided you ran 'server-start') or if there is not an existing copy it will run the command supplied with the "alternate-editor" option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With