0

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.

Spectre
  • 682
  • 10
  • 26

4 Answers4

2

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
phils
  • 71,335
  • 11
  • 153
  • 198
0

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")
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • Create a file in your home directory called `.emacs` and put those lines of code in it -- setting the path however you choose. – lawlist Sep 04 '13 at 19:51
  • Nope, doesnt work. The home directory is still treated as /home. – Spectre Sep 04 '13 at 19:57
  • This doesn't alter your home directory. It just alters where Emacs looks for certain files and where certain files are created when using Emacs. – lawlist Sep 04 '13 at 19:58
  • But when emacs starts up, there is an option of "Open Home Directory". When I click that, it takes me to /home and not the intended directory. Similarly, when I add a diary entry or a note, it adds those files in the /home directory. – Spectre Sep 04 '13 at 20:02
  • It sounds like "Open Home Directory" is working as it should -- the code I provided does `not` alter the home directory -- it only alters where Emacs looks for and stores certain files. Your diary entries are likely using a default of the home directory, and you will need to set a specific diary variable to control its path. For example, org-mode uses this for org files: `(setq org-agenda-files . . .`). Something like: `(custom-set-variables '(diary-file "~/diary/emacs"))` – lawlist Sep 04 '13 at 20:07
  • I added an example of how to set the `diary-file` location to the answer above. `diary-file is a variable defined in 'calendar.el' -- its [default] value is "~/diary".` – lawlist Sep 04 '13 at 20:16
  • Yes, and since its a pain to change the way emacs behaves for every package (e.g. if I use R/octave and I want to save the session, I bet its gonna save it at /home), I had made this EmacsHome and referenced everthing from there using relative paths, which would work only if Emacs could change the directory it treats as the HOME folder. – Spectre Sep 04 '13 at 20:23
  • It may be a pain to set up initially, but once all of the variables are custom set, it makes it very easy to back-up everything and have the same setup on multiple computers. It is a real treat to have everything relating to Emacs all in one folder, and then branch out into sub-folders from there. I even have things like aspell and w3m and wanderlust all set up within that hierarchy. – lawlist Sep 04 '13 at 20:35
0

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.

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
  • Actually emacs creates the .emacs file automatically at /home. But, I would like .emacs to be in /home/EmacsHome. So, this command gives an error "File exists". We need to try to change the way emacs starts so that it can look for the .emacs elsewhere than its default location. – Spectre Sep 04 '13 at 20:21
  • You can set a path to a custom `init.el` file by adding to or creating within the Emacs source files `.../lisp/site-start.el` and then within `site-start.el` using a line such as `(load-file "~/.0.data/.0.emacs/init.el")`. Everything that would normally be inside your `.emacs` file can be transferred to your custom `init.el` file, and then the `.emacs` file would no longer be needed. – lawlist Sep 04 '13 at 20:43
0

There's also another solution:

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

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

test30
  • 3,496
  • 34
  • 26