4

I am using the latest version of Emacs on Windows 7.

I unzipped Emacs to: C:\Users\MyName\OneDrive\emacs

.emacs.d is in: C:\Users\MyName\AppData\Roaming

I would like to have to set up .emacs.d in C:\Users\MyName along with an init.el instead of ~.emacs. Do I transfer .emacs.d to the new location or create a new .emacs.d folder?

I assume changing the .emacs.d location will also require me to change %HOME%. If so, how do I change the home variable?

Stefan
  • 26,154
  • 3
  • 46
  • 84
curious-scribbler
  • 185
  • 1
  • 1
  • 8

2 Answers2

8

I really like the answer posted by @Ryan here.

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

P.S. I cannot make a comment, so I posted an answer.

Firas
  • 131
  • 1
  • 7
  • 1
    "All problems in computer science can be solved by another level of indirection" (the "fundamental theorem of software engineering") -- David Wheeler. – NickD Jun 16 '18 at 01:28
  • 1
    *this* file beeing ``C:\Users\Username\AppData\Roaming\.emacs``. Everything is in the manual : ``M-x`` ``info-emacs-manual`` >> Emacs and Microsoft Windows/MS-DOS >> Windows HOME – Flint Oct 02 '18 at 11:10
  • I appreciate this response so much, as well as the pointer to the manual. Thanks! – taranaki Sep 28 '20 at 22:04
7

Well, based on the manual and my memory of how I set up my emacs configuration, you're correct, you'll need to set up the HOME environment variable.

You can set up the HOME variable on Windows 7 by going to the Control Panel > System > Advanced System Settings > Advanced > Environment Variables… and checking the User Variables for < User Name > list.

If there isn't already a user variable called HOME in that list, just press “New” and put one in pointing to the directory you want. Not exactly sure if there are any other programs that use HOME as an environment variable, but so far I've not encountered any other program in Windows that uses it.

Tariq Kamal
  • 390
  • 1
  • 9
  • I think I didn't make my question clear. Before changing User Variables, I'd need to make changes to .emacs.d and make a new init.el. How do I transfer my .emacs.d to a new location and have an init.el within it. – curious-scribbler Feb 16 '15 at 13:12
  • @curious-scribbler -- If you have changed your home environment correctly, Emacs will create a new `.emacs.d` folder in that new home directory when you launch Emacs. You can either use a `.emacs` file in the new home directory for your user configurations, or you can create an `init.el` and place it inside your new `.emacs.d` folder. In terms of copying anything over from the previous installation, you can use Windows Explorer to copy / paste until you are more comfortable with using Emacs (which contains other possibilities for copy / paste). – lawlist Feb 16 '15 at 16:17
  • @curious-scribbler: What @lawlist said, although I'm a little mystified. I just copy my existing `init.el` into an `.emacs.d` directory in the `HOME` directory I set up, using Windows Explorer. They're really just text files you can move about, which is great for backing up and synchronizing your emacs settings across multiple machines. – Tariq Kamal Feb 17 '15 at 06:07
  • @TariqKamal I am completely confused at the moment. Can you please break this down for me. Should I change my HOME or redirect emacs to load something else? – curious-scribbler Feb 17 '15 at 06:27
  • @curious-scribbler: Well, what _I_ did was change my `HOME` variable to `C:\Users\UserName` and moved my existing `.emacs.d` directory to `C:\Users\UserName` (in your case, if you haven't made any customizations, just create your `.emacs.d` directory and `init.el` file). That's worked okay for me. – Tariq Kamal Feb 18 '15 at 07:33