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')"
Jens Lange
  • 463
  • 2
  • 13

1 Answers1

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.

user30747
  • 161
  • 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 Jul 07 '16 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 Jul 18 '16 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 Jul 20 '16 at 00:33
  • Strange. I don't see this option detailed anywhere in 'man emacs' (Cygwin) nor online here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Invocation.html. When I try a plain `emacs-w32 -n`, it complains about `Unknown option -n'`. – user30747 Jul 21 '16 at 18:46
  • 1
    As said, it's an option of emacsclient-w32 not emacs-w32. Check out [emacsclient Options](https://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html). – Jens Lange Jul 29 '16 at 19:37
  • I would like to mention that I went back to nt-emacs. I came to the conclusion that under windows the nt version works overall better. A lot of packages with dependency on the OS or external windows programs do not work correctly under the cygwin version. Fixing that is beyond me. The official nt version 25 is now 64bit and they offer an official dependency package. The only thing I miss is pdf-tools, but I hope that will be solved by time. Currently I use cygwin only for aspell, git and difftools as an extension to nt-emacs. – Jens Lange Oct 21 '16 at 01:57