tags:

views:

998

answers:

6

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:

  1. Use the Emacs that comes with Cygwin. (Then find a way to get to cmd.exe if you want it.)
  2. Use NTEmacs and Cygwin as a "sometimes" shell. (A special command to launch Cygwin)
  3. 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:

  1. M-x whois doesn't work on NTEmacs.
  2. Packages like Wanderlust include a Makefile that isn't Windows friendly.
  3. 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?

A: 

I like the xemacs version that you get from the Cygwin setup program. Works out of the box, the Alt key maps to Meta just fine, and the bash shell buffer is there whenever you need it.

mobrule
+1  A: 

The third option. I am using NTEmacs + EmacsW32 + Cygwin. This way I have a native Windows application with Unix utilities and bash shell. The makefiles work, I have never used M-x whois though. I cannot think of any immediate drawbacks of this setup.

Here are interesting bits of my setup, basically very similar to http://www.emacswiki.org/emacs/NTEmacsWithCygwin:

(setq cygwin-root "c:/cygwin/")
(setq private-bin (concat home-dir "/usr/bin"))
(setq exec-path (cons private-bin exec-path))
(setenv "PATH" (concat private-bin ";" (getenv "PATH")))
; Add Cygwin Emacs stuff
(add-to-load-path "/usr/share/emacs/site-lisp")
; Add Cygwin Info pages
(add-to-list 'Info-default-directory-list
             (concat cygwin-root "usr/share/info/"))

(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)

(setq w32shell-cygwin-bin "c:\\cygwin\\bin")
(require 'w32shell)
(w32shell-add-emacs)
(w32shell-set-shell "cygwin")
Laurynas Biveinis
+3  A: 

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.

ak
Are you assuming the Cygwin Emacs here?
Laurynas Biveinis
Yep, I should have mentioned that. NTemacs probably won't work in any of those terminals since presumably it requires the console.
ak
Interesting 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.
User1
I 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.
ak
Are 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: http://chadaustin.me/2009/10/reasons-why-mintty-is-the-best-terminal-on-windows/
User1
+4  A: 

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.

justinhj
+1 for gnuwin32
Laurynas Biveinis
+1  A: 

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)
)
Jonathan Arkell
A: 

Just like @justinhj, I use the native version of emacs on windows in conjunction with the (also native) ports of gnu utils (e.g. binutils for 'strings', etc.).

And I always use cygwin as the shell, within Emacs or independently of Emacs. That way, I retain the look & feel of my work environment when I switch back & forth from Windows to/from Linux/AIX/Solaris.

Unfortunately however, when I upgraded my Emacs from 21.2 to 23.2, Emacs lost its ability to recognize '/cygwin/c' by default. I have to research this now to see why it isn't working anymore and what I can do to fix that. I just found the following information and I'll check it out to see whether this is helpful. It seems odd that now that I need an external package for something that used to be always there by default:

I prefer, however, to minimize the use of additional packages. So, I just checked further the behavior of my "new" Emacs + Cygwin and it seems that I can access the C: drive by simply typing '/'.

That is cool - only one character (slash) instead of /cygdrive/c. However, the shell within Emacs prompts with '/cygdrive/c', a somewhat confusing difference.

Android Eve