How to best integrate Emacs and Cygwin?
Solution 1
Use the Emacs in Cygwin. Not XEmacs..Emacs. I just install everything from Cygwin and type the following to run Emacs:
XWin -multiwindow export DISPLAY=:0.0 emacs&
It may also help to create a link to your C drive (or any other drive) like so:
ln -s /cygdrive/c /c
I've been using this for several months and it always works well. I constantly use advanced features like TRAMP and subversion without any issues. All advanced packages like cedet just work.
If you hadn't noticed, I am the original poster. After all of my research and attempts, this one worked and I am VERY PLEASED. Good job Cygwin!
Also, I recommend not using shell within Emacs. Utilities like top
just don't seem to work. Instead, use MinTTY and screen. Cygwin gives you ssh directly in MinTTY (you don't need putty). The best part is that a lot of my Linux knowledge works seamlessly in Windows.
Solution 2
The best solution must be cygwin emacs-w32. It using win32 native gui, and using cygswin POSIX system. That means you have a windows native gui program and all the cygwin path, shell working.
Installation is very easy: setup.exe --> emacs-w32. Now the version number is:24.2.93.1
So good.
Solution 3
A fourth choice is to run emacs in one of Cygwin's alternative terminals: (u)rxvt, mintty, xterm. These all offer much better terminal emulation than the console, which means a much improved emacs experience.
Solution 4
I tend to use the native version of emacs on windows in conjunction with the (also native) ports of gnu utils, which are much faster, though less complete, than the Cygwin ones.
Then I just use a cygwin window for the bash shell and the things that are missing.
Solution 5
I installed cygwin on the root. It explicitly warns you against it, but I saw no ill effects. (I found that piece of advice from Steve Yegge).
I also installed cygwin-mount, which helps a bunch. Also, I had to switch from ispell to aspell. Finally, a little bit of .emacs tweaking, and I was good to go:
;;;;;;;;;;;;;;;;;;;;;;
;;CygForTheWin
;;*cygwin
(when (equal system-type 'windows-nt)
(message "Setting up Cygwin...")
(let* ((cygwin-root "c:")
(cygwin-bin (concat cygwin-root "/bin"))
(gambit-bin "/usr/local/Gambit-C/4.0b22/bin/")
(snow-bin "/usr/local/snow/current/bin")
(mysql-bin "/wamp/bin/mysql/mysql5.0.51a/bin/"))
(setenv "PATH" (concat cygwin-bin ";" ;
snow-bin ";"
gambit-bin ";"
mysql-bin ";"
"c:/usr/local/jdk1.60_03/bin/"
".;")
(getenv "PATH"))
(setq exec-path (cons cygwin-bin exec-path)))
(require 'cygwin-mount)
(cygwin-mount-activate)
(setq shell-file-name "bash")
(setq explicit-shell-file-name "bash")
(defun jonnay-cygwin-shell ()
"Wrapper around cygwin-shell so that it doesn't throw an error"
(interactive)
(condition-case e
(cygwin-shell)
(message "There was an error trying to launch the shell: %s" e)))
(message "Setting up Cygwin...Done")
;; found from the manual, check, use and make go?
(defun my-shell-setup ()
"For Cygwin bash under Emacs 20"
(setq comint-scroll-show-maximum-output 'this)
(setq comint-completion-addsuffix t)
(setq comint-eol-on-send t)
(setq w32-quote-process-args ?\")
(make-variable-buffer-local 'comint-completion-addsuffix))
(setq shell-mode-hook 'my-shell-setup)
(add-hook 'emacs-startup-hook 'jonnay-cygwin-shell)
)
Related videos on Youtube
Sousou
Updated on September 25, 2020Comments
-
Sousou over 3 years
There are a ton of ways to integrate Cygwin with Emacs on Windows. EmacsWiki shows a few ideas. Here are the options that I've found:
- Use the Emacs that comes with Cygwin. (Then find a way to get to cmd.exe if you want it.)
- Use NTEmacs and Cygwin as a "sometimes" shell. (A special command to launch Cygwin)
- Use NTEmacs and Cygwin as the "always" shell. (M-x shell launches cygwin)
To give some clarity as to "why". Here are a couple of examples where I wish I had Cygwin with Emacs:
- M-x whois doesn't work on NTEmacs.
- Packages like Wanderlust include a Makefile that isn't Windows friendly.
- Sometimes I just need a bash shell for something.
So which option of Emacs/Cygwin works well for others? Also, has anyone tried MSYS integration successfully?
-
Laurynas Biveinis over 14 yearsAre you assuming the Cygwin Emacs here?
-
ak. over 14 yearsYep, I should have mentioned that. NTemacs probably won't work in any of those terminals since presumably it requires the console.
-
Sousou over 14 yearsInteresting idea. Do you notice much of a lag in performance (seeing it's not native like NTEmacs)? Also, how do you launch one of these terminals and which one do you like best? Thanks for the reply.
-
ak. over 14 yearsI haven't used NTemacs, so couldn't really compare, but Cygwin isn't as non-native as many people think. The program code itself runs natively anyway; it's just the POSIX API calls that need to be mapped to Windows, and in most cases that's a pretty thin mapping layer. fork() is the big exception, but that shouldn't matter in an editor. Regarding the terminal I'd recommend mintty, but I'm biased because I wrote it.
-
Sousou over 14 yearsAre you suggesting running emacs in curses mode (no GTK UI) under a terminal program? BTW I looked into it and mintty is very cool. Did you see this blog post: chadaustin.me/2009/10/…
-
Sousou over 13 yearsI haven't tried XEmacs with Cygwin, but the Emacs version in Cygwin is currently at 23.
-
Vincent about 8 yearsHuh. When I try this, I get
$ -bash: XWin: command not found
bash: -bash:: command not found
-
Apteryx about 8 years@Vincent: You have to install an X11 server. Using the excellent apt-cyg companion of Cygwin (https://github.com/transcode-open/apt-cyg#quick-start), here's what I needed to install:
apt-cyg install xorg-server xinit emacs-X11
. After that, User1's instructions should work. There is more detail available here regarding setting up X with Cygwin: http://x.cygwin.com/docs/ug/setup.html#setup-cygwin-x-installing -
Apteryx almost 8 yearsThis is a good solution, but there are caveats: 1) By default the emacs-w32.exe opens a useless shell Window when started from GUI instead of the CLI. This can be fixed by creating a script based on "C:\cygwin\bin\run.exe emacs-w32". Another (more annoying) caveat persists: it's impossible to right-click on a file to open it in Emacs (or associate emacs-w32 as default application to open some files): the path of the file passed to emacs-w32 is prefixed by "/cygdrive/c/Windows/system32/", and it fails to open :(
-
Apteryx almost 8 yearsI've added an example of a run script that can be used to associate Cygwin's emacs-w32 to any file type on Windows; see emacs.stackexchange.com/a/24390/11807
-
Henrik K about 5 yearsSmall detail - first execute the xwin multiwindow command in one cygwin prompt - then open another one and execute the export and emacs commands.