Initialisation file portability tweaks

I did warn you... this is going to be about emacs!

I keep my configuration under version control using github, and I use the same setup on two different platforms (linux and OSX).  Most of it is a collection of accumulated cruft and tweaks cannibalised from others, but there's two bits I haven't seen elsewhere that I think are worth sharing, which help make it portable:

First of all I set a variable to the location of the checkout.  This is not novel, but the way the default is determined possibly is: file-truename resolves any symbolic links, etc to find the true-name of the file; this means you can check out the configuration anywhere, and all that is needed to install it is to symlink init.el to ~/.emacs.  file-name-directory just returns the directory base, which we now know is our checkout location where all our code is.

Secondly, there is still occasionally the need for some platform-specific code.  I accomplish this by loading a file determined by the platform name (if it exists).  You need to be a bit careful here, because currently on my Ubuntu system 'system-type reports as gnu/linux and the forward-slash will be interpreted as a path separator, so I convert that to a dash with subst-char-in-string.  (For the record, OS X currently reports as "darwin").  Obviously you could do something similar with hostname, for example.

Mark Hepburn 26 September 2009
blog comments powered by Disqus