Skip to content

Commit

Permalink
add function to get a configuration value
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas committed Nov 30, 2024
1 parent 30749e3 commit a7cd2ff
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions helix-term/src/commands/engine/steel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> anyhow::Result<SteelVal> {
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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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#"
Expand Down

0 comments on commit a7cd2ff

Please sign in to comment.