Oleksandr Gavenko's blog
2017-01-24 14:00 Emacs 25 under Windows

I haven't used Windows for a long time and new job may require Windows environment. So I checked out new ways to use Emacs under Windows.

I used to prefer native Emacs over Cygwin because of native widgets and copy/paste. With cygwin-mount cross-compiling from Cygwin to native win application would be easy.

The only problem I encountered that hg is a Python script, not an executable and can't be called from native Emacs. To work around with issue I wrote simple Cygwin application that route call and arguments to script.

So you just rename this utility to $SCRIPT.exe and put it behind Cygwin in a PATH. It have basic protection from infinite calling to itself and allows using of scripts under from Cygwin in native Windows application, like native Emacs.

Source code of utility is available on http://hg.defun.work/utils/file/tip/cygwin/cygrun/cygrun.c

But I constantly have issue with VC mode. Native Emacs is wrongly determining file revision and reported it as string rev. That it's due to quoting and wrong Emacs code assumption: Re: Using Cygwin Emacs.

Starting X for graphical Emacs seems too complicated, but possible. Especially by using multi-window:

XWin -multiwindow

but all programs should be started with DISPLAY set:

DISPLAY=:0 xterm

With some tweaking it is possible smoother integration:

XWin -clipboard -silent-dup-error -xkblayout "us,ru" -xkboptions "grp:caps_toggle"

Nowadays there is emacs-w32 build in Cygwin repositories. It uses native widgets and in all other cases is regular Cygwin application. So I have Hg/Git and TRAMP working out of the box!

Only issue with emacs-w32 executable is that all Cygwin executables compiled with --subsystem=console or -mconsole (which is by default). That causes opening Windows console window along with GUI. That console window distracts me during Alt+TAB.


Re: Is it possible to hide emacs-w32 console window?

Cygwin programs can't be compiled with -mwindows (or --subsystem=windows). Reason for this described in run(1) man page:

run - start programs with hidden console window

     run [ -p path ] command [ --wait ] [ --quote ] arguments

     runcommand [ -p path ] [ --wait ] [ --quote ] arguments


   Windows programs are either GUI programs or console programs. When started
   console programs will either attach to an existing console or create a new
   one. GUI programs can never attach to an exiting console. There is no way
   to attach to an existing console but hide it if started as GUI program.

   run will do this for you. It works as intermediate and starts a program but
   makes the console window hidden.

and run command helps to hide console window. So you should start Emacs as:

run emacs-w32

I have "smart" starter of Emacs with short and convenient for quick typing name e and batch file e.bat. Because I switched to emacs-w32 as a default for Windows I updated e.bat implementation to take care about run:

run emacsclient-w32 -a emacs-w32 %*

Full script available at:: http://hg.defun.work/utils/file/tip/emacs/e.bat

emacs, win, cygwin


all / emacs / java / python


admin(1), anki(1), blog(1), css(2), cygwin(2), emacs(3), fs(1), git(2), gradle(1), hg(2), html(1), interview(11), java(2), js(3), lang(2), lighttpd(1), mobile(1), naming(1), oracle(1), print(1), problem(5), quiz(6), rst(1), security(1), sql(2), srs(1), style(1), unit(1), utils(1), vcs(3), web(2), win(2)