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 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-. - rot13
- ROT13: rotate ASCII letters by 13 (its own inverse); other chars unchanged.
- 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_
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.