on master help sign in
Add :get-option command (#2231)
15db603Daniel
book/src/generated/typable-cmd.md+2−1
@@ -55,7 +55,8 @@
55| `:tutor` | Open the tutorial. |
55| `:tutor` | Open the tutorial. |
56| `:goto`, `:g` | Go to line number. |
56| `:goto`, `:g` | Go to line number. |
57| `:set-language`, `:lang` | Set the language of current buffer. |
57| `:set-language`, `:lang` | Set the language of current buffer. |
58−| `:set-option`, `:set` | Set a config option at runtime |
58+| `:set-option`, `:set` | Set a config option at runtime. |
59+| `:get-option`, `:get` | Get the current value of a config option. |
59| `:sort` | Sort ranges in selection. |
60| `:sort` | Sort ranges in selection. |
60| `:rsort` | Sort ranges in selection in reverse order. |
61| `:rsort` | Sort ranges in selection in reverse order. |
61| `:tree-sitter-subtree`, `:ts-subtree` | Display tree sitter subtree under cursor, primarily for debugging queries. |
62| `:tree-sitter-subtree`, `:ts-subtree` | Display tree sitter subtree under cursor, primarily for debugging queries. |
helix-term/src/commands/typed.rs+31−3
@@ -928,9 +928,30 @@ pub(super) fn goto_line_number(
928 Ok(())
928 Ok(())
929}
929}
930
930
931+// Fetch the current value of a config option and output as status.
932+fn get_option(
933+ cx: &mut compositor::Context,
934+ args: &[Cow<str>],
935+ _event: PromptEvent,
936+) -> anyhow::Result<()> {
937+ if args.len() != 1 {
938+ anyhow::bail!("Bad arguments. Usage: `:get key`");
939+ }
940+
941+ let key = &args[0].to_lowercase();
942+ let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
943+
944+ let config = serde_json::to_value(&cx.editor.config().clone()).unwrap();
945+ let pointer = format!("/{}", key.replace('.', "/"));
946+ let value = config.pointer(&pointer).ok_or_else(key_error)?;
947+
948+ cx.editor.set_status(value.to_string());
949+ Ok(())
950+}
951+
931/// Change config at runtime. Access nested values by dot syntax, for
952/// Change config at runtime. Access nested values by dot syntax, for
932/// example to disable smart case search, use `:set search.smart-case false`.
953/// example to disable smart case search, use `:set search.smart-case false`.
933−fn setting(
954+fn set_option(
934 cx: &mut compositor::Context,
955 cx: &mut compositor::Context,
935 args: &[Cow<str>],
956 args: &[Cow<str>],
936 _event: PromptEvent,
957 _event: PromptEvent,
@@ -1487,8 +1508,15 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1487 TypableCommand {
1508 TypableCommand {
1488 name: "set-option",
1509 name: "set-option",
1489 aliases: &["set"],
1510 aliases: &["set"],
1490− doc: "Set a config option at runtime",
1511+ doc: "Set a config option at runtime.",
1491− fun: setting,
1512+ fun: set_option,
1513+ completer: Some(completers::setting),
1514+ },
1515+ TypableCommand {
1516+ name: "get-option",
1517+ aliases: &["get"],
1518+ doc: "Get the current value of a config option.",
1519+ fun: get_option,
1492 completer: Some(completers::setting),
1520 completer: Some(completers::setting),
1493 },
1521 },
1494 TypableCommand {
1522 TypableCommand {