Dotemacs In Org

As time goes, my .emacs file grows so large that I find it difficult to organise, to switch things on/off and document the references where I found solutions for certain tasks. I decided to use Org to organise my .emacs file so that I can have emacs-lisp code and descriptions all in one file with sections.

My has two parts. The first part initialise Org for loading the second part, where most of the settings are.

Initialise Org

MELPA has to be loaded before Org is loaded. This part of the file will be tangled into a file called dotemacs.

#+BEGIN_SRC emacs-lisp :tangle dotemacs
(require 'package)
(add-to-list 'package-archives 
'("melpa" . "") t)

(when (< emacs-major-version 24)
    (add-to-list 'package-archives '("gnu" . "")))

* Load the rest
#+BEGIN_SRC emacs-lisp :tangle dotemacs
(require 'org)
(org-babel-load-file "~/env/emacs/")

The rest of the file

Here is where you put your emacs settings. This part of the file will be tangled into a file called dotemacs.el

* Python
** Jedi
Jedi is an emacs package for Python auto-completion 
#+BEGIN_SRC emacs-lisp :tangle yes
(require 'jedi)
(autoload 'jedi:setup "jedi" nil t)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:setup-keys t)

* Magit
Magit is an emacs package for handling git repositories.
#+BEGIN_SRC emacs-lisp :tangle yes
(global-set-key (kbd "C-c g") 'magit-status)

Last step

The first part of the org file is tangled into a file called “dotemacs” (because I put “dotemacs” after :tangle). Now all you need to do is to make a symbolic link .emacs in your home directory to point to this dotemacs file.

ln -s ~/env/emacs/dotemacs ~/.emacs 

Then emacs will load the to tangle the rest of the settings into dotemacs.el. Org is smart enough not to recompile dotemacs.el if nothing is changed.

Alternative method - not using Org at all

Neglecting all of the above, there is another way to organise your emacs settings. That is to put your settings into separate .el files and include them using the require command in your .emacs file like this:

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

(require 'python-settings)

And you will have your python-mode setting in python-settings.el (and many others) under ~/.emacs.d/user_settings

blog comments powered by Disqus