Change .emacs directory in Ubuntu

3.5k views Asked by At

Currently my .emacs file is found in /home So is my .emacs.d folder and I suppose some other files like diary, notes etc will be created in this folder.

I find this really messy and I want all my emacs related files(including the .emacs) and folders in a single folder, say /home/EmacsHome

How do I do that in Ubuntu 12.04? In windows I did this by setting an environment variable HOME to the path of EmacsHome. But, in Ubuntu, the HOME variable will be used for several other programs as well, so I dont want to change that.

4

There are 4 answers

8
lawlist On

This works for OSX, so perhaps for you too . . . just change the paths to whatever suits your needs. The user-emacs-directory is where you would set the equivalent of .emacs.d. I have everything related to Emacs in my user-emacs-directory. If you use package manager, the elpa directory would be automatically crated there also.

(setq default-directory "~/.0.data/")

(setq user-emacs-directory "~/.0.data/.0.emacs/")

(setq diary-file "~/emacs/diary")
2
Alberto Zaccagni On

You could create a symbolic link to them, like so

ln -s /home/EmacsHome ~/.emacs.d

The first argument is the folder where you want the folders to be, the second one is where emacs usually looks for its configuration files, so with this approach you can put the folder wherever you like.

0
phils On

Emacs already supports a config directory for holding everything Emacs-related: ~/.emacs.d. Just use that.

Rename ~/.emacs to ~/.emacs.d/init.el, and you're virtually done.

If you have any other emacs-specific files outside of that directory, you might need to set a variable here or there to relocate them, or simply rename the file -- these days the defaults tend to automatically be within ~/.emacs.d, but an older filename in the home directory might still take precedence.

e.g.: the bookmarks file used to be ~/.emacs.bmk but if you haven't customized the variable then you can simply rename it to ~/.emacs.d/bookmarks. See C-h f locate-user-emacs-file RET and M-x find-variable RET bookmark-default-file RET for details.

If you're not sure how to proceed for any given file(s), you could just update the question with the details.

And as Alberto Zaccagni said, just create a symlink if you want an alternative name to access the directory. Although personally I would suggest retaining ~/.emacs.d as the real directory, and making the alternative name the link, like so:

ln -s ~/.emacs.d /home/EmacsHome
0
test30 On

There's also another solution:

cd your-directory
HOME=$PWD emacs -L .

taken from https://github.com/capitaomorte/yasnippet#important-note-regarding-bug-reporting