Aerion
Aerion

Reputation: 73

Emacs init file won't load at start up

I'm trying to run Emacs v22.2 on a Windows 7 computer. However, the init file isn't loaded at start up (loading it manually with M-x load-file works fine).

I've tried using both:

~\.emacs, ~\_emacs 
~\.emacs.d.init.el 

but the problem persists.

Evaluating (insert (getenv "HOME")) returns the expected value.

Upvotes: 4

Views: 5655

Answers (4)

I've just managed to solve the same problem (lcollado and klang's answer gave me a small hint on how to fix it).

I had set up a configuration file at C:\Users\Edwin\.emacs.d\init.el and when I tried to get Emacs to load it, it didn't. My initial thought was to make an init.el file at C:\Users\Edwin\AppData\Roaming\.emacs.d\init.el which would load my original configuration file. However, I wanted a simpler solution.

Then I remembered that Symbolic Links exist. So I did a few searches on how to make a symbolic link in Windows and the difference between Hard Links and Soft Links.

My first attempt was to make a soft link that pointed to my init.el. But Emacs ignored the link and started without the init.el.

The next attempt that did work was a hard link. The steps that I did was as follows:

  1. Open Command Prompt with Administrative Privileges.
    a. Press Windows + R.
    b. Type "cmd.exe" and press Shift + Enter.
    c. Tap "Yes" when Windows asks for Administrative Privileges.

  2. Go to your home directory.
    a. Type cd C:\Users\<your name>.

  3. Run the following command to make a hard link in C:\Users\<your name>\AppData\Roaming\.emacs.d\init.el:

    :: mklink /h Destination Source
    :: Destination - Where do you want the hard link to be and what will be it's name?
    :: Source      - What file do you want to link?
    mklink /h AppData\Roaming\.emacs.d\init.el .emacs.d\init.el
    

Upvotes: 0

Anamika Mahankakdi
Anamika Mahankakdi

Reputation: 81

I faced a similar issue(on windows 10). The problem was that Emacs was reading ~\.emacs instead of ~\.emacs.d\init.el on startup. Shifting the contents of ~\.emacs to ~\.emacs.d\init.el and deleting ~\.emacs solved the issue.

Upvotes: 4

lcollado
lcollado

Reputation: 151

Depending on how you open emacs in Windows 7, it will look in different places for the .emacs file. If call it from within a shell (in cygwin, Msys, etc) it will look in the $HOME (~) location, if you run it form the installation directory by clicking on the icon, it looks for this file in the %APPDATA% location ( usually C:\Users\your user name\AppData\Roaming ). This can lead you in a merry chase all over the place. I found that it is best to determine where you want the file to be stored, and the create symbolic links ( using windows mklink utility ) to all other possible locations.

Upvotes: 7

klang
klang

Reputation: 524

I just installed the patched version of Emacs on Windows 7, specified the environment variable HOME=c:\klang, checked out my decade old configuration files from github and added

(and (= emacs-major-version 23) 
  (defun server-ensure-safe-dir (dir) "Noop" t))

to ~/.emacs.d/init.el and was up and running.

What you are missing is some component from mule.el, just install the new version of emacs to fix it.

If HOME is not set in the genereal environment, (getenv "APPDATA") will probably take over and emacs will try to read your init file somewhere under that directory.

Upvotes: 2

Related Questions