pub fn electric_columns(
lang: Lang,
prev_nonblank: Option<&str>,
line: &str,
unit: IndentUnit,
) -> u16Expand description
The indent, in columns, for a line being electrically re-indented.
Deliberately lexical, not tree-driven, and that follows from
IN.2’s finding rather than being a shortcut. At the instant the
closer is typed, two things are true at once: the published snapshot
has not caught up with the edit, and the code around the cursor is
half-written — so a fresh parse would produce an ERROR node with
no block structure and the engine would decline anyway. There is no
version of this that the tree can answer, so asking it would cost a
parse to learn nothing.
It reuses indent_columns_for_new_line with the current line
passed as next: “the indent a new line here would get, given what
this line starts with” is exactly the question, so no second
algorithm is needed. Word closers subtract the extra level the
bracket scan cannot see.