MingaEditor.Commands.BufferManagement (Minga v0.1.0)

Copy Markdown View Source

Buffer management commands: save/reload/quit, buffer list/navigation/kill, ex-command dispatch, and line number style cycling.

Summary

Functions

Changes the active buffer's filetype and triggers a highlight reparse.

Cleans up editor state after an agent session dies (:DOWN handler).

Refreshes editor state after SessionManager restarts a managed session.

Opens a special buffer in a popup window or switches to it.

Normalizes shell identity and returns whether the old session is still owned.

Schedules config reload through an explicit reload implementation.

Schedules config reload with explicit data arguments for the reload implementation.

Types

format_terminal()

@type format_terminal() ::
  {:committed, non_neg_integer()}
  | :unchanged
  | {:failed, term()}
  | :stale
  | :canceled

save_action()

@type save_action() ::
  :save | {:save_quit, MingaEditor.State.Tab.id() | nil} | {:save_as, Path.t()}

save_continuation()

@type save_continuation() ::
  {:save_after_format, pid(), non_neg_integer(), save_action()}

session_restart_ownership()

@type session_restart_ownership() :: {:owned, state()} | {:stale, state()}

state()

@type state() :: MingaEditor.State.t()

Functions

alternate_file(state)

@spec alternate_file(state()) :: state()

apply_filetype_change(state, filetype)

@spec apply_filetype_change(state(), atom()) :: state()

Changes the active buffer's filetype and triggers a highlight reparse.

Used by the language picker (LanguageSource.on_select) and the :set ft= ex command. Centralizes the side effects so both paths stay in sync.

continue_after_format(state, continuation, terminal)

@spec continue_after_format(state(), save_continuation(), format_terminal()) ::
  state()

execute(state, arg2)

@spec execute(state(), Minga.Mode.command()) :: state()

handle_agent_session_down(state, session_pid, reason)

@spec handle_agent_session_down(state(), pid(), term()) :: state()

Cleans up editor state after an agent session dies (:DOWN handler).

The session is already dead, so no stop/unsubscribe is needed. This clears the spinner, agent state, tab session/status, and workspace.

handle_agent_session_restarted(state, session_id, old_pid, new_pid, reason)

@spec handle_agent_session_restarted(state(), String.t(), pid(), pid(), term()) ::
  state()

Refreshes editor state after SessionManager restarts a managed session.

open_special_buffer(state, buffer_name, buffer_pid)

@spec open_special_buffer(state(), String.t(), pid()) :: state()

Opens a special buffer in a popup window or switches to it.

prepare_agent_session_restart(state, old_pid)

@spec prepare_agent_session_restart(state(), pid()) :: session_restart_ownership()

Normalizes shell identity and returns whether the old session is still owned.

reload_config(state)

@spec reload_config(state()) :: state()

reload_config(state, reload_module)

@spec reload_config(state(), module()) :: state()
@spec reload_config(state(), (state() -> {:ok | {:error, String.t()}, state()})) ::
  state()

Schedules config reload through an explicit reload implementation.

reload_config(state, reload_module, reload_args)

@spec reload_config(state(), module(), [term()]) :: state()

Schedules config reload with explicit data arguments for the reload implementation.

tab_goto(state, cmd)

@spec tab_goto(state(), atom()) :: state()