15

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?

  • If you can control your own location of the Emacs installation (e.g., putting it wherever you want, or at least have write access to the installation), then you can take complete control by using something like site-start.el to load your own init.el and you no longer need a .emacs. In this example, you don't need to fiddle with the home directory (unless someone else on the computer is putting stuff in there that will affect what you do). In other words, it can be blank and you never need to touch it. – lawlist Jun 3 '15 at 19:14
4

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.

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

  • I like this solution and would like to use it however it still does not tell me how to change my user-emacs-directory – Startec Jun 4 '15 at 0:11
  • My suggestion was to use symlinks, really. As shown by the other answers you need to put something in one of the standard locations Emacs reads during init, even if all it does is load your config from somewhere else. – glucas Jun 4 '15 at 0:22
  • The manual link is broken. – corvus_192 Sep 10 '17 at 10:20
15

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 and .emacs.d/ anywhere I want.

  • Thank you, almost just what I needed. I left off the default-directory and sentenv HOME but otherwise it's what I needed to setq! – Grant Bowman Dec 10 '17 at 4:01
  • I tried Ryan's answer. But, now I am not able to open this file within emacs from AppData\Roaming folder. Kindly excuse me, as I couldn't add comment because, I don't have 50 points yet. – Sreekumar R Dec 16 '17 at 9:53
  • @SreekumarR Your should ask a new question, linking to this one, instead of posting an "Answer" – Andrew Swann Dec 16 '17 at 11:14
  • @SreekumarR If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Stefan Dec 16 '17 at 13:18
5

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.

  • 1
    Yes, 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) – Startec Jun 3 '15 at 18:21
  • 3
    Note that this hack makes Emacs consider something else as the home directory. – wasamasa Jun 3 '15 at 18:34
1

You say:

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.

1

Just for the sake of completeness, I provide a link to:

https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Location-of-init-file.html

Which says that you can set a HOME value in the registry path:

HKCU\SOFTWARE\GNU\Emacs\HOME

But this value is overridden by the environment variable HOME.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.