Minga.Editing.TextObject (Minga v0.1.0)

Copy Markdown View Source

Text object selection for Vim operator-pending mode.

Each function takes a Readable.t() and a cursor position() and returns a {start_pos, end_pos} range (both positions inclusive), or nil when no matching text object exists around the cursor.

All positions use byte-indexed columns ({line, byte_col}).

Word text objects

  • inner_word/2 (iw) — the word (or whitespace run) under the cursor, without surrounding whitespace.
  • a_word/2 (aw) — the word plus one surrounding whitespace run (trailing preferred; leading used when at end of line).

Paragraph text objects

  • inner_paragraph/2 (ip) — contiguous non-blank lines around the cursor, or the current blank-line run when the cursor is on a blank line.
  • a_paragraph/2 (ap) — the paragraph plus one surrounding blank line, preferring a trailing blank line and using a leading blank at end of file.

Sentence text objects

  • inner_sentence/2 (is) — the current sentence without trailing whitespace.
  • a_sentence/2 (as) — the current sentence including trailing whitespace.

Quote text objects

  • inner_quotes/3 (i", i') — the content between the nearest enclosing quote pair on the current line, excluding the quote characters themselves.
  • a_quotes/3 (a", a') — same range including the quote characters.

Parenthesis / bracket text objects

  • inner_parens/4 (i(, i{, i[) — content between the nearest enclosing open/close delimiter pair, excluding the delimiters. Handles nesting: e.g. i( inside (a (b) c) with cursor on b selects a (b) c.
  • a_parens/4 (a(, a{, a[) — same range including the delimiters.

Delimiter search spans multiple lines.

Summary

Types

A zero-indexed {line, byte_col} position.

An inclusive {start_pos, end_pos} range, or nil when not found.

Structural text object type.

Raw tree-sitter textobject result: {start_row, start_col, end_row, end_col} or nil.

Functions

Returns the current paragraph plus one surrounding blank line.

Returns the range of text including the nearest enclosing delimiter pair around the cursor.

Returns the range of text including the nearest enclosing quote pair on the cursor's line.

Returns the current sentence including trailing whitespace.

Returns the range of the word under the cursor plus one adjacent whitespace run (trailing preferred; leading used when the word is at the end of line).

Returns the current paragraph range without surrounding blank lines.

Returns the range of text inside the nearest enclosing delimiter pair around the cursor, not including the delimiters.

Returns the range of text inside the nearest enclosing quote pair on the cursor's line, not including the quote characters.

Returns the current sentence without trailing whitespace.

Returns the range of the word (or whitespace / symbol run) under the cursor, excluding any surrounding whitespace.

Converts a raw tree-sitter textobject range into an inclusive Vim-style outer range.

Converts a raw tree-sitter textobject range into an inclusive Vim-style inner range.

Types

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

A zero-indexed {line, byte_col} position.

range()

@type range() :: {position(), position()} | nil

An inclusive {start_pos, end_pos} range, or nil when not found.

structural_type()

@type structural_type() :: :function | :class | :parameter | :block | :comment | :test

Structural text object type.

tree_range()

@type tree_range() ::
  {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
  | nil

Raw tree-sitter textobject result: {start_row, start_col, end_row, end_col} or nil.

Functions

a_paragraph(buffer, position)

@spec a_paragraph(Minga.Editing.Text.Readable.t(), position()) :: range()

Returns the current paragraph plus one surrounding blank line.

A trailing blank line is preferred. If the paragraph reaches end of file and has a leading blank line, that leading blank is included instead.

Corresponds to Vim's ap text object.

a_parens(buffer, position, open_char, close_char)

Returns the range of text including the nearest enclosing delimiter pair around the cursor.

Searches across multiple lines. Handles nesting.

Returns nil if no enclosing pair is found.

Corresponds to Vim's a(, a{, a[, etc.

a_quotes(buffer, arg, quote_char)

@spec a_quotes(Minga.Editing.Text.Readable.t(), position(), String.t()) :: range()

Returns the range of text including the nearest enclosing quote pair on the cursor's line.

Returns nil if no enclosing quote pair is found.

Corresponds to Vim's a" / a' motions.

a_sentence(buffer, position)

@spec a_sentence(Minga.Editing.Text.Readable.t(), position()) :: range()

Returns the current sentence including trailing whitespace.

When the cursor is on whitespace between two sentences, this follows Vim's around-sentence behavior and selects the following sentence.

Corresponds to Vim's as text object.

a_word(buffer, arg)

Returns the range of the word under the cursor plus one adjacent whitespace run (trailing preferred; leading used when the word is at the end of line).

Corresponds to Vim's aw motion in operator-pending mode.

inner_paragraph(buffer, position)

@spec inner_paragraph(Minga.Editing.Text.Readable.t(), position()) :: range()

Returns the current paragraph range without surrounding blank lines.

A paragraph is a contiguous run of non-blank lines. When the cursor is on a blank line, the current blank-line run is returned so operators still have a stable linewise target.

Corresponds to Vim's ip text object.

inner_parens(buffer, position, open_char, close_char)

@spec inner_parens(
  Minga.Editing.Text.Readable.t(),
  position(),
  String.t(),
  String.t()
) :: range()

Returns the range of text inside the nearest enclosing delimiter pair around the cursor, not including the delimiters.

Searches across multiple lines. Handles nesting (the cursor's depth relative to the nearest enclosing pair is tracked).

Returns nil if no enclosing pair is found.

Corresponds to Vim's i(, i{, i[, etc.

inner_quotes(buffer, arg, quote_char)

@spec inner_quotes(Minga.Editing.Text.Readable.t(), position(), String.t()) :: range()

Returns the range of text inside the nearest enclosing quote pair on the cursor's line, not including the quote characters.

Returns nil if no enclosing quote pair is found.

Corresponds to Vim's i" / i' motions.

inner_sentence(buffer, position)

@spec inner_sentence(Minga.Editing.Text.Readable.t(), position()) :: range()

Returns the current sentence without trailing whitespace.

Sentences end at ., !, or ?, may include closing delimiters after the punctuation, and stop at paragraph boundaries.

Corresponds to Vim's is text object.

inner_word(buffer, arg)

@spec inner_word(Minga.Editing.Text.Readable.t(), position()) ::
  {position(), position()}

Returns the range of the word (or whitespace / symbol run) under the cursor, excluding any surrounding whitespace.

Corresponds to Vim's iw motion in operator-pending mode.

structural_around(tree_data)

@spec structural_around(tree_range()) :: range()

Converts a raw tree-sitter textobject range into an inclusive Vim-style outer range.

Semantically identical to structural_inner/1 (tree-sitter already distinguishes inside vs around via the capture name). This function exists so callers can express intent clearly.

structural_inner(tree_data)

@spec structural_inner(tree_range()) :: range()

Converts a raw tree-sitter textobject range into an inclusive Vim-style inner range.

The caller is responsible for querying the parser (via Parser.Manager.request_textobject/4) and passing the result here. Returns nil when tree_data is nil (no match found by the parser).