19

I installed emacs 23.3.1 in c:/emacs-23.3. Following the hints in this page, I updated the site-start.el to set HOME environment variable.

(setenv "HOME" "c:/users/USER/emacs")

And I made c:/users/USER/.emacs (like I did in unix/mac) to write the code for using slime, but it doesn't seem to start slime correctly.

Is this a correct way of setting emacs in Windows 7? Where do I put the .emacs file?

prosseek
  • 182,215
  • 215
  • 566
  • 871

8 Answers8

25

You need to set HOME in environment variables in Computer settings (if I remember correctly), or put init file to default directory (just start Emacs, and press C-x C-f ~/ to see what is actual directory). And as I remember, on Windows, init file could be called _emacs...

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • I've caught pieces of discussion re: _emacs. I've decided to go with renaming from cmd prompt, while in directory, `ren _emacs .emacs`. – Brady Trainor Nov 25 '13 at 06:31
  • 6
    Changing the HOME variable will potentially influence all other applications installed, so this does not seem to be a good solution. – BartoszKP Aug 27 '14 at 10:54
  • 1
    As far as I know, there was no pre-existing HOME variable. I just did this a few days ago, and it seems to be okay. – Marcus Gladir Aug 28 '14 at 20:22
15

I am running emacs as a portable app and this works very well for me:

Create a batch file in the root of your emacs directory. For example, I created:

C:\Dropbox\PortableApps\emacs-24.3\run_emacs_portable.bat

Then, edit the file and put this text into it:

set HOME=.\
bin\runemacs.exe %*

Now, I just launch emacs via the run_emacs_portable.bat file and my HOME folder always points to my emacs installation folder.

The %* allows you to pass arguments to the .bat file and have them forwarded to the runemacs.exe

Matt Klein
  • 7,856
  • 6
  • 45
  • 46
  • 2
    You should add `%*` after `runemacs.exe` to forward arguments and be able to `Open With` portable Emacs. – user Apr 17 '14 at 22:46
  • Thanks, I added in your suggestion! Great idea. – Matt Klein Apr 18 '14 at 06:15
  • I was thinking about making a .bat file that would add HOME=.\ to the system, so I could just use the standard .exe on all my systems, after executing the .bat. I've tried setx -m, but it doesns't seem to work very well. Do you have any clue how I might get it to work? – Eivind Dahl Nov 04 '16 at 16:48
  • 1
    @EivindDahl When the .bat file runs `set HOME=.\ ` it is changing the environment variable for that shell instance only. If you double-click the batch file, then a new shell (cmd.exe) is run, it's `HOME` value is changed, and then the shell is shut down. That is why this solution has the call `set HOME=.\ ` take place in the same .bat file as the call to `runemacs.exe`. When `runemacs.exe` is executed from within the .bat file, the value of `HOME` for the running shell is `.\ `. – Matt Klein Nov 07 '16 at 13:36
1

Inside the home directory .emacs.d is created automatically, and you can make init.el as a startup file. Also refer to this question.

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
1

To setup Emacs home folder in your Windows User folder (C:\Users\User\.emacs.d) just add this code to your current init file and restart Emacs.

(when (eq system-type 'windows-nt)
  (unless (getenv "Home")
    (shell-command (format "setx \"%s\" \"%s\"" 'Home (getenv "UserProfile")))))
1

I liked Роман Захаров's answer which seems good for maintaining a cross-platform configuration, but it didn't work.

This is what finally worked for me.

(when (eq system-type 'windows-nt)
  (setenv "Home" (getenv "UserProfile")))
0

you can start emacs, type M-x pwd and that will show you where you are in the Windows file tree. You can put your .emacs there.

Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217
0

On Windows, Emacs is started with some Properties defined, found when you right-click the executable on your windows system. There you can define the

  1. execution-directory, e.g. "C:\Users\loggedin_user\" (in parantheses)

  2. where emacs executes

  3. and looks for the .xemacs (.emacs) directory, where it find its init.el.

  4. And where you can define the startup instructions (like (setenv "HOME" "c:/Users/Username/") ) etc.

If you configure that, the next time, emacs starts from the directory, you defined, with the initialisation-file

Coliban
  • 601
  • 2
  • 9
  • 24
0

If you want to use c:/users/USER/.emacs, you should have set your HOME variable to c:/users/USER, not c:/users/USER/emacs.

raspy
  • 3,995
  • 1
  • 14
  • 18