Expand description
Small pure text transforms used by Edit/Tools actions.
Two shapes live here: whole-text transforms (&str -> String: line-ending
conversion, blank-line squeezing, ROT13, hard wrap) and cursor-relative
rewrites ((&str, usize) -> Option<(String, usize)>: increment number,
smart toggle, transpose characters/words/lines/sentences/paragraphs/
sections, wrap the paragraph at the cursor). The host applies the former via
App::transform_selection_or_buffer and the latter via
App::rewrite_at_cursor; everything here is unit-tested without a terminal.
Functions§
- bump_
number_ at - Increment (or decrement,
delta = -1) the integer at or immediately after the cursor char offsetcursorintext. Returns the rewritten text and the new cursor offset (kept at the number’s start), orNoneif no digit is found on the cursor’s line at/after the cursor. Handles an optional leading-. - delete_
char_ at - Delete the character at char offset
cursor(EmacsC-d), leaving the cursor where it was.Noneat the end of the buffer, where there is nothing to delete. - delete_
paragraph_ at - Delete the paragraph at the cursor (a run of non-blank lines) along with the
blank lines that separate it from the next one.
Nonewhen the text holds no paragraph. - delete_
section_ at - Delete the section at the cursor (lines delimited by two or more blank lines)
along with the break that separates it from the next one.
Nonewhen the text holds no section. - delete_
sentence_ at - Delete the sentence at the cursor along with the spacing after it, staying on
the line. Sentences are split as in the Go → Sentence navigation
(
sentence_starts).Nonewhen the text holds no sentence. - delete_
word_ at - Delete the word at the cursor (or the next one, when the cursor is between
words) along with the spacing after it, staying on the line.
Nonewhen the text holds no word. - line_
ranges - The
(start, end)char range of every line’s content, the newline excluded. A trailing newline does not add an empty final line. Public forvix-modal’s line-based motions (j/k/0/^/$/gg/G), which need the same line boundaries the transpose commands already use. - paragraph_
units - The
(start, end)char range of every paragraph: a run of non-blank lines, as in the Go → Paragraph navigation. Public forvix-modal’s{/}paragraph motions (crates/vix-modal/spec/index.md). - rot13
- ROT13: rotate ASCII letters by 13 (its own inverse); other chars unchanged.
- sentence_
starts - Char offsets where each sentence begins: the first non-space char, then the
first non-space char after any
./!/?(plus trailing quotes/brackets) followed by whitespace. Shared by the Go → Sentence navigation andtranspose_sentences_at, so both agree on where a sentence starts. - sentence_
units - The
(start, end)char range of every sentence, trailing whitespace excluded. Sentences begin wheresentence_startssays they do, so the transpose and delete commands agree with the Go → Sentence navigation. Public forvix-modal’s(/)sentence motions (crates/vix-modal/spec/index.md). - smart_
toggle_ at - Toggle the boolean-ish token at char offset
cursorto its opposite: word pairs (true/false,yes/no, …) matched as whole words with case preserved, or symbol pairs (&&/||,==/!=, …) at/around the cursor. Returns the rewritten text and the cursor’s new offset, orNoneif nothing togglable is under the cursor. - squeeze_
blank_ lines - Collapse runs of two or more blank (empty or whitespace-only) lines into a single empty line. A trailing newline is preserved.
- tag_
column - The 0-based char column of
taginlinewhen it appears as a whole word (bounded by non-word characters), orNone. Used by the TODO/FIXME finder. - to_crlf
- Convert all line endings to CRLF (
\r\n). Normalizes to LF first so mixed input doesn’t produce\r\r\n. - to_lf
- Convert all line endings to LF (
\n), dropping any\r. - transpose_
chars_ at - Transpose the two characters around char offset
cursor(EmacsC-t): swap the char before the cursor with the one at it, advancing the cursor. At the end of a line/buffer, swaps the last two characters. Never crosses newlines. Returns the rewritten text and new cursor, orNoneif there is no pair. - transpose_
lines_ at - Transpose the line before the cursor’s line with the cursor’s line (Emacs
C-x C-t), preserving the newline between them and leaving the cursor at the end of the pair.Noneon the first line of the buffer. - transpose_
paragraphs_ at - Transpose the paragraph before the cursor with the paragraph at/after it
(Emacs
M-x transpose-paragraphs), preserving the blank lines between them. Paragraphs are runs of non-blank lines, as in the Go → Paragraph navigation.Nonewhen there is no pair. - transpose_
sections_ at - Transpose the section before the cursor with the section at/after it,
preserving the break between them. Sections are delimited by a run of two or
more blank lines, as in the Go → Section navigation.
Nonewhen there is no pair. - transpose_
sentences_ at - Transpose the sentence before the cursor with the sentence at/after it
(Emacs
M-x transpose-sentences), preserving the whitespace between them. Sentences are split as in the Go → Sentence navigation (sentence_starts).Nonewhen there is no pair. - transpose_
words_ at - Transpose the word before the cursor with the word at/after it (Emacs
M-t), preserving the separator between them and leaving the cursor after the moved pair. ReturnsNoneif two words can’t be found. - word_
units - The
(start, end)char range of every word: a run of alphanumeric or_characters, as used by the word motions. Public forvix-modal’sw/b/eword motions (crates/vix-modal/spec/index.md) — same lowercase-onlyworddefinition the spec’s v1 explicitly picks (noWORDdistinction), so punctuation is a separator, not its own word, unlike real Vim’sword; documented there as a deliberate v1 scope decision. - wrap
- Hard-wrap (fill)
textto at mostwidthchars per line. Blank lines and list items separate chunks, and each chunk is refilled on its own: its words are re-flowed greedily, keeping the chunk’s indentation, any comment/quote marker shared by every line, and a hanging indent under a list bullet. Widths count chars, not terminal columns. - wrap_
paragraph_ at - Hard-wrap the paragraph around the cursor (the run of non-blank lines holding
it) to
widthchars, leaving the cursor at the end of the rewritten paragraph.Nonewhen the cursor is not in a paragraph or the paragraph is already wrapped.