Skip to content

Add desktop.el session persistence - #627

Merged
dakra merged 1 commit into
dakra:mainfrom
mrcnski:desktop-support
Aug 16, 2026
Merged

dakra merged 1 commit into
dakra:mainfrom
mrcnski:desktop-support

Conversation

@mrcnski

@mrcnski mrcnski commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Terminals don't survive an Emacs restart. Even with desktop-save-mode enabled, every ghostel buffer is simply gone after desktop-read. desktop.el skips non-file buffers unless their mode opts in, so a saved session restores files and window layouts only.

#625 made a fix straightforward: the desktop handlers persist one ghostel-identity alist.

Fix

A new ghostel-desktop.el, mirroring ghostel-bookmark.el's architecture:

  • ghostel-mode points the buffer-local desktop-save-buffer at an autoloaded save function (a quoted symbol, no load-time dependency)
  • ghostel.el registers the autoloaded restore handler in desktop-buffer-mode-handlers under with-eval-after-load 'desktop.
  • The registration lives in ghostel.el because desktop-read loads ghostel itself through the saved major mode and looks the handler up immediately, before anything could load ghostel-desktop.el.

Saving records (DIRECTORY IDENTITY). Restoring reuses a live buffer with the saved slot identity (so a repeated desktop-read doesn't spawn duplicates), otherwise starts a fresh shell in the directory under the exact saved buffer name, with the saved identity as its ghostel-identity. Window configurations find the buffer by name, and ghostel-project and friends keep reusing the restored terminal. A failed spawn (e.g. the directory no longer exists) kills the partial buffer and re-signals so desktop.el reports the buffer and moves on.

Two kinds of saved terminals are deliberately skipped, with a message:

  • Command buffers (ghostel-exec, ghostel-compile, eshell visual commands — identities with a command key). Unlike a bookmark jump, a desktop restore runs unattended at startup, and automatically re-running a saved command (e.g. a build) seemed like a footgun. Happy to add an opt-in defcustom for respawning such commands if you'd like parity with the bookmark jump.
  • Remote (TRAMP) terminals, since spawning their shells would open connections, possibly prompting for credentials, in the middle of desktop-read. As above, an opt-in is easy if wanted.

I kept v1 free of new defcustoms given the API overhaul you mentioned. Both skips are documented in the README's new Desktop section.

Other info

Eleven tests modeled on ghostel-bookmark-test.el.

README section, comparison-table row, and CHANGELOG entry included.

Restoring many terminals spawns one shell per buffer. The README points at the stock desktop-restore-eager for throttling rather than anything ghostel-specific.

🤖 Generated with Claude Code

@dakra

dakra commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Haven't looked too closely but looks good on a quick pass.
Can you rebase on latest master and fix CI (which could be tricky with the not allowed with-eval-after load, not sure what's best there or if we have to add an exception)

@mrcnski

mrcnski commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I plan to update all my PRs soon but haven't been able to do so yet.

A saved terminal records its working directory and identity;
desktop-read starts a fresh shell in that directory under the saved
buffer name, so restored window configurations find the buffer and
identity-based reuse (ghostel-project etc.) carries over the
restart.  Command buffers and remote terminals are skipped, with a
message: a desktop restore runs unattended at startup, where
re-running a saved command or opening TRAMP connections would be
surprising.  Architecture mirrors ghostel-bookmark.el: a lazily
loaded ghostel-desktop.el with autoloaded save/restore functions.
@dakra
dakra force-pushed the desktop-support branch 2 times, most recently from 4b8f545 to 9db5153 Compare August 16, 2026 08:54
@dakra
dakra merged commit 9db5153 into dakra:main Aug 16, 2026
27 checks passed
@dakra

dakra commented Aug 16, 2026

Copy link
Copy Markdown
Owner

@mrcnski thanks. I rebased, fixed the CI, the lint warnings and some other edge cases my clanker complained about (restore when the directory doesn't exists anymore, dead terminals and buffer renames)

Merged 🙏

This branch was previously deployed

1 inactive deployment
github-pages — 9db51530 Deployed Aug 16, 2026 by dakra via deploy #162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants