Use Rust and Ruby Syntax
By the end of this chapter, you will have navigated syntax, selected a complete definition, and undone a syntax indentation change.
Current built-in syntax support covers saved .rs and .rb paths. Matching
is case-sensitive. Other suffixes and pathless buffers retain ordinary text
editing. Syntax analysis does not require or start a language server.
Prepare a Rust File
From the repository root, save this text as syntax.rs:
fn greet() {
let message = "hello";
println!("{message}");
}
Open it in the nonmodal profile:
env -u RUBYOPT -u RUBYLIB -u GEM_HOME -u GEM_PATH \
cargo run --locked -p rur-editor --bin rur-terminal-proof -- \
--profile nonmodal syntax.rs
Keywords and comments use syntax styles from the selected theme. Active regions and search matches retain their own emphasis.
Navigate and Select Structure
Move to the second line with Down. Through Alt-x, choose move-syntax-up.
Point moves to the enclosing block; repeating moves toward the outer function.
move-syntax-down enters a named child. move-syntax-forward and
move-syntax-backward visit named siblings. A missing target leaves point in
place. These commands have no factory key bindings.
Return to the second line with move-buffer-start, then Down. Invoke
select-syntax. The ordinary active region selects the syntax node at point.
Repeating the command expands an exact node selection to its enclosing named
node when one exists. Ctrl-G deactivates the region.
Invoke select-definition from inside the function. The region covers the
outer function. Repeating retains that definition. This command selects an
outer definition; it does not look up a symbol in another file.
Indent and Undo
Cancel the active region, return to the second line, and choose indent-syntax
through Alt-x. The current line gains leading indentation according to the
active editing policy. Ctrl-Z restores the original unindented line;
Ctrl-X Ctrl-Z reapplies the change.
A linear region applies indentation to its intersected lines as one undoable change. Blank lines, comments, strings, and malformed lines retain their bytes. Save deliberately with Ctrl-X Ctrl-S, then leave through Ctrl-Q.
Try Ruby and Plain Text
After leaving the editor, save this text as syntax.rb:
class Greeting
def message
"hello"
end
end
Start another editor process with the earlier command, replacing syntax.rs
with syntax.rb. Inside message, select-definition selects the outer class.
The same syntax movement, selection, and indentation command names apply. A .txt file with
identical content remains ordinary text: syntax commands preserve point and
selection when analysis is unavailable.
See Syntax Movement, Definition Selection, and Syntax Indentation for the exact target and preservation rules.
Previous: Language Intelligence | Part | User Guide | Next: Exercise Language Server Transport