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) and cursor-relative rewrites ((&str, usize) -> Option<(String, usize)>: increment number, smart toggle, transpose). 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 -.
rot13
ROT13: rotate ASCII letters by 13 (its own inverse); other chars unchanged.
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_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.