Emacs and Microsoft Windows Tips

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

This page are tips about using Emacs on Microsoft Windows. The info on this page is tested on Windows 7 and Windows Vista.

Where is emacs's init file located?

By default, it's at:

If you have the environment variable named “HOME”, then it's at:

“HOME” should not be confused with “HOMEPATH”.

See: Windows Environment Variables Basic Tutorial.

What's emacs's init file name?

By default, emacs looks for the following in order:

The file can be byte-compiled, ending in “.elc”.

(info "(emacs) Find Init")

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 in your init file:

(set-background-color "pink")

Where to download a ready-to-use emacs for Windows?

See: Where to Download Emacs for {Windows, Mac, Linux}.

How to start emacs?

For Windows users, after download, unzip it. Go to the folder, in the “bin” dir, then click on file runemacs.exe to launch.

To run emacs inside Windows Console, start like this:

C:\Users\mary\apps\emacs-24.1\bin\emacs.exe --no-window-system

How to start emacs with default dir at home dir?

Create a Windows shortcut, then set the “Start in” field.

Windows 7 GNU emacs shortcut properties 2012-06-15
GNU emacs shortcut properties, in Windows 7.

To create a file shortcut:

  1. Hold Alt then drag that runemacs.exe icon to desktop.
  2. In the newly created alias icon, right click to open file properties. Then, in the “Start in” field, enter %home%.
  3. In the “Target” field, you can add your own init files. For example, here's mine: %home%\apps\emacs-24.1\bin\runemacs.exe -q --load=%home%\ErgoEmacs_dev\init.el --load=%home%\.emacs. Here, i suppress loading init files by -q, but load ErgoEmacs init files, then load my personal init files.

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.

  1. Go to 〖Start ▸ Control Panel〗.
  2. Choose Classic View on the left.
  3. Double click on the “Regional and Language Options” icon, then go to “Keyboards and Languages” tab, click on “Change Keyboards…”.
  4. Then, go to “Advanced Key Settings” tab, then, it should list Key sequences on the right column.
  5. 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.

How to run Bash shell or PowerShell inside emacs?

By default, the command named shell will run “cmd.exe” inside emacs.

You can use eshell. Emacs: M-x eshell.

For powershell, install the powershell package. 〔➤ Emacs: How to Install Packages Using ELPA, MELPA

Where to get language modes for Visual Basic, “cmd.exe”, PowerShell?

With emacs 24, they are probably in MELPA repository. See: Emacs: How to Install Packages Using ELPA, MELPA.

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

Environment Variables

Two environment variable important to emacs are HOME and PATH.

Note: by default Windows 7 and Windows Vista has HOMEPATH, but not HOME.

Setting Your Home Dir

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"

If you are running emacs within Cygwin, then the init file will be at ~/.

See: Windows Environment Variables Basic Tutorial.

Setting Environment Variable for Emacs Only

See: Emacs: Set Environment Variables within Emacs.

Using Cygwin

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

If you came from a unix background, you may want to install unix shell and utilities such as {“diff”, “find”, “grep”, …}. I recommend Cygwin.

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.

See also: Installing Cygwin Tutorial.

Like it? Buy Xah Emacs Tutorial.
blog comments powered by Disqus