I try to keep my .emacs organized. The configuration will always be a work in progress, but I'm starting to be satisfied with the overall structure.
All stuff is under ~/.elisp
, a directory that is under version control (I use git, if that's of interest). ~/.emacs
simply points to ~/.elisp/dotemacs
which itself just loads ~/.elisp/cfg/init
. That file in turn imports various configuration files via require
. This means that the configuration files need to behave like modes: they import stuff they depend on and they provide
themselves at the end of the file, e.g. (provide 'my-ibuffer-cfg)
. I prefix all identifiers that are defined in my configuration with my-
.
I organize the configuration in respect to modes/subjects/tasks, not by their technical implications, e.g. I don't have a separate config file in which all keybindings or faces are defined.
My init.el
defines the following hook to make sure that Emacs recompiles configuration files whenever saved (compiled Elisp loads a lot faster but I don't want to do this step manually):
;; byte compile config file if changed
(add-hook 'after-save-hook
'(lambda ()
(when (string-match
(concat (expand-file-name "~/.elisp/cfg/") ".*\.el$")
buffer-file-name)
(byte-compile-file buffer-file-name))))
This is the directory structure for ~/.elisp
:
~/.elisp/todo.org
: Org-mode file in which I keep track of stuff that still needs to be done (+ wish list items).
~/.elisp/dotemacs
: Symlink target for ~/.emacs
, loads ~/.elisp/cfg/init
.
~/.elisp/cfg
: My own configuration files.
~/.elisp/modes
: Modes that consist only of a single file.
~/.elisp/packages
: Sophisticated modes with lisp, documentation and probably resource files.
I use GNU Emacs, that version does not have real support for packages. Therefore I organize them manually, usually like this:
~/.elisp/packages/foobar-0.1.3
is the root directory for the package. Subdirectory lisp
holds all the lisp files and info
is where the documentation goes. ~/.elisp/packages/foobar
is a symlink that points to the currently used version of the package so that I don't need to change my configuration files when I update something. For some packages I keep an ~/.elisp/packages/foobar.installation
file around in which I keep notes about the installation process. For performance reasons I compile all elisp files in newly installed packages, should this not be the case by default.