MingaEditor.Commands (Minga v0.1.0)

Copy Markdown View Source

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 purestate → statepipeline (dot-repeat replay),execute/2returns{state, {:dot_repeat, count}}. The caller (Editor`) dispatches it.

Summary

Types

Action the GenServer must dispatch after execute/2.

Internal editor state.

Functions

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

Executes a single command against the editor state.

Starts a new buffer process for the given file path.

Types

action()

@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()

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

Internal editor state.

Functions

add_buffer(state, pid, opts \\ [])

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

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

execute(state, cmd)

@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(file_path)

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

Starts a new buffer process for the given file path.