Change Two Files Together
By the end of this chapter, you will have run one configured command that changes two files, undone both changes together and verified their saved bytes.
Create two files in the repository root:
printf 'alpha\n' > first.txt
printf 'beta\n' > second.txt
Save this trusted configuration as pair.rb in the same directory:
targets = ['first.txt', 'second.txt'].map { |path| File.expand_path(path) }
Rur.configuration.command('prefix-pair', lambda { |context|
members = context.buffers.select { |entry| targets.include?(entry.fetch('name')) }
raise 'Open both target files first' unless members.length == 2
participants = members.map { |entry| entry.fetch('participant') }
context.declare(participants)
participants.each do |participant|
range = context.observe(participant, 0, 0)
context.replace(participant, range.merge('replacement' => 'X'))
end
}, {'kind' => 'multibuffer', 'requires' => 'buffer', 'effects' => ['text', 'selection']})
This command selects exactly those two normalized filenames. Other open buffers remain outside its declared scope. An unavailable target rejects the command before any text changes. Trusted configuration runs with your process's ordinary Ruby permissions; load only source you trust.
Start from that directory:
cargo run --locked -p rur-editor --bin rur-terminal-proof -- --config pair.rb first.txt
Press Ctrl-X Ctrl-F, enter second.txt, then Enter. Invoke prefix-pair through
Alt-x and Enter. The files now contain Xalpha and Xbeta. Ctrl-X b switches
using the complete displayed filename; the pane controls
let you display both at once.
Press Ctrl-Z from either participating buffer. Both prefixes disappear together.
Press Ctrl-X Ctrl-Z to redo both. With --profile modal, return to Normal and
use u and Ctrl-R for the same linked undo/redo. A later independent edit can
make a peer's history head incompatible; an ordinary linked undo then refuses
the whole operation rather than undoing only one file.
Save each buffer separately with Ctrl-X Ctrl-S. A linked text edit does not combine filesystem Saves into one operation. Exit with Ctrl-X Ctrl-C and verify:
cat first.txt second.txt
The output is Xalpha followed by Xbeta, on separate lines. Closing a pane
keeps the file open. Closing just one buffer can refuse while its retained
history still links to another live buffer. Complete Exit considers all buffers
and resolves their dirty decisions together.
Text, mark and undo history belong to the buffer; each pane retains its own point and viewport. Focus and arrangement changes are outside text undo. For retained branch targets and selective compensation, continue with Use Retained History and the checked Ruby API.
Previous: Repeat and Record Changes | Part | User Guide | Next: Recover Unsaved Work