Xah Lee, 2009-06-10, …, 2011-03-28
This page provides some tips about using Emacs with Microsoft Windows OS. The info on this page is tested on Windows Vista, but should work in Windows XP and Windows 7.
On Windows, i recommend ErgoEmacs. It is a emacs distribution by me and David Capello. With ErgoEmacs, we try to make the Windows Emacs experience smooth. (this opinion is obviously biased).
Where to download a ready-to-use emacs for Windows?
Where to get language modes for Visual Basic, Javascript, “cmd.exe”, PowerShell?
A javascript mode is bundled with emacs 23.2 (see: Emacs 23.2 Features.) But you can also get them at:
There are several packages for cmd.exe batch file, written by different people. You may want to try them in the order listed here:
See also: How to Install Emacs Packages.
Where is emacs's init file? the “.emacs”?
That depends on whether if you have the HOME environment variable setup. If not, look at:
on Windows Vista and Windows 7 C:\Users\xah\AppData\Roaming\ on Windows XP C:\Users\xah\Application Data\
If you don't know how to set env var, see: Windows Environment Variables.
What's emacs's init file name?
By default, it is 〔$HOME/.emacs〕 or 〔$HOME/.emacs.d/init.el〕.
How to find out if my emacs's init is loaded?
Type some garbage in your init file, then restart emacs. If emacs starts with error, then you know it's loaded.
Or, you can put the following code:
(set-background-color "pink")
When i type 【Ctrl+SPACE】, Windows switches me to other language input. What to do?
You can disable the Windows shortcut that switches you among input methods of different languages. Here's the exact instruction for Windows Vista. Other Windows version should be similiar.
Go to 〖Start▸Control Panel〗. Choose Classic View on the left. Then, double click on the “Regional and Language Options” icon, then go to “Keyboards and Languages” tab, click on “Change Keyboards…”. Then, go to “Advanced Key Settings” tab, then, it should list Key sequences on the right column. Select a input choice that has shortcut key, then click the button “Change Key Sequence”.
When i type 【Ctrl+Alt+s】, HP System info came up. How to disable that?
See: Disable Ctrl+Alt+S of HP Support Information.
If you have other key combo that mysteriously launchs some other program, basically, you want to find the shortcut file that launches it, right click and choose “Properties”, then in Shortcut tab, change the shoctuct key field there.
How to run bash shell or PowerShell inside emacs?
By default, the command named “shell” will run the interface to “cmd.exe”.
ErgoEmacs has several shells bundled. You can find them in the menu 〖Tools▸Shell〗. You can also call them by name.
| Emacs Command Name | Shell Interface To |
|---|---|
| shell | Windows cmd.exe |
| powershell | Windows PowerShell |
| msys-shell | Bash (from MSYS) |
| cmd-shell | Windows cmd.exe |
| eshell | bash-like shell written in emacs lisp |
See also: PowerShell Tutorial ◇ Emacs: What's eshell? “eshell” vs “shell” Difference?.
FTP in GNU Emacs for Windows does not seem work?
If you are using ErgoEmacs or Lennart's EmacsW32, it should work out of the box.
GNU Emacs for Windows's ftp facilities are broken out of the box. The problem is due to some incompatibility of emacs ftp interface with Windows's bundled FTP program at 〔C:/Windows/system32/ftp.exe〕.
To find out what ftp program emacs is trying to interface, type this code:
(executable-find "ftp") in a empty file, select it, then call “eval-region”.
When emacs launches, it inherits Windows's env vars. So, you can set your Windows's env var and emacs will have it.
If you don't know how to set env var, see: Windows Environment Variables. For how to do it with PowerShell, see: Using PowerShell to Manage Environment Variables.
Two env var important to emacs are HOME and PATH.
Normally, you should set a HOME env var. Here's how you do it in cmd.exe:
REM example of setting HOME env var setx HOME "C:\Users\mary"
Note: case does not matter in env var names, nor cmd.exe's command names.
Once you have HOME env var set, emacs will save its customization file “.emacs” at your home dir.
If you do not have a env var named HOME, then emacs may save the “.emacs” file at 〔C:\Users\mary\AppData\Roaming\〕.
If you are running emacs within cygwin, then the init file will be at 〔~/〕.
You can also set environment variables within emacs without actually setting them in the OS. To do so, use this sample code:
; show env var named path (getenv "PATH") ; example of setting env var named “path” ; by appending a new path to existing path (setenv "PATH" (concat "C:\\cygwin\\usr\\local\\bin" ";" "C:\\cygwin\\usr\\bin" ";" "C:\\cygwin\\bin" ";" (getenv "PATH") ) )
In some situations, it's better to set some env var inside emacs for emacs only. This way, you are free to have a different env var value in your cmd.exe or cygwin shell, independent of emacs.
Emacs has a variable named “exec-path”. Its value is a list of dir paths. Emacs uses “exec-path” to find executable binary programs. For example, when spell checking, emacs will try to find ispell or aspell in exec-path. When you press Z to compress file in dired, emacs will try to find gzip or gunzip in exec-path. When you type 【Alt+x diff】 or 【Alt+x grep】or 【Alt+x shell】, emacs will try to find the program in exec-path too.
If emacs complains that it cannot find ispell or ftp or gzip etc, the problem is probably with your exec-path.
Emac's “exec-path” variable and and the value of the env var “PATH” in emacs, have slightly different purposes. When you are running a shell in emacs, emacs uses the env var PATH to find programs, similar to when you are using a shell in a terminal. The exec-path is used by emacs itself to find programs it needs for its features, such as spell checking, file compression, compiling, grep, diff, etc.
By default, emacs inherits the PATH env var from the OS, and copies
its value to emacs variable exec-path too. So that, the output of
(getenv "PATH") and the value of “exec-path” variable, are
equivalent.
But if you did set the PATH env var within emacs (e.g. by (setenv "PATH" …)), you probably also want to adjust your exec-path. Here's a example of setting exec-path:
(when (string-equal system-type "windows-nt") (setq exec-path '( "C:/Program Files (x86)/Emacs/emacs/bin/" "C:/Program Files (x86)/Emacs/EmacsW32/gnuwin32/bin/" "C:/Windows/system32/" "C:/Windows/" "C:/Windows/System32/Wbem/" "C:/Windows/system32/WindowsPowerShell/v1.0/" ) ))
For detail about env var and exec-path, see: Difference Between Emacs's “(getenv PATH)” and “exec-path”.
Some of emacs's features require unix utilities. For example, spell checking requires “aspell”, image thumbnail preview requires ImageMagick, checking difference between files require “diff”, listing files with particular suffix requires unix “find” (used by find-dired).
ErgoEmacs has the complete set of unix utility bundled. They are in the dir 〔C:\Program Files (x86)\ErgoEmacs\msys\bin〕.
If you came from a unix background, and is not using ErgoEmacs, you may want to install unix shell and utilities such as “diff”, “find”, “grep” etc. There are 2 good solutions: Cygwin and MinGW.
Cygwin is a complete unix solution. After installing Cygwin core, you'll have bash and grep, cat, awk, sort, uniq etc. You can also install any extra unix packages, for example: vi, svn, rsync, unison, wget, curl, git, gcc, X11, or entire KDE or Gnome.
MinGW is a minimal system derived from Cygwin. It is designed for compiling unix software on Windows. It includes the suite of shell utils, and gcc environment.
See also: Installing Cygwin Tutorial.