mirror of https://github.com/helix-editor/helix
Merge a8a6f33f07
into 205e7ece70
commit
2bddcb5692
|
@ -53,6 +53,7 @@
|
|||
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` |
|
||||
| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` |
|
||||
| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` |
|
||||
| `atomic-save` | Whether the document should write its contents to a backup file, then rename that backup to the target file when saving. This prevents data loss if the editor is interrupted while writing the file, but may confuse some file watching/hot reloading programs. | `true` |
|
||||
| `trim-final-newlines` | Whether to automatically remove line-endings after the final one on write | `false` |
|
||||
| `trim-trailing-whitespace` | Whether to automatically remove whitespace preceding line endings on write | `false` |
|
||||
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` |
|
||||
|
|
|
@ -980,6 +980,7 @@ impl Document {
|
|||
// mark changes up to now as saved
|
||||
let current_rev = self.get_current_revision();
|
||||
let doc_id = self.id();
|
||||
let atomic_save = self.atomic_save();
|
||||
|
||||
let encoding_with_bom_info = (self.encoding, self.has_bom);
|
||||
let last_saved_time = self.last_saved_time;
|
||||
|
@ -1029,7 +1030,7 @@ impl Document {
|
|||
|
||||
// Assume it is a hardlink to prevent data loss if the metadata cant be read (e.g. on certain Windows configurations)
|
||||
let is_hardlink = helix_stdx::faccess::hardlink_count(&write_path).unwrap_or(2) > 1;
|
||||
let backup = if path.exists() {
|
||||
let backup = if path.exists() && atomic_save {
|
||||
let path_ = write_path.clone();
|
||||
// hacks: we use tempfile to handle the complex task of creating
|
||||
// non clobbered temporary path for us we don't want
|
||||
|
@ -1914,6 +1915,11 @@ impl Document {
|
|||
.unwrap_or_else(|| self.config.load().insert_final_newline)
|
||||
}
|
||||
|
||||
/// Whether the document should write its contents to a backup file, then rename that backup to the target file when saving. This prevents data loss if the editor is interrupted while writing the file, but may confuse some file watching/hot reloading programs.
|
||||
pub fn atomic_save(&self) -> bool {
|
||||
self.config.load().atomic_save
|
||||
}
|
||||
|
||||
/// Whether the document should trim whitespace preceding line endings on save.
|
||||
pub fn trim_trailing_whitespace(&self) -> bool {
|
||||
self.editor_config
|
||||
|
|
|
@ -346,6 +346,8 @@ pub struct Config {
|
|||
pub default_line_ending: LineEndingConfig,
|
||||
/// Whether to automatically insert a trailing line-ending on write if missing. Defaults to `true`.
|
||||
pub insert_final_newline: bool,
|
||||
/// Whether the document should write its contents to a backup file, then rename that backup to the target file when saving. This prevents data loss if the editor is interrupted while writing the file, but may confuse some file watching/hot reloading programs. Defaults to `true`
|
||||
pub atomic_save: bool,
|
||||
/// Whether to automatically remove all trailing line-endings after the final one on write.
|
||||
/// Defaults to `false`.
|
||||
pub trim_final_newlines: bool,
|
||||
|
@ -1021,6 +1023,7 @@ impl Default for Config {
|
|||
workspace_lsp_roots: Vec::new(),
|
||||
default_line_ending: LineEndingConfig::default(),
|
||||
insert_final_newline: true,
|
||||
atomic_save: true,
|
||||
trim_final_newlines: false,
|
||||
trim_trailing_whitespace: false,
|
||||
smart_tab: Some(SmartTabConfig::default()),
|
||||
|
|
Loading…
Reference in New Issue