Persistent project switching in Emacs
Just a short note for today, as the super-fast-latex post is still cooking:
Emacs provides a few mechanisms to manage buffer/window state as a group. There’s current-window-configuration
(and its register variants) and desktop-save
, and you can act on groups of buffers by every predicate imaginable in ibuffer
. But the window configurations vaporize when you shut down Emacs, and they don’t handle unopened file buffers. desktop-read
is an all-or-nothing affair. Somehow there’s no clear way to bookmark and switch to (across Emacs sessions) a collection of files, buffers and windows together as a unit… or project.
Spinning up a new Emacs session (it happens) or switching between projects (using project.el
) always annoyed me since I’d have to reopen or redisplay the project files I was working on last, then recreate my preferred window configuration and so on. This is especially so since all the ingredients to seamlessly switch projects are present in the Emacs API but haven’t been put together.
Between burly
, bufler
, persp-mode
, projectile
and various tab libraries I’m sure this hole is covered, but I’m happy with project.el
and wanted something much simpler, so I whipped something up.
project-x
saves my project state (open files, buffers and window configuration) and restores them across Emacs sessions.
Resuming project states
Resume a saved project state in a fresh Emacs process:
In addition to the window configuration, project files saved by project-x
are restored (as highlighted in ibuffer
here.)
Enhanced project switching
When I switch projects I switch window configurations too, opening files if needed:
Normally this kind of customization would just live in init.el
, but I decided to package it in case someone’s looking for a similar feature. At just a few defuns and a couple of hook functions, it really is much simpler than full fledged workspace management packages for Emacs. It works perfectly within a session, but it only restores files and directory windows across sessions (no shells, help buffers, etc). It’ll do for now.
I also threw in a project backend to recognize non-version controlled projects through the presence of a “.project” file in the path. I might take it out to make the library do-one-thing-well, or I might add more project.el
enhancements to it instead. The struggle is eternal.