diff options
author | Joe | 2022-03-25 09:05:20 +0000 |
---|---|---|
committer | GitHub | 2022-03-25 09:05:20 +0000 |
commit | bee05dd32a685b58015514492525673b1b568b0d (patch) | |
tree | 4d141ece2ff029b881013f7ef4e89bfb9b064919 /helix-term/src/commands | |
parent | 309f2c2c8e64f8be2123a0232c5f9761496b6514 (diff) |
Add refresh-config and open-config command (#1803)
* Add refresh-config and open-config command
* clippy
* Use dynamic dispatch for editor config
* Refactor Result::Ok to Ok
* Remove unused import
* cargo fmt
* Modify config error handling
* cargo xtask docgen
* impl display for ConfigLoadError
* cargo fmt
* Put keymaps behind dyn access, refactor config.load()
* Update command names
* Update helix-term/src/application.rs
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
* Switch to unbounded_channel
* Remove --edit-config command
* Update configuration docs
* Revert "Put keymaps behind dyn access", too hard
This reverts commit 06bad8cf492b9331d0a2d1e9242f3ad4e2c1cf79.
* Add refresh for keys
* Refactor default_keymaps, fix config default, add test
* swap -> store, remove unneeded clone
* cargo fmt
* Rename default_keymaps to default
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/typed.rs | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d35b7082..8b7f481b 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1,6 +1,6 @@ use super::*; -use helix_view::editor::Action; +use helix_view::editor::{Action, ConfigEvent}; use ui::completers::{self, Completer}; #[derive(Clone)] @@ -540,7 +540,7 @@ fn theme( .theme_loader .load(theme) .with_context(|| format!("Failed setting theme {}", theme))?; - let true_color = cx.editor.config.true_color || crate::true_color(); + let true_color = cx.editor.config().true_color || crate::true_color(); if !(true_color || theme.is_16_color()) { bail!("Unsupported theme: theme requires true color support"); } @@ -894,7 +894,7 @@ fn setting( let key_error = || anyhow::anyhow!("Unknown key `{key}`"); let field_error = |_| anyhow::anyhow!("Could not parse field `{arg}`"); - let mut config = serde_json::to_value(&cx.editor.config).unwrap(); + let mut config = serde_json::to_value(&cx.editor.config().clone()).unwrap(); let pointer = format!("/{}", key.replace('.', "/")); let value = config.pointer_mut(&pointer).ok_or_else(key_error)?; @@ -904,8 +904,12 @@ fn setting( } else { arg.parse().map_err(field_error)? }; - cx.editor.config = serde_json::from_value(config).map_err(field_error)?; + let config = serde_json::from_value(config).map_err(field_error)?; + cx.editor + .config_events + .0 + .send(ConfigEvent::Update(config))?; Ok(()) } @@ -995,6 +999,25 @@ fn tree_sitter_subtree( Ok(()) } +fn open_config( + cx: &mut compositor::Context, + _args: &[Cow<str>], + _event: PromptEvent, +) -> anyhow::Result<()> { + cx.editor + .open(helix_loader::config_file(), Action::Replace)?; + Ok(()) +} + +fn refresh_config( + cx: &mut compositor::Context, + _args: &[Cow<str>], + _event: PromptEvent, +) -> anyhow::Result<()> { + cx.editor.config_events.0.send(ConfigEvent::Refresh)?; + Ok(()) +} + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -1381,6 +1404,20 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: tree_sitter_subtree, completer: None, }, + TypableCommand { + name: "config-reload", + aliases: &[], + doc: "Refreshes helix's config.", + fun: refresh_config, + completer: None, + }, + TypableCommand { + name: "config-open", + aliases: &[], + doc: "Open the helix config.toml file.", + fun: open_config, + completer: None, + }, ]; pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> = |