If you enjoyed this site, please consider donating $3. Any amount is appreciated. Thanks!

Emacs and Microsoft Windows Tips

Xah Lee, 2009-06-10, 2009-08-21

This page provides some tips about using Emacs with Microsoft Windows OS.

To install emacs for Microsoft Windows OS, go to: http://www.ourcomments.org/Emacs/EmacsW32.html (just download the “EmacsW32+Emacs Install Wizard”) The website mentions many technical details for advanced emacs users, such as source code location, how to compile, patch vs unpatch, difference with GNU Emacs... etc, but it shouldn't matter to you if you just want to use emacs.

After you download, run the installer, everything should work fine.

When you launch emacs for the first time, it will show you a screen about setting up. You can show this screen anytime by going to the menu “Options‣Customize EmacsW32...”.

EmacsW32 startup cust

The Customization screen invoked by the menu “Options‣Customize EmacsW32...”

Just click on the “Set all to EmacsW32 style!”, and you should have emacs behave like most Windows aplication.

Correcting Path Variable

Emacs uses the exec-path to find some of its programs, such as gzip, diff, etc. In EmacsW32 by default, you may find unnecessary dir by default such as “C:/Program Files (x86)/QuickTime/QTSystem/”. Here's how to correct it:

(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/"
)
 ))

(info "(elisp) Subprocess Creation")

Visual Basic, PowerShell and other Modes

Emacs by default does not include modes for Visual Basic (VBA, VBScript, ASP), PowerShell, PowerShell interactive shell. Here's where to get them:

Emacs 22 or 23 also doesn't have modes for JavaScript (JScript). You can download them at:

js2-mode by Steve Yegge http://code.google.com/p/js2-mode/.

Command Line Shells

EmacsW32 provides you with 3 interactive OS shells: cmd-shell, cygwin-shell, msys-shell. The cmd-shell starts Windows's “cmd.exe”. The cygwin and msys runs unix shells of Cygwin and MinGW (both are ports of unix dev system to Windows). If you don't have unix background, you don't need to worry about Cygwin or MinGW. By default, the command “shell” will start cmd-shell.

Using Cygwin

If you came from a unix background, 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, you'll have all bash and shell utils, ssh, vi, emacs, cvs, subversion, git, gcc, as well as X11, or entire KDE or Gnome. MinGW is derived from Cygwin, and is minimal system, mostly suitable for compiling unix software on Windows. It includes the suite of shell utils, and gcc environment.

If you are using cygwin, see: Installing Cygwin Tutorial.

Some of emacs's features require unix utilities. For example, spell checking requires aspell, image thumbnail preview requires imagemagick suite, checking difference between files require diff, listing files with particular suffix requires unix “find” (used by find-dired).

However, if you are not familiar with unix, you don't need to worry about these. You can mostly have all these functionalities by calling emac's interactive shell command “shell”, or once-time shell command by typing “Alt+x shell-command”, and these will call Windows's “cmd.exe”, or Windows PowerShell if you have it installed and setup.

Cygwin and EmacsW32

If you are using emacsW32, then you can go to the cygwin shell by calling the command cygwin-shell. First, you need to set the cygwin-shell path. This you can do by pulling the menu under “Options‣Customize emacsW32”. Or, you can put the following line in your .emacs: “(setq w32shell-cygwin-bin "C:\\cygwin\\bin")”.

Once you have the w32shell-cygwin-bin set, the command “shell” will also invoke cygwin-shell. If you want run plain Windows's “cmd.exe” shell, you can call cmd-shell. EmacsW32 also has msys-shell, which is for those who are using MinGW.

Note, when using cygwin shell in emacsW32, if the $PATH env var is not set correctly, it can cause Window to mistakingly popup a dialogue saying some program crashed. For a example, see: http://xah-forum.blogspot.com/2009/06/cygwinimagemagickemacsw32-causes-vista.html.

To fix shell env var in emacs, you can use the following:

(when (string-equal system-type "windows-nt")
  (setenv "PATH"
        (concat
         "C:\\cygwin\\usr\\local\\bin" ";"
         "C:\\cygwin\\usr\\bin" ";"
         "C:\\cygwin\\bin" ";"
         "C:\\Program Files (x86)\\Emacs\\emacs\\bin\\" ";"
         "C:\\Windows\\system32" ";"
         "C:\\Windows" ";"
         "C:\\Windows\\System32\\Wbem" ";"
         "C:\\Windows\\Program Files (x86)\\PHP" ";"
         "C:\\Windows\\Program Files (x86)\\Java\\jdk1.6.0_14\\bin" ";"
         "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\"
         )
        ) )

See also: Difference between Emacs's “(setenv PAHT ...)” and “(setq exec-path ...)”.

(info "(elisp) System Environment")


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”.

FTP in GNU Emacs for Windows does not seem work?

Yes, GNU Emacs for Windows's ftp facilities are broken out of the box. It is a well known problem. The reason seems to have to do with Windows's bundled FTP program at “C:/Windows/system32/ftp.exe”. The solution is to use the one bundled with emacsW32 at “C:/Program Files (x86)/Emacs/EmacsW32/gnuwin32/bin/”. You should have this path in your exec-path. If you are using EmacsW32, ftp should work out of the box.

To find out what ftp program emacs is trying to interface, put this code: “(executable-find "ftp")” in a empty buffer, select it, type “Alt+x eval-region”.


Related essays:

2006-07
© 2006 by Xah Lee.