diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index ef1a7685769f..96f9fd97b9a1 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -509,6 +509,20 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) { engine.register_module(module); } +fn get_option_value(cx: &mut Context, args: Vec) -> anyhow::Result { + if args.len() != 1 { + anyhow::bail!("Bad arguments. Usage: `:get key`"); + } + + let key = &args[0].to_lowercase(); + let key_error = || anyhow::anyhow!("Unknown key `{}`", key); + + let config = serde_json::json!(std::ops::Deref::deref(&cx.editor.config())); + let pointer = format!("/{}", key.replace('.', "/")); + let value = config.pointer(&pointer).ok_or_else(key_error)?; + Ok(value.to_owned().into_steelval().unwrap()) +} + // File picker configurations fn fp_hidden(config: &mut FilePickerConfig, option: bool) { config.hidden = option; @@ -578,6 +592,8 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { .unwrap(); }); + module.register_fn("get-config-option-value", get_option_value); + module .register_fn("raw-file-picker", || FilePickerConfig::default()) .register_fn("register-file-picker", HelixConfiguration::file_picker) @@ -693,6 +709,14 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { "#, )); + builtin_configuration_module.push_str(&format!( + r#" +(provide get-config-option-value) +(define (get-config-option-value arg) + (helix.get-config-option-value *helix.cx*)) +"#, + )); + // Register the get keybindings function builtin_configuration_module.push_str(&format!( r#"