Minga.Extension.Editor (Minga v0.1.0)

Copy Markdown View Source

Editor surface for Minga extensions.

This module provides the DSL macros and compile-time wiring for editor-specific extension components: options, commands, keybindings, modeline segments, and capabilities.

use Minga.Extension.Editor is the recommended way to define an extension that contributes editor UI and interaction features. It injects the Minga.Extension behaviour, registers compile-time accumulate attributes for each editor component, provides a default child_spec/1, and imports the editor DSL macros.

Usage

defmodule MingaOrg do
  use Minga.Extension.Editor

  option :conceal, :boolean,
    default: true,
    description: "Hide markup delimiters and show styled content"

  command :org_cycle_todo, "Cycle TODO keyword",
    execute: {MingaOrg.Todo, :cycle},
    requires_buffer: true

  keybind :normal, "SPC m t", :org_cycle_todo, "Cycle TODO", filetype: :org

  modeline_segment :word_count, side: :right, priority: 50 do
    if ctx.data.filetype in [:markdown, :text, :org] do
      {" WORDS ", ctx.info_fg, ctx.bar_bg, [], nil}
    end
  end

  capability :filetype, :org

  @impl true
  def name, do: :minga_org

  @impl true
  def description, do: "Org-mode support"

  @impl true
  def version, do: "0.1.0"

  @impl true
  def init(_config), do: {:ok, %{}}
end

For extensions that contribute agent-side components (hooks, skills, MCP servers, slash commands), see Minga.Extension.Agent.

Summary

Functions

Injects the Minga.Extension behaviour, editor DSL macros, and a default child_spec/1.

Declares a runtime or UI capability this extension uses.

Declares an editor command this extension provides.

Declares a keybinding this extension provides.

Sets the extension's load policy.

Declares a modeline segment this extension provides.

Functions

__using__(opts)

(macro)

Injects the Minga.Extension behaviour, editor DSL macros, and a default child_spec/1.

The injected macros are: option/3, command/3, keybind/4, keybind/5, modeline_segment/2, modeline_segment/3, and capability/2.

At compile time, each macro accumulates declarations into module attributes. The __before_compile__ hook then generates __option_schema__/0, __command_schema__/0, __keybind_schema__/0, __modeline_segment_schema__/0, and __capability_schema__/0 functions that the framework reads at load time.

capability(family, value)

(macro)

Declares a runtime or UI capability this extension uses.

Capabilities are declarative and are available through Minga.Extension.Manifest before init/1 runs. They should describe contribution surfaces or runtime needs, not perform side effects.

command(name, description, opts)

(macro)

Declares an editor command this extension provides.

Accumulated at compile time and exposed via __command_schema__/0. The framework auto-registers these commands when the extension loads.

Options

  • :execute (required) -- {Module, :function} MFA tuple. The function receives editor state and returns new state.
  • :requires_buffer -- when true, command is skipped if no buffer is active (default: false)

Examples

command :org_cycle_todo, "Cycle TODO keyword",
  execute: {MingaOrg.Todo, :cycle},
  requires_buffer: true

command :org_toggle_checkbox, "Toggle checkbox",
  execute: {MingaOrg.Checkbox, :toggle},
  requires_buffer: true

keybind(mode, key_string, command_name, description)

(macro)

Declares a keybinding this extension provides.

Accumulated at compile time and exposed via __keybind_schema__/0. The framework auto-registers these keybindings when the extension loads.

Examples

keybind :normal, "SPC m t", :org_cycle_todo, "Cycle TODO"
keybind :normal, "M-h", :org_promote_heading, "Promote heading", filetype: :org

load_policy(policy)

(macro)

Sets the extension's load policy.

See Minga.Extension for supported policies and examples.

modeline_segment(name, opts \\ [], list)

(macro)

Declares a modeline segment this extension provides.

The block receives ctx, the same context map used by built-in modeline segments, and returns a segment tuple, a list of segment tuples, nil, or [].

Examples

modeline_segment :word_count, side: :right, priority: 50 do
  if ctx.data.filetype in [:markdown, :text, :org] do
    {" WORDS ", ctx.info_fg, ctx.bar_bg, [], nil}
  end
end