Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using emacs on ubuntu 9.04.

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

My emacs file is called .emacs

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

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 added entries.

Many thanks for any advice,

share|improve this question

migrated from stackoverflow.com Sep 3 '11 at 7:51

This question came from our site for professional and enthusiast programmers.

5 Answers 5

up vote 10 down vote accepted

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.
share|improve this answer

Another thing to try if what everyone else said does not work for you, is to chown the .emacs and .emacs.d file and directory.

For some reason my .emacs and .emacs.d were owned by root and emacs would not load it unless I did sudo emacs.

A simple sudo chown `whoami` .emacs did it.

share|improve this answer

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?

share|improve this answer

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.

share|improve this answer

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")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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