Skip to main content

Crate vix_textops

Crate vix_textops 

Source
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 offset cursor in text. Returns the rewritten text and the new cursor offset (kept at the number’s start), or None if 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 (Emacs C-d), leaving the cursor where it was. None at 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. None when 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. None when 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). None when 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. None when 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 for vix-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 for vix-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 and transpose_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 where sentence_starts says they do, so the transpose and delete commands agree with the Go → Sentence navigation. Public for vix-modal’s (/) sentence motions (crates/vix-modal/spec/index.md).
smart_toggle_at
Toggle the boolean-ish token at char offset cursor to 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, or None if 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 tag in line when it appears as a whole word (bounded by non-word characters), or None. 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 (Emacs C-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, or None if 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. None on 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. None when 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. None when 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). None when 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. Returns None if 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 for vix-modal’s w/b/e word motions (crates/vix-modal/spec/index.md) — same lowercase-only word definition the spec’s v1 explicitly picks (no WORD distinction), so punctuation is a separator, not its own word, unlike real Vim’s word; documented there as a deliberate v1 scope decision.
wrap
Hard-wrap (fill) text to at most width chars 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 width chars, leaving the cursor at the end of the rewritten paragraph. None when the cursor is not in a paragraph or the paragraph is already wrapped.