Repository navigation
Conversation
Like the Ruby rmate, open a file that does not exist yet as an empty buffer (data: 0) and create it when the editor first saves it. If the buffer is closed without saving, no file is left behind. The parent directory must exist. -c/--create keeps its behaviour: it creates the file when opening it. On save, the file is opened with create(true), and the backup step is skipped when there is no file to back up. Fixes the TODO in main.rs about the default for creating missing files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR lets rmate open a file that does not exist yet without
-c/--create, as the Ruby implementation does. The editor shows an empty buffer, and the file is created when the editor first saves it.Note: If the buffer is closed without saving, no file is left behind. This is the same behavior of Ruby implementation and what a user would intuitively expect. Note that this is different than the current
-c/--createoption, which creates the empty file first, even if later the user decides to save nothing.Motivation
Without
-c, rmate exits on a missing file withError: "No such file or directory (os error 2)". Issue #1 asked for a way to open a new file without runningtouchfirst, and-cwas added for that (cb8ccd6). With-c, the file is created on disk at open, even if you never save it.The Ruby rmate implementation creates nothing at open time. For a missing file it sends
data: 0:The README says rmate-rs supports all options and rmate.rc settings of the Ruby implementation, so this PR follows the same pattern. It also resolves the TODO in
main.rs: "Flip how the setting for creating non-existing files work so by default it doesn't create new empty files."Changes
These changes are automatically generated by CLAUDE:
src/file_handler.rs,get_requested_buffers(): without-c, a missing file is no longer an error. A new helper,canonicalize_missing(), resolves the path through its parent directory, which must exist. The buffer gets size 0, and the read-only check is skipped until the file is saved.src/file_handler.rs,write_to_disk(): the target is opened withcreate(true), and the backup tofile~is skipped when there is no file to back up.src/remote_editor.rs,open_file_in_remote(): for a missing file, sends empty contents instead of failing onFile::open.src/settings.rs: the-chelp now reads "Create a missing file when opening it. Without this flag, a missing file is created when it is first saved".src/main.rs: removes the TODO.README.md: one entry under Features.Testing
Tested on macOS (aarch64) against a test editor that receives the file, then sends
saveandclose, and against an Emacs rmate server:-c-cNo such file or directory, exit 1Couldn't save: … Permission denied; nothing createdAlso tested end to end on Linux (RHEL 9, kernel 5.14, x86_64): rmate on the remote host opened a missing file in the editor on macOS, with and without
-c. Without-c, the file was created on save, and no file was created when the buffer was closed without saving. With-c, the file was created at open.Additional remarks
master, and they merge without conflicts in either order.is_some_andandis_none_orneed Rust 1.82. CI builds withstable.