How can I preserve my current working environment across reboots?

After work I want to preserve the current state with open buffers, etc so that when I startup again, I’m greeted by that scratch buffer reminding me where I just took of.

Such thing would greatly help in getting off the PC in time with the peace of mind of easily taking up where I left.

It’s not currently possible to save the entire session state across reboots. Some things could be restored, like the list of open buffers, cursor positions and register contents, but other things can’t, like mappings and hooks and highlighters. In addition, Kakoune can’t control anything about the number and layout of clients in a session, so that can’t be restored either.

I use my kakoune-state-save plugin to save and restore my command and search histories, and my last cursor position in each file. That’s definitely not a complete session-restore solution, but I find it better than starting completely from scratch every time.


Cool, got it working nicely — one question though:

  • Can I also reopen all buffers that where open before I closed the last time?

I don’t know of an existing plugin to do such a thing, but you would probably want to set up a KakEnd hook that did something like:

  • create a directory to store session state, if it doesn’t already exist
  • clear out the contents of the directory
  • use eval -buffer * to run a command in each open buffer
  • in each open buffer, try to symlink the file into that session-state directory (“try” because buffers like *debug* do not represent files on disk

Then have a KakBegin hook that opens all the files symlinked in that session-state directory.

Good instructions! Thanks, I will have a try, seems very feasible — ecen more somlooking at your state saving module.

  • I also need to ensure the reload is only triggered when kak was invoked without file parameter.

  • And saving is only done when more than one buffer is involved (since that was probably a one-off)

@Screwtapello Should I eventually find the time to work on this, I’d feel more comfortable doing so on a PR to your solution. How would you feel about this?

It’s Kakoune state that can be saved, so it fits!

I can imagine people wanting to customise how and where open buffers are saved and reloaded (for example, having a separate set of buffers for each git repository they work in, or only reloading buffers when their laptop is connected to their work WiFi), so I think the best approach would be to have a command to save the open buffer-list to a directory, and another command to load the open buffer-list from a directory. Then in the “Usage” section of the README, you can include a snippet that wraps those commands with extra logic as a “serving suggestion”.