Public API for interacting with the editor from eval (M-:).
Provides user-friendly functions for common editor operations. All
functions default to the running MingaEditor GenServer and the
active buffer. Pass an explicit editor PID to target a different
instance.
Usage from eval
# M-: Minga.API.insert("hello")
# M-: Minga.API.save()
# M-: Minga.API.cursor()
# M-: Minga.API.open("lib/minga.ex")Error handling
Functions return {:ok, result} or {:error, reason} where
possible. They never raise on bad input.
Summary
Functions
Returns the full content of the active buffer.
Returns the current cursor position as {line, col} (0-indexed).
Executes an editor command by name.
Folds all available ranges in the active window.
Toggles the fold at the cursor line in the active window.
Inserts text at the current cursor position in the active buffer.
Returns the number of lines in the active buffer.
Logs a message to the *Messages* buffer.
Returns the current editor mode (e.g. :normal, :insert, :visual).
Moves the cursor to the given {line, col} position (0-indexed).
Opens a file in the editor. If the file is already open, switches to it.
Saves the active buffer to disk.
Sets the available fold ranges for the active window.
Unfolds all folds in the active window.
Types
@type editor() :: GenServer.server()
Editor GenServer reference.
Functions
Returns the full content of the active buffer.
Examples
{:ok, text} = Minga.API.content()
@spec cursor(editor()) :: {:ok, {non_neg_integer(), non_neg_integer()}} | {:error, :no_buffer}
Returns the current cursor position as {line, col} (0-indexed).
Examples
{:ok, {line, col}} = Minga.API.cursor()
@spec execute(Minga.Mode.command(), editor()) :: :ok
Executes an editor command by name.
Commands are the same atoms used internally (e.g. :save, :undo,
:move_down, :buffer_next). See Minga.Command.Registry for
the full list.
Examples
Minga.API.execute(:undo)
Minga.API.execute(:buffer_next)
Minga.API.execute({:goto_line, 42})
@spec fold_all(editor()) :: :ok
Folds all available ranges in the active window.
@spec fold_toggle(editor()) :: :ok
Toggles the fold at the cursor line in the active window.
Inserts text at the current cursor position in the active buffer.
Examples
Minga.API.insert("hello world")
Minga.API.insert("\n") # insert a newline
@spec line_count(editor()) :: {:ok, non_neg_integer()} | {:error, :no_buffer}
Returns the number of lines in the active buffer.
Examples
{:ok, count} = Minga.API.line_count()
Logs a message to the *Messages* buffer.
Examples
Minga.API.message("Build completed!")
@spec mode(editor()) :: Minga.Mode.mode()
Returns the current editor mode (e.g. :normal, :insert, :visual).
Examples
:normal = Minga.API.mode()
@spec move_to(non_neg_integer(), non_neg_integer(), editor()) :: :ok | {:error, :no_buffer}
Moves the cursor to the given {line, col} position (0-indexed).
Examples
Minga.API.move_to(0, 0) # go to start of file
Minga.API.move_to(10, 5) # line 11, column 6
Opens a file in the editor. If the file is already open, switches to it.
Examples
:ok = Minga.API.open("lib/minga.ex")
Saves the active buffer to disk.
Examples
:ok = Minga.API.save()
@spec set_fold_ranges([Minga.Editing.Fold.Range.t()], editor()) :: :ok
Sets the available fold ranges for the active window.
Extensions call this to provide fold ranges computed from their own logic (e.g., org-mode heading ranges). The editor will preserve any existing folds that match the new ranges.
@spec unfold_all(editor()) :: :ok
Unfolds all folds in the active window.