1

I invested a lot of time to get a Windows file association working with cygwin emacsclient-w32. But every "solution" has some dead end that I can't solve. Any help really appreciated.

What I want is a simple file association for .cfg and .txt files to be opened by cygwin emacsclient-w32 (gui-version). The association has to work for local drive pathes and UNC pathes. What command will do the job?

Let's start at the basic. Command

"C:\cygwin64\bin\run.exe" emacsclient-w32 "%1"

Gets me /cygdrive/c/Users/MYUSERNAME/Desktop/C:\Users\MYUSERNAME\Desktop\myfile.cfg

Drag and dropping files works. Doesn't result in the path problem above.

I even tried cygpath. Problem there was that for UNC pathes there was one missing leading slash. When I add it local files were broken. The cygpath try looked like this:

C:\cygwin64\bin\bash.exe -c "emacsclient-w32 $(cygpath -u '%L')"

1 Answer 1

2

I did this exercise today, and ended up with the following batch file (I named it runemacs.bat):

setlocal enableextensions enabledelayedexpansion
set bin=C:\cygwin64\bin
IF "%~1" NEQ "" (
    for /f "delims=" %%i in ('%bin%\cygpath.exe %1') do set filepath=%%i
    %bin%\run.exe --quote %bin%\emacs-w32 "!filepath!"
) ELSE (
    %bin%\run.exe --quote %bin%\emacs-w32
)
endlocal

The secret for the path parts is to use the "--quote" arguments of cygpath.exe. It seems to work well, except that for some reason the UI freezes a couple seconds shortly after launching Emacs (for me at least), which is annoying.

This batch file can be associated to open any file you like.

6
  • Changed last line to %bin%\run.exe --quote %bin%\emacsclient-w32 -n "%filepath%" . Seems to work in general with local and UNC path. Still there is a problem with emacs. I used process exporer and found out it somehow does some crazy stuff when opening a file on an SMB share. This stuff is also the reason why it takes so long to open a file on an smb-share compared to programms like notepad++. I've seen some suggestions but none worked. Well at least the file now opens when Emacs is done with it's stuff.
    – Jens Lange
    Commented Jul 7, 2016 at 12:17
  • What is the '-n' option supposed to do? It is not documented in the man page of run.exe installed with Cygwin.
    – user30747
    Commented Jul 18, 2016 at 17:03
  • It's not an option of run.exe, it's an option of emacsclient-w32. The manual says "Let emacsclient exit immediately, instead of waiting until all server buffers are finished."
    – Jens Lange
    Commented Jul 20, 2016 at 0:33
  • Strange. I don't see this option detailed anywhere in 'man emacs' (Cygwin) nor online here: gnu.org/software/emacs/manual/html_node/emacs/…. When I try a plain emacs-w32 -n, it complains about Unknown option -n'.
    – user30747
    Commented Jul 21, 2016 at 18:46
  • 1
    As said, it's an option of emacsclient-w32 not emacs-w32. Check out emacsclient Options.
    – Jens Lange
    Commented Jul 29, 2016 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.