Skip to content

zmalltalker/dot-emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My .emacs.d

I’m experimenting with using org-mode to handle my .el files. I use my setup with emacs 24.

Where are the .el files?

You’ll notice that this git repository doesn’t include any .el files, except init.el. In fact, you’ll find that .gitignore instructs Git to ignore several .el files.

Why would I do this?

The first years I used Emacs, I kept my configuration in ~/.emacs - which soon became a mess. As I grew a bit more confident with emacs-lisp I split my single .emacs into several files, and required these.

Then along came Textmate, and I pretty much forgot about Emacs until I discovered the Emacs starter kit which provided me with an Emacs environment out of the box that completely blew me away. I haven’t touched Textmate since.

The problem with using code you don’t know is that there’s bound to be stuff in there that you don’t understand. Since I don’t like working with code I don’t understand I stopped maintaining my Emacs configuratio, which means I don’t use Emacs as efficently as I could - which defeats the purpose of using Emacs.

So I’m back to writing my Emacs configuration by hand.

What was the problem?

I’d put emacs-lisp comments in my .el files, but like all other comments you risk not updating them as you change stuff, and end up with comments that are obviously false:

What can I say? This sucks.

So instead of pretending I’d maintain comments, I decided to turn things around. Rather than start by adding code and then write comments to help me remember what I intended to achieve when I revisit the file in a hundred years, I’d start by describing what I wanted to achieve and write the code implementing it afterwards. Since I do most all of my writing in org-mode, what would be better than to use org-mode to describe my intentions and then support it with elisp code blocks embedded in the .org file.

You’re currently looking at the result.

How does it work?

In init.el you’ll find some code I copied off the Internet (pretty much like a kid would pick up a piece of bubble gum from the street and put it in his mouth). I would use org-mode for this file to have it documented, except it contains the elisp code that makes it possible to use this setup.

My .emacs.d/extras directory contains libraries/functionality in org-mode files, which are compiled to elisp like this:

(setq org-custom-library-dir (expand-file-name "extras" dotfiles-dir))
(mapc #'org-babel-load-file (directory-files org-custom-library-dir t "\\.org$"))

This code will compile all .org files in the extras/ directory and load them into Emacs. After these files have been loaded, I do the same trick to any .org files directly under ~/.emacs.d:

(mapc #'org-babel-load-file (directory-files dotfiles-dir t "\\.org$"))

This happens, step by step

  • I start emacs, and it will by convention load ~/.emacs.d/init.el
  • init.el will load org-mode, I keep a local version checked out, your Emacs version will probably have org-mode bundled.
  • init.el will call org-babel-load-file for any .org files in extras/
  • init.el will call org-babel-load-file for any .org files in ~/.emacs.d. In fact, the file you’re reading right now will have a corresponding .el file.
  • I treat marius.org as my main configuration file. (I would make this a hyperlink, but you know … later.)

Just to prove I’m an idiot

I just discovered my fantastic setup will cause an error if an .org file in ~/.emacs.d does not have a corresponding .el file. Since this file does not contain any begin_src instructions, a readme.el file would not be generated, and I’d get a load error when starting Emacs.

The only way I could think of to resolve this is to add an empty source block :-/

;;

About

My org-babel based .emacs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published