Skip to content

An Unorthodox Emacs Setup with a Static Init File Generator

Intro

Recently I started to rebuild my old setup in quest for more speed. I was hacking on Emacs at C level, rebuilding, and restarting it often and found annoying the startup delay caused by my old setup. Instead I would be starting Emacs with -Q option, but then I would be sending it to the background since I have rebound C-z to serve as M-x replacement.

I have been using that binding for quite a long now, so it is in my muscle memory. Also, I really have to be careful when I run Emacs with -Q flag. An option would be to have an alternative, scaled down startup. But why, when I can rework my init file to start in less then a halv second? Easier said than done! At least in my case: one thing led to another and after two weekends I ended up with a generator for my init file.

The Idea

Why a static file generator, why not just write another init file instead?

I started by refactoring my old Emacs setup which used org-mode with a save-file hook to automatically tangle and compile file. It was a bit annoying to work with it as the setup become bigger. Mostly because it takes a while to compile the file, especially when native compiler is used. I have a habit of pressing C-x C-s quite often which would trigger compilation sometimes when I didn’t really wanted it. It is also wasteful to check every file as Emacs saves it just to see if it is one of the init files.

Yet another reason is that I started to use early-init.el to speed up some graphical setup. I think it is nice to have both files open at once so I can work with them as they were one file.

For the startup speed, I wanted an init file with as little overhead as possible. For the future maintaince, for example when I install on a clean computer I prefered it to be self-contained so I don’t need to think what comes first or of special order to install things in, because I always forgett it. I am one of those guys: what was the thing I did there?

For those reasons I am getting ridd of all third party dependencies so I can bootstrap it from within a stock Emacs without a prior setup. That means generally that I am ditching third party tools such as the excellent use-package by J. Wiegley or even libraries like s.el or dash. Bare bones only.

I like my literal setup with org, since it brings structure to the init file. By structuring parts of init file in headings and sub-headings, we can actually keep things in same file, but structure it as if we work in different files. Finally, I really like use-package, not so much for the features, but also because it brings more structure to the configuration, this time on a lisp level.

I wish to be able to write my init file in a structured way, so idea here is to see if I can combine org-mode with something that at least resembles use-package macros. I have found that I mostly use configure, ensure and bind keywords from the use-package, while others where not that used by me, so I will need replacement for mostly those three. Don’t misunderstand me, I don’t wish to replace use-package, and I am not stopping to use it because I don’t like it. On contrary it is an excellent and well written tool. I am just not sure how to fit it into a zero, or at least minimal overhead kind of a framework.

I also found the automatic tangle a bit problematic. I wanted to simplify the generated init file to speed up things up, so I tested two small optimizations: I am merging all small lambdas belonging to a given mode hook into one, and I also tested to unroll all key bindings specifications. I am not sure I could do that
if I used automatic tangling. Maybe it is possible but I don’t know how to do it.

I also feel I need to learn a bit more about elisp, I am still just scratching the surface of it. It turned out to be a quite interesting little project in that regard.

The Result

I have been using it for my own Emacs configuration for about two weeks now. For the moment I am happy with it. The tool is just a simple, bare-bone of a prototype, but it does what I need. I consider it to be in alpha with many features missing. I also have some ideas about modularisation I would like to try to make it more usable for bigger setups, but as of current, it can be used for configuring a personal setup, which is enough for me to use it.

If you would like to give it a try

It would be nice if you would like to test it and report bugs, possible improvements etc. You will find it on Github.

If you are someone creating a distribution for other people, or developing packages and testing with different versions of Emacs, uploading to different repositories etc, you probably wish to stay away from this. But if you are an ordinary user looking for a help to write a well-structured, somewhat optimized setup, you might give it a try.

Post a Comment

Your email is never published nor shared. Required fields are marked *