Both GNU and XEmacs can be run under Cygwin. Why would you want to do this? Because emacs expects to be run on a unix-style system, and cygwin provides the most-unix-like experience to be had on window$. Trust me, your life will improve 😊

There are two ports of Emacs you can run together with Cygwin. For information about how to use native w32 Emacs port with Cygwin see NTEmacsWithCygwin.

GNU Emacs ported to the Cygwin environment comes with Cygwin. The initial setup is easy (from setup.exe, browse to Editors → emacs). Choose emacs-X11 to run both the X and terminal (character-mode) versions, or emacs to run only on terminal (i.e. within bash).

Note that the Meta key doesn’t always work as well as you’d like: CygwinMeta.

I had persistent display problems running in bash:

I found (after a lot of posting) I could solve these problems by:

@echo off
rem Start bash as interactive shell

rem Put your path to bash here
cd /d D:\bin\cygwin\1.3.13-1\bin

rem Set vars for Emacs
set CYGWIN=tty title
set TERM=ansi
set HOME=t:\tlroche

bash --login -i

rem Does this really unset?
rem Answer: No, it is pointless to put the following at the *end* of a
rem         batch file.  Environment variables are local to the process in
rem         which they are set.  Child processes inherit the environment of
rem         their parent *at the time the child process is started*.
rem set HOME=
rem set TERM=
rem set CYGWIN=

I unset the envvars (I hope) so as not to confuse my non-cygwin emacs. (I use a single _emacs on all platforms, which tries to figure out on which platform it’s actually running by looking at various envvars. But multi-platforming emacs is a whole ‘nother topic.) Note that, with the CYGWIN envvar, “title” is optional, but “tty” is not: see SetTty.

Kris Thielemans claims unsetting is normally not necessary as environment variables are local to the current cmd/command shell. They survive only as long as the cmd/command shell from which you ran the cygwin.bat file. As cygwin is usually launched from the Start button or an Icon, the cmd/command shell exits just after you exit cygwin.

Kris Thielemans also says that you do not need to set HOME as /etc/profile sets it to /home/$USER. If this doesn’t end up where you want, you can always use cygwin’s mount to put /home where you like.

And finally, Kris Thielemans also says that the usual setting for TERM is cygwin (which is done automatically if TERM isn’t set). This works fine for him.

Life was easier (but also slower and more memory-intensive) running emacs under X. To do this:

  1. When you install, (in category view) select Editors>emacs-X11. That should bring in emacs (though not the lisp sources--that’s a separate package), XFree86, and lots of other stuff.
  2. Run bash (i.e. the cygwin shortcut), and within bash run ‘startx’. This will eventually launch a (windows) window running X, plus a bunch of xterm’s.
  3. From one of the xterm’s, run ‘emacs &’.

BTW, Kris Thielemans says “you should mention in that how-to that emacs-X runs with any (proper) X-windows emulator. (In my case, it runs happily using Exceed.) Also, the startx command is only available when you installed the XFree package.” (It looks like now startx comes in xinit package.) Also, lemme mention the batch file I use to start X (automating the first two steps above:

@echo off
rem Use bash to start X

cd /d D:\bin\cygwin\1.3.13-1\bin

rem Set vars for Emacs
set CYGWIN=tty title
set HOME=t:\tlroche

bash --login -c "startx"

rem The following is commented out because it has no effect.
rem rem Unset
rem set HOME=
rem set CYGWIN=

You can then customize your startx and .xinitrc to launch whatever programs (xterm, emacs, etc) you want.

You may also launch emacs or any other compatible executable without going through a console window, by means of a batch file like the following:

@echo off
C:\cygwin64\bin\run.exe --quote /usr/bin/bash.exe --login -c "/usr/bin/startx /usr/bin/emacs -g 90x37+150+0 -- /usr/bin/X :0 -multiwindow -clipboard"

(this assumes you installed Cygwin under C:\cygwin64\)

For further help, try these lists (which I found useful):

For cygwin issues, unless it’s an X problem, in which case use See also:

For emacs issues, see the EmacsMailingLists.

CategoryWThirtyTwo CategoryPorts