How to best integrate Emacs and Cygwin?
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?
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.
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.
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.
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.
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)
)
I'm using wsl2 with the win32 27.1 distribution. I followed the instructions here: https://www.emacswiki.org/emacs/NTEmacsWithCygwin The only change I made was this:
(let* ((cygwin-root "//wsl$/Ubuntu/")
Where Ubuntu is your distribution.
I don't have the proper /mnt/c working yet.
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.
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")
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:
- Re: /cygdrive/c vs c:
- cygwin-mount.el
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.
I investigated three options, all with windowed (but not X11) versions of Emacs. (The terminal is too hardcore for me.) Here goes:
- The XEmacs that comes with Cygwin
- EmacsW32
- Standard Emacs for Windows
The Cygwin folks want to steer you to their Emacs/XEmacs. In http://cygwin.com/faq/faq-nochunks.html#faq.using.ntemacs, they write "Note that all of this ``just works'' if you use the Cygwin port of Emacs or XEmacs from Cygwin Setup".
Be sure to install the xemacs-sumo package in addition to xemacs; otherwise M-x shell won't work. You can launch xemacs without using X11 as
DISPLAY= xemacs &
Drawbacks: 1) Boy, this is an old Emacs. I didn't really want to soldier on with this when everyone else is using Emacs 23. 2) I found it mildly annoying that the install required a whole bunch of X11 libs even if you aren't running X11. 3) No cua-mode out of the box.
EmacsW32 (http://ourcomments.org/Emacs/EmacsW32.html) has a one-click installer, a M-x cygwin-shell command, and CUA mode. But tab completion in the Cygwin shell uses Windows paths, which drove me crazy. The W32 port doesn't seem to be actively improved since 2008, but they provide installers with more recent Emacs versions.
The standard Emacs for Windows seems to be the best bet. Download from http://ftp.gnu.org/pub/gnu/emacs/windows/, unzip, and launch from inside Cygwin. Then it picks up the home directory etc. Paste the mumbo-jumbo from http://cygwin.com/faq/faq-nochunks.html#faq.using.ntemacs into ~/.emacs. Restart Emacs and run M-x shell. All works as expected.
FWIW, I use the normal GNU Emacs Windows releases, and I use Cygwin. I've never had any problems, but I don't do much with Cygwin outside Emacs. Oh, and I'm using an old version of Cygwin (with all versions of Emacs).
For setup, I load these two files, in order:
- http://www.emacswiki.org/emacs/cygwin-mount.el
- http://www.emacswiki.org/emacs/setup-cygwin.el
Build emacs from source:
-Download the latest stable release (24.5 as of this writing).
-Unzip and cd into the emacs folder
-Run these steps in order:
$ ./autogen.sh
$ ./configure --with-w32
$ make
$ make install
-Copy emacs.exe, by hand, from the "emacs folder"/src to cygwin/bin
-Run emacs:
$ emacs&
精彩评论