Posted on 09-08-2012
Filed Under (Technology) by bigbang

The Emacs configure file is put under HOME path by default. So, the only thing we need to do is to put .emacs into HOME path and Emacs works. But is it the best way to do it under Windows? Let me introduce three ways to do this job and I think you can find your best way.

The first way, we can change HOME path value

But by doing this, we also change the value of $HOME environment variable, and will affect Cygwin or some other applications which also need Windows HOME path to do something.

The second way, let Emacs load the specifc .emacs file

We don’t change the HOME path of Windows, but let default .emacs file to read our own Emacs configure file and reset Emacs HOME path in this file by Emacs lisp. Let me show you how to do it.

You can use C-x C-f command and open ~/.emacs file (by default, the file is under folder C:/Documents and Settings/water/Application Data).

If there is no such file under ~/ path, we can create .emacs file in Emacs: just open ~/.emacs file, modify the file and save it! You can also use _emacs instead. Then put following sentences in .emacs file:

(load-file "E:/water/.emacs")

File E:/water/.emacs is the real .emacs for our Emacs here, and we can put the real sentences which we want to use to load our Emacs. The first thing we need to do is to set the home path:

(setenv "HOME" "E:/water") 
(setenv "PATH" "E:/water") 
;;set the default file path 
(setq default-directory "~/") 
(add-to-list 'load-path "~/emacs/site-lisp")

The advantage of this method is very simple and we can backup .emacs file easily, and will never affect any other applications.

The third way, modify Windows Registry and add Emacs directory info

We can add this item to Windows Registry to let Emacs load specific .emacs file:



We can use above three ways to set Emacs Home path, but what’s the sequence which Emacs will use to load configure file? The normal sequence is:

  1. If you have set the environment variable HOME, then Emacs will use HOME as root folder.
  2. If you have set the Regiestry item HKCU\SOFTWARE\GNU\Emacs\HOME, then Emacs will use this as HOME path. This method is not recommended because it will make all users share the same HOME path.
  3. If file C:\.emacs exits, then Emacs will use C:\.emacs to set variables. By doing this, Emacs can be compatible with older Emacs configure file.
  4. Use user’s AppData path as HOME path (usually, in Windows XP it is something similar to C:/Documents and Settings/water/Application Data). The user AppData path changes according to Windows Edition.

The second way is my best choice, simple and convenient.

(1) Comment    Read More