AI and Emacs Bankruptcy

A few weeks ago I declared Emacs bankruptcy for the umpteenth time. Well, maybe the third or fourth time.

My reasons were the usual: my configuration was full of outdated cruft and customization variables I no longer understood, my emacs.d/ folder was overloaded with cache files and debris from old packages, custom.el was full of experimental stuff that I no longer used, etc., etc.

Besides the urge to clean up the incomprehensible mess that was my old configuration, I had several other incentives to start anew.

First was that I had just upgraded to Emacs 31. Surely some of the Lisp code in my init.el that was needed to get Emacs 28 up and running was no longer necessary in modern Emacs.

Second, I was inspired by a trick of Prot, who has a huge literate Emacs configuration file. He generates the Emacs init files from his Org configuration file by tangling the code blocks in the file. Tangling means that the code blocks are extracted from the Org file and placed in the Emacs initialization files early-init.el and init.el. Most literate configuration schemes work by having the init.el file load the Org file and tangle the code blocks on the fly. This works, but it is a slower process. That was the technique my original configuration used.

Finally, I wanted to see if AI could help me in the transition to a new configuration. More on that in a moment.

My guiding principle was to start from scratch and add only what was essential from my old configuration file, and do so in a “modern Emacs” way. To me that meant using built-in Emacs functionality over external packages whenever possible and, when external packages were needed, favoring ELPA over MELPA, and GNU over NonGNU packages.

I decided to jettison most Emacs “eye candy.” Nerd icons and the Doom modeline are nice, but not essential. I didn’t want anything that I felt could bog down Emacs.

I would also use the default locations for files. Org-mode likes ~/org/ for its agenda files, so ~/org/ it is. I have a MacBook Pro laptop and also run Windows using Parallels. So as not to include any operating system-specific code, I created symbolic links in Windows that pointed to the macOS files. So ~/org/ on Windows points to ~/org/ on Mac, which itself is a link to a shared Dropbox directory.

The only files I would put under version control would be the literate configuration file dem-emacs.org as well as the generated early-init.el and init.el files. What I would not put under version control would be my whole .emacs.d/ directory. That is a now real directory, not a symbolic link, and it contains symbolic links to the three configuration files.

So my ~/dotfiles/emacs/.emacs.d/ directory holds just these three files:

~/dotfiles/emacs/.emacs.d $ tree .
.
├── dem-emacs.org
├── early-init.el
└── init.el

The ~/.emacs.d/ directory is NOT a symbolic link; however, it does contain the symbolic links to the three configuration files.

~/.emacs.d $ tree -L 1
.
├── cache
├── dem-emacs.org -> ../dotfiles/emacs/.emacs.d/dem-emacs.org
├── early-init.el -> ../dotfiles/emacs/.emacs.d/early-init.el
├── elpa
├── init.el -> ../dotfiles/emacs/.emacs.d/init.el
├── private
└── var

By using just a few subdirectories of ~/.emacs.d/ I can keep the files that Emacs uses tucked away from the top-level directory.

I use GNU Stow to establish the symbolic links:

cd ~/dotfiles
stow --no-folding emacs

What’s the role of AI in this process? Like I’ve said before, I think AI is a good educational tool and I prefer to use it to educate myself rather than have it just write code. I suppose I could have given ChatGPT my old configuration.org and prompted, “rewrite this in modern Emacs.” The result may have worked, but I would have learned nothing about configuring Emacs in the process. Instead I took small sections of my old configuration and dissected each line with the help of ChatGPT. This was a slow but rewarding process and I learned a lot. The result was a much cleaner configuration.

Here is the configuration on GitHub. As you can see it is bare bones, but it is a good start. It loads in about a second compared to 6 seconds for my old configuration! I can add to it as needed, but given my new Emacs philosophy, I will be selective in what I add. Over the years I have have jettisoned “heavy” external packages like Flycheck, Projectile, Company, and Helm and replaced them with light-weight packages that use built-in Emacs functions. Now I hope to get on with my work and not worry about Emacs bankruptcy again for a long, long time.

By mannd

I am a retired cardiac electrophysiologist who has worked both in private practice in Louisville, Kentucky and as a Professor of Medicine at the University of Colorado in Denver. I am interested not only in medicine, but also in computer programming, music, science fiction, fantasy, 30s pulp literature, and a whole lot more.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.