summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel2022-04-24 10:30:18 +0000
committerGitHub2022-04-24 10:30:18 +0000
commit15db6031bbbdf7a795c15050a551dee09e9d1248 (patch)
tree97d995a2e5fc8e86851f28d8ccdaa34101beb31f
parent3f2bd7770e9cdbb57c139ef950e2d63ccf8ac674 (diff)
Add :get-option command (#2231)
-rw-r--r--book/src/generated/typable-cmd.md3
-rw-r--r--helix-term/src/commands/typed.rs34
2 files changed, 33 insertions, 4 deletions
diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md
index 33f3b839..ee00e9ce 100644
--- a/book/src/generated/typable-cmd.md
+++ b/book/src/generated/typable-cmd.md
@@ -55,7 +55,8 @@
| `:tutor` | Open the tutorial. |
| `:goto`, `:g` | Go to line number. |
| `:set-language`, `:lang` | Set the language of current buffer. |
-| `:set-option`, `:set` | Set a config option at runtime |
+| `:set-option`, `:set` | Set a config option at runtime. |
+| `:get-option`, `:get` | Get the current value of a config option. |
| `:sort` | Sort ranges in selection. |
| `:rsort` | Sort ranges in selection in reverse order. |
| `:tree-sitter-subtree`, `:ts-subtree` | Display tree sitter subtree under cursor, primarily for debugging queries. |
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index d44bcf75..9ed78d1d 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -928,9 +928,30 @@ pub(super) fn goto_line_number(
Ok(())
}
+// Fetch the current value of a config option and output as status.
+fn get_option(
+ cx: &mut compositor::Context,
+ args: &[Cow<str>],
+ _event: PromptEvent,
+) -> 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::to_value(&cx.editor.config().clone()).unwrap();
+ let pointer = format!("/{}", key.replace('.', "/"));
+ let value = config.pointer(&pointer).ok_or_else(key_error)?;
+
+ cx.editor.set_status(value.to_string());
+ Ok(())
+}
+
/// Change config at runtime. Access nested values by dot syntax, for
/// example to disable smart case search, use `:set search.smart-case false`.
-fn setting(
+fn set_option(
cx: &mut compositor::Context,
args: &[Cow<str>],
_event: PromptEvent,
@@ -1487,8 +1508,15 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "set-option",
aliases: &["set"],
- doc: "Set a config option at runtime",
- fun: setting,
+ doc: "Set a config option at runtime.",
+ fun: set_option,
+ completer: Some(completers::setting),
+ },
+ TypableCommand {
+ name: "get-option",
+ aliases: &["get"],
+ doc: "Get the current value of a config option.",
+ fun: get_option,
completer: Some(completers::setting),
},
TypableCommand {