I am using a Windows 7 computer and do not have administrator access. Therefore I can not place a dot emacs file in the root directory. Is there a way for me to specify a different location for the dot emacs file?
Emacs has several places it looks for init files, as documented in the manual. If you want to customize Emacs you must start with one of those files.
A common approach is to use the file
init.el in your
user-emacs-directory, instead of having a
.emacs in your HOME directory.
user-emacs-directory defaults to
~/.emacs.d, so it is still relative to your HOME, but the benefit of this approach is you can keep everything related to your Emacs configuration in one place. That directory could be under version control, backed up, shared across multiple machines, etc. You can use a symlink (
mklink on Windows) to keep the files in some other location.
For example, it is quite common to see folks maintain their Emacs configuration on Github. You can find lots of examples of this by searching Github for elisp projects with init.el files.
On every Windows install on which I use Emacs, I have the following code in a
.emacs file at the listed location:
;; Place this file in C:\Users\Username\AppData\Roaming and point to the appropriate files (setq user-init-file "C:/path/to/.emacs") (setq user-emacs-directory "C:/path/to/.emacs.d/") (setq default-directory "C:/whatever/you/want/to/start/in") (setenv "HOME" "D:/my/home/directory") (load user-init-file)
This way I can put my
.emacs.d/ anywhere I want.
Your .emacs file goes in your
HOME directory. From the Emacs manual:
The Windows equivalent of HOME is the user-specific application data directory. The actual location depends on the Windows version...
You can override this default value of HOME by explicitly setting the environment variable HOME to point to any directory on your system. HOME can be set either from the command shell prompt or from ‘Properties’ dialog of ‘My Computer’. HOME can also be set in the system registry, see MS-Windows Registry.
I know how to set the home directory however for version control reasons I want to be able to set emacs to read from a different directory (so that I can have a directory specific to emacs).
Your init file goes in your home directory, which you can put anywhere. Apparently you want to have a different directory for stuff that Emacs loads. That's not a problem. Put your init file in your home directory, and have that file add another directory to the value of variable
load-path and then require whatever other Emacs libraries you want to use. Put those libraries in that other directory.
IOW, your init file need not contain anything beyond setup of the directory where you keep the Emacs libraries that you want to load.
Just for the sake of completeness, I provide a link to:
Which says that you can set a
HOME value in the registry path:
But this value is overridden by the environment variable
Think you could put
(setq user-init-file "C:/path/to/.emacs") and other lines proposed by @ryan into site-start.el
Your site may also have a site startup file; this is named site-start.el, if it exists. Like default.el, Emacs finds this file via the standard search path for Lisp libraries. Emacs loads this library before it loads your init file.