# `MingaEditor.Commands.BufferManagement`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/commands/buffer_management.ex#L4)

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

# `format_terminal`

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

# `save_action`

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

# `save_continuation`

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

# `session_restart_ownership`

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

# `state`

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

# `alternate_file`

```elixir
@spec alternate_file(state()) :: state()
```

# `apply_filetype_change`

```elixir
@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`

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

# `execute`

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

# `handle_agent_session_down`

```elixir
@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`

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

Refreshes editor state after SessionManager restarts a managed session.

# `open_special_buffer`

```elixir
@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`

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

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

# `reload_config`

```elixir
@spec reload_config(state()) :: state()
```

# `reload_config`

```elixir
@spec reload_config(state(), module()) :: state()
@spec reload_config(state(), (state() -&gt; {:ok | {:error, String.t()}, state()})) ::
  state()
```

Schedules config reload through an explicit reload implementation.

# `reload_config`

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

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

# `tab_goto`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
