edit: Editor-independent text actions and background Markdown facts#
Use find_window to read the caret’s local root list, table or block. Pass its text and absolute offset to act, together with the caller’s cached file-level Precedent and inert context. A host with the full buffer in memory can let act find that window. If preceding lines leave list ownership ambiguous, pass an editor-confirmed root slice. Scan document facts after edits, away from the typing path.
TYPING_ACTIONS lists keys that can delegate to the editor. ACTIONS also includes explicit commands with status messages for refusals.
Apply Result.edits in reverse order in one undo step. Install the new selections and any snippet fields after applying the edits. None delegates the key to the host. A result carrying only a message is a refusal.
Editor-independent text actions and background Markdown facts.
Use find_window to read the caret’s local root list, table or block. Pass its text and absolute offset to act, together with the caller’s cached file-level Precedent and inert context. A host with the full buffer in memory can let act find that window. If preceding lines leave list ownership ambiguous, pass an editor-confirmed root slice. Scan document facts after edits, away from the typing path.
TYPING_ACTIONS lists keys that can delegate to the editor. ACTIONS also includes explicit commands with status messages for refusals.
Apply Result.edits in reverse order in one undo step. Install the new selections and any snippet fields after applying the edits. None delegates the key to the host. A result carrying only a message is a refusal.
- class myform.edit.Context(window_offset: int = 0, precedent: Precedent | None = None, inert: bool = False, inert_ranges: tuple[Span, ...] = (), mode: Mode | None = None, declared: Precedent | None = None, line_ending: str | None = None, format_options: Mapping[str, object] | None = None)#
Editor state cached before invoking a typing action.
Offsets are absolute Python string indexes, including on a sliced window. Inert ranges are sorted and disjoint. Insertions at their start are protected.
- class myform.edit.Edit(start: int, end: int, text: str)#
Replace a half-open range in the original buffer with text.
- class myform.edit.Facts(headers: tuple[Header, ...], tables: tuple[Table, ...], fences: tuple[Fence, ...], notes: tuple[Note, ...], inert_ranges: tuple[Span, ...], open_inert_end: int | None = None)#
Landmarks and sorted, disjoint inert ranges for one buffer version.
- is_inert(point: int) bool#
Check an absolute caret, including the end of an unclosed raw fence.
- class myform.edit.Fence(start: int, end: int, opener: int, closer: int | None, mark: str, directive: str | None, raw: bool)#
A fence pair, with line-start offsets and an exclusive extent.
- class myform.edit.Header(start: int, end: int, level: int, title: str)#
A root heading, with its absolute source extent and unparsed title.
- class myform.edit.IdxMention(start: int, end: int, idx: Idx)#
A parsed address with the original offsets after its section sign.
- class myform.edit.IncludeSite(path: str, start: int, end: int)#
A complete root MyST include without arguments that change the inclusion.
- class myform.edit.InlineFacts(inlines: tuple[InlineSpan, ...], links: tuple[Link, ...], definitions: tuple[LinkDefinition, ...])#
Parser-derived inlines, resolved links and reference definitions.
- class myform.edit.InlineSpan(kind: str, start: int, end: int, inner_start: int, inner_end: int)#
A parser-recognized inline and its content in source coordinates.
- class myform.edit.Link(start: int, end: int, label_start: int, label_end: int, destination: str, destination_span: Span | None, title: str = '', reference_label: str | None = None, reference_span: Span | None = None)#
Source spans and the resolved destination of a Markdown link.
Offsets are half-open Python string indexes. The label range covers the displayed source inside its marks.
reference_labelis the parser’s normalized lookup key.reference_spancovers the second bracket pair’s contents, with an empty span for collapsed references and None for shortcuts.destination_spancovers the written destination when available.
- class myform.edit.LinkDefinition(label: str, start: int, end: int, destination: str, title: str, label_span: Span)#
The first parsed definition for a normalized label.
The source range covers the definition’s complete physical lines, including container prefixes and existing line endings. The label span excludes the brackets and retains the original spelling, escapes and line endings. The parser supplies destination and title as it resolves them for links.
- class myform.edit.Mode(*values)#
The editor mode requested by an action.
- class myform.edit.Note(start: int, end: int, label: str, definition: bool, block: Span | None = None, body_start: int | None = None, body: str = '')#
A note reference or definition and its source span.
- class myform.edit.PipeTable(rows: tuple[_Row, ...], newline: str)#
A table window with source spans for its header, delimiter and body.
- property start: int#
Return the first row’s offset within the supplied source.
- property end: int#
Return the last row’s end, before the line ending.
- property columns: int#
Return the number of columns declared by the header.
- property prefix: str#
Return the continuation prefix of the table’s container.
- property overflows: bool#
Report whether an edit could discard source cells beyond the header.
- property data_rows: tuple[int, ...]#
Return physical row indices, skipping the delimiter.
- property directions: list[str]#
Read the source alignment markers.
- property padding: TablePadding#
Infer local padding by the same rule used on formatter saves.
- values() list[list[str]]#
Read the rectangle of editable cells, with ragged cells filled in.
- locate(point: int) tuple[int, int]#
Return the physical row and the column at a source point.
- cell_span(point: int) tuple[int, int]#
Return the current cell’s content bounds in the supplied source.
- row_span(point: int) tuple[int, int]#
Return the current row’s bounds without its line ending.
- row_cell_count(point: int) int#
Return the number of source cells in the current row, before empty fill.
- position(point: int) str | None#
Describe the column and the header/body position for the status bar.
- in_raw_span(point: int) bool#
Tell whether an insertion point follows an opening backtick run in its cell.
- raw_pipe_offsets() tuple[int, ...]#
Find unescaped table separators inside matched raw spans across physical cells.
- class myform.edit.Result(edits: tuple[Edit, ...], selections: Selections, message: str | None = None, mode: Mode | None = None, fields: tuple[Span, ...] = (), register: str | None = None)#
Edits in buffer order and new selections in the edited buffer.
- class myform.edit.Section(start: int, end: int, level: int, marks: int, title_start: int, title: str, parent: int | None, subtree_end: int)#
A root ATX heading line and the extent of its structural subtree.
- class myform.edit.SectionExtraction(name: str, text: str, edit: Edit, anchors: frozenset[str])#
The sibling filename, complete new content, and edit to the original document.
- class myform.edit.Table(start: int, end: int, delimiter: int)#
A table extent and its delimiter row’s starting offset.
- class myform.edit.TableGhost(start: int, end: int, delimiter: str, body: str, caret: int, newline: str)#
A delimiter proposal at an empty source line below a possible table header.
- class myform.edit.Window(start: int, end: int, kind: 'list' | 'table' | 'block', line_ending: str = '\n')#
A root window excluding its last EOL, with its line ending as metadata.
- myform.edit.act(text: str, selections: Selections, action: str, context: Context, *, count: int | None = None, list_typed_mark: 'conform' | 'keep' = 'conform', window_hint: Window | None = None, **args: object) Result | None#
Plan the text changes for a key within its root editing window.
The input text may be the whole buffer or a window with a known absolute offset. Supply its line ending in Context when a sliced window omits its only EOL. All input ranges and output edits use original absolute offsets. A host can reuse action_window’s result as window_hint for the same supplied text, action and single selection. Result selections use absolute offsets in the resulting buffer. A key that falls through returns None. A structural refusal returns its message with the selections and text untouched. Wrap, link creation and note commands use the full document. For R, explicit note settings choose note organization, independently of the caret’s structural context.
- myform.edit.action_window(text: str, caret: int, action: str, *, end: int | None = None) Window | None#
Plan the bounded read for a key or delegate an unrelated line.
- myform.edit.add_directive_option(text: str, point: int, key: str, *, facts: Facts | None = None, catalog: Catalog | None = None) Result | None#
Insert an unset option into the existing option header’s syntax.
- myform.edit.change_directive(text: str, point: int, directive: DirectiveSpec, *, facts: Facts | None = None) Result | None#
Replace the directive name alone, leaving arguments, options and body in place.
- myform.edit.close_fence(text: str, selections: Selections, context: Context, *, facts: Facts) Result | None#
Close a verified unmatched opener before the host applies its other Enter rules.
- myform.edit.define_note(text: str, point: int, label: str, *, note_home: str = 'auto', facts: Facts | None = None) Result | None#
Create only the definition for an existing undefined reference.
- myform.edit.directive_options(text: str, point: int, *, facts: Facts | None = None, catalog: Catalog | None = None) tuple[OptionSpec, ...]#
List unused options for the directive at an editable caret.
- myform.edit.extract_section(text: str, start: int, stop: int, suffix: str, *, facts: Facts | None = None) SectionExtraction | None#
Move a self-contained root section into an adjacent source file via a MyST include.
- myform.edit.fence_line(text: str, start: int) FenceLine | None#
Recognize the delimiter at the structural content column of a line.
- myform.edit.fence_mark(text: str, char: str) str#
Choose a delimiter longer than every run of that character in the body.
- myform.edit.fence_precedent(facts: Facts, kind: FenceKind) str#
Use the file’s first fence of the same kind, with MyST defaults.
- myform.edit.find_window(text: str, caret: int) Window#
Find the caret’s root list, table or block by walking neighboring lines.
The offsets index Python characters. The caller supplies inert context separately.
- myform.edit.header_at(sections: tuple[Section, ...], point: int) int | None#
Find a header only when the point is on its physical line.
- myform.edit.idx_headings(text: str, spec: IdxSpec, facts: Facts | None = None, *, base_level: int | None = None) tuple[HeadingPlan, ...]#
Return arch plans for the editable headers at their original offsets.
- myform.edit.idx_mentions(text: str, spec: IdxSpec, facts: Facts | None = None) tuple[IdxMention, ...]#
Find explicit parseable mentions in Markdown prose, shielding raw material.
- myform.edit.include_site(text: str, start: int, stop: int, *, facts: Facts | None = None) IncludeSite | None#
Recognize a whole plain include with the request on its opening line.
- myform.edit.inline_include(text: str, site: IncludeSite, content: str, *, same_directory: bool) Edit | None#
Replace a confirmed include with a stable source snapshot.
- myform.edit.inline_note(text: str, start: int, stop: int, *, facts: Facts | None = None) tuple[Edit, ...]#
Inline a single-paragraph note and remove its definition when no use remains.
- myform.edit.is_table_delimiter(text: str) bool#
Screen a line for a possible table separator without parsing any cells.
- myform.edit.is_table_line(text: str) bool#
Screen a physical line for a pipe row or a one-column delimiter.
- myform.edit.list_marker(text: str, caret: int) tuple[int, int] | None#
Read the absolute marker bounds for the caret’s item line, if any.
- myform.edit.match_fence(text: str, point: int, *, facts: Facts | None = None) Result | None#
Navigate from either fence line to the other line’s first delimiter.
- myform.edit.may_have_idxs(text: str, path: Path | None = None) bool#
Cheaply detect cases where a structural command might need optional arch.
- myform.edit.new_directive(text: str, selection: Span, directive: DirectiveSpec, *, wrap: bool = False, facts: Facts | None = None) Result | None#
Plan a registry-backed directive skeleton or wrap selected whole lines.
- myform.edit.new_fence(text: str, point: int, kind: FenceKind, *, facts: Facts | None = None) Result | None#
Open a code or math block below the caret’s block, with a fill-in caret.
- myform.edit.new_target(text: str, point: int, label: str, *, facts: Facts | None = None) Result | None#
Add a target above the current block and return its clipboard reference.
- myform.edit.next_note_label(facts: Facts, policy: str = 'auto') str | None#
Choose the next numeric label, or return None when a name must be supplied.
- myform.edit.note_at(facts: Facts, point: int) Note | None#
Find a marker or the surrounding definition at a caret, including marker end.
- myform.edit.note_jumps(facts: Facts, point: int) tuple[Note, ...]#
Return all opposite endpoints of the note under the caret, in source order.
- myform.edit.outline(text: str, facts: Facts | None = None) tuple[Section, ...]#
Read the root outline. Parent values index the returned tuple.
- myform.edit.parse_mention(text: str, spec: IdxSpec) Idx#
Parse an address as written in prose, with a section sign accepted.
- myform.edit.plan_list_refactors(text: str, start: int, stop: int, *, format_name: str = 'myst', facts: Facts | None = None, doc: Doc | None = None) tuple[tuple[ListRewrite, Edit], ...]#
Return the proven rewrites for a root list or a selection of sections.
- myform.edit.preview_idxs(text: str, point: int, path: Path | None = None) tuple[str, ...]#
Offer the new title’s regular and available reserved address.
- myform.edit.read_table(text: str, caret: int) PipeTable | None#
Read the table around a caret, given text and a caret relative to that text.
- myform.edit.rebalance_fences(text: str, point: int, *, facts: Facts | None = None) Result | None#
Close an unpaired fence or lengthen an ordinary directive around its nested fences.
- myform.edit.resolve_idx_spec(text: str, path: Path | None = None, *, name: str | None = None, facts: Facts | None = None) IdxSpec | None#
Resolve a front matter, project, explicit Add choice or inferred index spec.
- myform.edit.scan_facts(text: str) Facts#
Scan headings, tables, fences, notes and inert ranges in a Markdown buffer.
Typing actions consume the cached inert ranges and do not call this document scan.
- myform.edit.scan_inline_facts(text: str) InlineFacts#
Collect source-mapped inlines and reference facts in one Markdown parse.
Spans use half-open Python string indexes in the supplied text. Each tuple is in source order. Nested inlines with a shared start list the outer span first. Reference-looking text with an undefined label remains literal text and produces no link fact. Repeated definition labels resolve to the first.
- myform.edit.scan_links(text: str) tuple[Link, ...]#
Resolve inline links, autolinks and defined references in source order.
Unresolved reference syntax remains literal text in the Markdown parser.
- myform.edit.section_at(sections: tuple[Section, ...], point: int) int | None#
Find the innermost section holding the point, including its body.
- myform.edit.section_destination(sections: tuple[Section, ...], point: int, motion: str, count: int = 1) int | None#
Return the destination header index for a structural motion.
- myform.edit.slugify(title: str) str#
Use the heading anchor spelling already used by myForm navigation.
- myform.edit.table_export(table: PipeTable, target: str) str#
Serialize table cell contents without editing the source.
- myform.edit.table_ghost(text: str, caret: int) TableGhost | None#
Propose a delimiter for a standalone pipe header above an empty line.
- myform.edit.target_label(text: str, point: int, *, facts: Facts | None = None) str#
Propose the heading slug, or an empty field on another block.
- myform.edit.web_url(value: str) str | None#
Accept a single complete HTTP(S) URL with a host, or a mail address.