Session state persistence for crash recovery.
Periodically saves the list of open files, cursor positions, scroll positions, and active buffer to a JSON file. On next launch, the session is restored: files are reopened and cursors are repositioned.
The session file includes a version field for forward compatibility.
Old session files that lack newer fields get defaults when loaded.
Clean shutdown detection
A clean_shutdown flag is set in the session file on orderly exit.
On next launch, if the flag is missing or false, Minga knows the
previous session crashed and shows "Restored from previous session"
in *Messages*.
Summary
Types
A single buffer's session state.
A snapshot of the current editor session.
A recoverable swap file entry.
Functions
Returns whether the last session was a clean shutdown.
Deletes the swap file for the given buffer path.
Loads the session from disk.
Marks the session as cleanly shut down.
Recovers content from a swap file. Returns {:ok, original_path, content}.
Saves a session snapshot to disk as JSON.
Scans the swap directory for recoverable swap files.
Returns the session file path.
Builds a session snapshot from the Editor's state.
Returns the default swap directory path.
Writes a swap file for the given buffer path.
Types
@type buffer_entry() :: Minga.Session.BufferEntry.t()
A single buffer's session state.
@type snapshot() :: Minga.Session.Snapshot.t()
A snapshot of the current editor session.
@type swap_entry() :: Minga.Session.Swap.Recovery.entry()
A recoverable swap file entry.
Functions
Returns whether the last session was a clean shutdown.
Deletes the swap file for the given buffer path.
Loads the session from disk.
@spec mark_clean_shutdown(keyword()) :: :ok
Marks the session as cleanly shut down.
Recovers content from a swap file. Returns {:ok, original_path, content}.
Saves a session snapshot to disk as JSON.
@spec scan_recoverable_swaps(keyword()) :: [swap_entry()]
Scans the swap directory for recoverable swap files.
Returns the session file path.
@spec snapshot(MingaEditor.State.t()) :: snapshot()
Builds a session snapshot from the Editor's state.
Queries each open buffer for its file path and cursor position. Only includes file-backed buffers (not scratch, nofile, or log buffers).
@spec swap_dir() :: String.t()
Returns the default swap directory path.
Writes a swap file for the given buffer path.