Skip to content

Commit

Permalink
WIP: Save splits on quit and automatically load it at startup.
Browse files Browse the repository at this point in the history
With this patch, Helix will automatically save the splits before
quitting and then load it when starting.

TODO: Unit testing?
  • Loading branch information
useche committed Dec 2, 2024
1 parent 0f3ecf4 commit 87e8be0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions book/src/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ The state is formatted with bincode, and stored in files in the state directory
| `commands` | whether to persist command history between sessions | `false` |
| `search` | whether to persist search history between sessions | `false` |
| `clipboard` | whether to persist helix's internal clipboard between sessions | `false` |
| `autostart-splits` | Set to `true` to automatically save the last split before quitting and load it when starting. | `false` |
| `old-files-exclusions` | a list of regexes defining file paths to exclude from persistence | `[".*/\.git/.*", ".*/COMMIT_EDITMSG"]` |
| `old-files-trim` | number of old-files entries to keep when helix trims the state files at startup | `100` |
| `commands-trim` | number of command history entries to keep when helix trims the state files at startup | `100` |
Expand Down
5 changes: 5 additions & 0 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ impl Application {
}
} else if stdin().is_tty() || cfg!(feature = "integration") {
editor.new_file(Action::VerticalSplit);
if persistence_config.autostart_splits {
if editor.load_split("".to_string()).is_err() {
editor.set_error("Unable to load default split. First time using it?");
}
}
} else {
editor
.new_file_from_stdin(Action::VerticalSplit)
Expand Down
4 changes: 3 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ fn quit_all_impl(cx: &mut compositor::Context, force: bool) -> anyhow::Result<()
}

// save split in default before quitting
cx.editor.save_split("".to_string());
if cx.editor.config().persistence.autostart_splits {
cx.editor.save_split("".to_string());
}

// close all views
let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ pub struct PersistenceConfig {
pub commands: bool,
pub search: bool,
pub clipboard: bool,
pub autostart_splits: bool,
pub old_files_exclusions: Vec<EqRegex>,
pub old_files_trim: usize,
pub commands_trim: usize,
Expand All @@ -988,6 +989,7 @@ impl Default for PersistenceConfig {
commands: false,
search: false,
clipboard: false,
autostart_splits: false,
// TODO: any more defaults we should add here?
old_files_exclusions: [r".*/\.git/.*", r".*/COMMIT_EDITMSG"]
.iter()
Expand Down

0 comments on commit 87e8be0

Please sign in to comment.