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

Command execution for the editor.

Atom commands are dispatched through `Minga.Command.Registry`, which maps
command names to execute functions pointing at the appropriate sub-module.
Tuple commands (parameterized commands like `{:insert_char, c}`) still use
pattern matching since they carry runtime arguments.

## Sub-modules

* `Commands.Movement`        — h/j/k/l, word, find-char, bracket, page scroll
* `Commands.Editing`         — insert/delete, join, replace, indent, undo/redo, paste
* `Commands.Operators`       — d/c/y with motions and text objects
* `Commands.Visual`          — visual selection delete/yank/wrap
* `Commands.Search`          — /, n/N, *, word-under-cursor search
* `Commands.BufferManagement`— save/reload/quit, :ex commands, buffer cycling
* `Commands.Marks`           — m, ', `, ``

## Action tuples

When a command requires the GenServer to do something outside the pure
`state → state` pipeline (dot-repeat replay), `execute/2` returns
`{state, {:dot_repeat, count}}`. The caller (`Editor`) dispatches it.

# `action`

```elixir
@type action() ::
  {:dot_repeat, non_neg_integer() | nil}
  | {:replay_macro, String.t()}
  | {:whichkey_update, MingaEditor.State.WhichKey.t()}
```

Action the GenServer must dispatch after execute/2.

# `state`

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

Internal editor state.

# `add_buffer`

```elixir
@spec add_buffer(state(), pid(), keyword()) :: state()
```

Adds a new buffer to the list and makes it active.

# `execute`

```elixir
@spec execute(state(), Minga.Mode.command()) :: state() | {state(), action()}
```

Executes a single command against the editor state.

Atom commands are resolved through the Command Registry. Tuple commands
(parameterized commands) are dispatched via pattern matching.

Returns `state()` for the common case, or `{state(), action()}` when the
GenServer must dispatch a follow-up action (dot-repeat, macro replay).

# `start_buffer`

```elixir
@spec start_buffer(String.t()) :: {:ok, pid()} | {:error, term()}
```

Starts a new buffer process for the given file path.

---

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