Emacs fails to load (.emacs) configuration file

I am using Emacs on Ubuntu 9.04.

I have my emacs configuration file in the ~/.emacs.d directory.

My emacs file is called .emacs.

I have some basic configuration. However, when I start emacs, it never loads my configuration and I have to keep doing it manually using e.g.

M-X Transient-mark-mode

My emacs file is listed below:

;; Emac customization file path
(add-to-list 'load-path "~/emacs.d")

;; Use font lock mode
(global-font-lock-mode t)

;; Highlight cursor line
(global-hl-line-mode t)

;; Highlight selected region
(transient-mark-mode t)

I want to add to this configuration instead of manually adding entries.


Solution 1:

Your init file contains personal EmacsLisp code that you want to execute when you start Emacs.

  • For GnuEmacs, it is ~/.emacs or _emacs or ~/.emacs.d/init.el.
  • For XEmacs, it is ~/.xemacs or ~/.xemacs/init.el.

Solution 2:

Torok Gabor's answer is what you are looking for. I only wish to point out a minor typo in your init file, it should be

(add-to-list 'load-path "~/.emacs.d")

Solution 3:

As Török said, probably you need to rename emacs to init.el.

One thing that drove me crazy for a while is that if ~/.emacs exists then emacs doesn't load ~/.emacs.d/init.el. So, if you have a ~/.emacs either delete it and move its contents into the other file, or (load "~/.emacs.d/init.el") inside ~/.emacs.

Solution 4:

It should be mentioned, however, that only Emacs 22+ loads ~/.emacs.d/init.el as alternate per-user init file. As a new but downward-compatible feature it priorizes ~/.emacs. This is arranged in lisp/startup.el.

After startup the user-init-file variable contains the full pathname of the init file in charge, e.g. /home/me/.emacs.elc or C:\Users\Me\.emacs.d\init.el etc. To see its value, in the *scratch* buffer type (insert user-init-file) followed by C-x C-e.

The ~/.emacs.d/ directory is actually a standard location for additional per-user files. The path is defined by the Emacs variable user-emacs-directory. Under Windows this path depends on the HOME (not USERPROFILE) variable. When HOME is set to C:\, for example, it will be C:\.emacs.d. When running Emacs portably I put upon this behavior, by using a batch-file that sets HOME to a directory on the pen drive.

There are not only Lisp files in this directory! For example, the auto-save feature by default stores any edited file into ~/.emacs.d/auto-save-list/ (see the auto-save-list-file-prefix variable). This inspired me to store backup-files there too:

(defvar --user-backup-directory (concat user-emacs-directory "backups"))
(if (not (file-exists-p --user-backup-directory))
    (make-directory --user-backup-directory t))
(setq backup-directory-alist `(("." . ,--user-backup-directory)))
(setq make-backup-files t)

Prior to Emacs 22 I also had a ~/elisp directory for my personal Lisp files. Now I use

(pushnew (expand-file-name "~/.emacs.d/elisp") load-path)

as advised here.

So ~/.emacs.d is actually quite useful, although I find the idea of ~/.emacs.d/init.el questionable. The ~/.emacs.d/ directory is a standard location for additional per-user files. Wouldn't it make more sense when Emacs reads ~/.emacs.d/init.el additionally to ~/.emacs.el?