Minga.Buffer.State (Minga v0.1.0)

Copy Markdown View Source

Internal state for the Buffer GenServer.

Holds the document, file path, dirty flag, and buffer-local runtime state.

Summary

Types

Buffer type controlling behavior

The source of an edit for undo/redo attribution.

File storage backend for buffer file I/O. Remote buffers still edit locally, but open/save/stat calls route through Erlang distribution.

t()

Functions

Accepts replacement content as a new saved baseline and advances the mutation version once.

Acknowledges disk metadata without changing dirty, version, or the saved content fingerprint.

Returns true when the backing file differs from the saved baseline.

Returns whether the buffer differs from its saved version.

Returns the saved content fingerprint, if one is known.

Returns the saved file size.

Replaces save tracking with a clean baseline for loaded content.

Returns save state for content loaded from storage.

Marks the buffer as having unsaved changes and advances the mutation version.

Records the current version as the save point for dirty tracking.

Returns the saved file mtime.

Records a content change that should not by itself make a clean buffer dirty.

Restores the mutation version and recalculates dirty state from the saved version.

Retargets the buffer to a new file path without changing content or dirty state.

Recalculates dirty state from the current mutation version and saved version.

Returns the current mutation version.

Types

buffer_type()

@type buffer_type() :: :file | :nofile | :nowrite | :prompt | :terminal

Buffer type controlling behavior:

  • :file: (default) normal file buffer, supports save/dirty/undo
  • :nofile: no file association, implicitly read-only, no save
  • :nowrite: has a file path for display but cannot save
  • :prompt: like :nofile but the last line is editable (for agent input, command input)
  • :terminal: backed by an external process writing into the buffer

edit_source()

@type edit_source() :: Minga.Buffer.EditSource.undo_source()

The source of an edit for undo/redo attribution.

options_server()

@type options_server() :: Minga.Config.Options.server()

storage()

@type storage() :: :local | {:remote, node(), String.t()}

File storage backend for buffer file I/O. Remote buffers still edit locally, but open/save/stat calls route through Erlang distribution.

t()

@type t() :: %Minga.Buffer.State{
  auto_save_timer: reference() | nil,
  auto_save_token: reference() | nil,
  buffer_type: buffer_type(),
  change_log: Minga.Buffer.ChangeLog.t(),
  decorations: Minga.Core.Decorations.t(),
  document: Minga.Buffer.Document.t(),
  events_registry: Minga.Events.registry(),
  explicit_options: MapSet.t(atom()),
  face_overrides: %{required(String.t()) => keyword()},
  file_path: String.t() | nil,
  filetype: atom(),
  name: String.t() | nil,
  options: %{required(atom()) => term()},
  options_server: options_server(),
  persistent: boolean(),
  read_only: boolean(),
  save_state: Minga.Buffer.SaveState.t(),
  storage: storage(),
  swap_dir: String.t() | nil,
  swap_timer: reference() | nil,
  undo_history: Minga.Buffer.UndoHistory.t(),
  unlisted: boolean()
}

Functions

accept_saved_content(state, metadata, content)

@spec accept_saved_content(t(), Minga.Buffer.SaveState.metadata(), String.t()) :: t()

Accepts replacement content as a new saved baseline and advances the mutation version once.

acknowledge_disk_metadata(state, metadata)

@spec acknowledge_disk_metadata(t(), Minga.Buffer.SaveState.metadata()) :: t()

Acknowledges disk metadata without changing dirty, version, or the saved content fingerprint.

changed_since_saved?(state, disk_mtime, disk_size, status)

@spec changed_since_saved?(
  t(),
  integer() | nil,
  non_neg_integer() | nil,
  Minga.Buffer.SaveState.saved_content_status()
) :: boolean()

Returns true when the backing file differs from the saved baseline.

dirty?(state)

@spec dirty?(t()) :: boolean()

Returns whether the buffer differs from its saved version.

file_hash(state)

@spec file_hash(t()) :: binary() | nil

Returns the saved content fingerprint, if one is known.

file_size(state)

@spec file_size(t()) :: non_neg_integer() | nil

Returns the saved file size.

load_saved_content(state, path, metadata, content)

@spec load_saved_content(
  t(),
  String.t() | nil,
  Minga.Buffer.SaveState.metadata(),
  String.t()
) :: t()

Replaces save tracking with a clean baseline for loaded content.

loaded_save_state(path, metadata, content)

@spec loaded_save_state(
  String.t() | nil,
  Minga.Buffer.SaveState.metadata(),
  String.t()
) ::
  Minga.Buffer.SaveState.t()

Returns save state for content loaded from storage.

mark_dirty(state)

@spec mark_dirty(t()) :: t()

Marks the buffer as having unsaved changes and advances the mutation version.

mark_saved(state, metadata, content)

@spec mark_saved(t(), Minga.Buffer.SaveState.metadata(), String.t()) :: t()

Records the current version as the save point for dirty tracking.

mtime(state)

@spec mtime(t()) :: integer() | nil

Returns the saved file mtime.

record_clean_change(state)

@spec record_clean_change(t()) :: t()

Records a content change that should not by itself make a clean buffer dirty.

restore_version(state, version)

@spec restore_version(t(), non_neg_integer()) :: t()

Restores the mutation version and recalculates dirty state from the saved version.

retarget_path(state, file_path)

@spec retarget_path(t(), String.t()) :: t()

Retargets the buffer to a new file path without changing content or dirty state.

sync_dirty(state)

@spec sync_dirty(t()) :: t()

Recalculates dirty state from the current mutation version and saved version.

version(state)

@spec version(t()) :: non_neg_integer()

Returns the current mutation version.