From 63086eecf7c92c5e5619b34110b28de167a715c9 Mon Sep 17 00:00:00 2001 From: piotrkwarcinski Date: Sun, 4 May 2025 22:27:25 +0200 Subject: [PATCH 1/5] feat: allow to get a register value from scheme --- helix-term/src/commands/engine/steel.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index c0469e40f..5f9f085be 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -1035,6 +1035,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { // Arity 1 module.register_fn("editor->text", document_id_to_text); module.register_fn("editor-document->path", document_path); + module.register_fn("register->value", cx_register_value); module.register_fn("set-editor-clip-right!", |cx: &mut Context, right: u16| { cx.editor.editor_clipping.right = Some(right); @@ -1112,6 +1113,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { template_function_arity_1("editor-doc-exists?"); template_function_arity_1("editor->text"); template_function_arity_1("editor-document->path"); + template_function_arity_1("register->value"); template_function_arity_1("set-editor-clip-top!"); template_function_arity_1("set-editor-clip-right!"); @@ -3069,6 +3071,15 @@ fn cx_is_document_in_view(cx: &mut Context, doc_id: DocumentId) -> Option Vec { + let items = cx + .editor + .registers + .read(name, cx.editor) + .map_or(Vec::new(), |reg| reg.collect()); + items.into_iter().map(|value| value.to_string()).collect() +} + fn cx_document_exists(cx: &mut Context, doc_id: DocumentId) -> bool { cx.editor.documents.get(&doc_id).is_some() } From edcb630075dc144af45ae86e39caeba5f46346b8 Mon Sep 17 00:00:00 2001 From: piotrkwarcinski Date: Sat, 10 May 2025 14:49:04 +0200 Subject: [PATCH 2/5] cleanup --- helix-term/src/commands/engine/steel.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 5f9f085be..5a885fd8b 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -3072,12 +3072,13 @@ fn cx_is_document_in_view(cx: &mut Context, doc_id: DocumentId) -> Option Vec { - let items = cx - .editor + cx.editor .registers .read(name, cx.editor) - .map_or(Vec::new(), |reg| reg.collect()); - items.into_iter().map(|value| value.to_string()).collect() + .map_or(Vec::new(), |reg| reg.collect()) + .into_iter() + .map(|value| value.to_string()) + .collect() } fn cx_document_exists(cx: &mut Context, doc_id: DocumentId) -> bool { From d9ec722a77383ddee7375388d4f4503ee698b0ef Mon Sep 17 00:00:00 2001 From: piotrkwarcinski Date: Sun, 11 May 2025 22:58:35 +0200 Subject: [PATCH 3/5] Add documentation --- helix-term/src/commands/engine/steel.rs | 60 ++++++++++++++++--------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index efebb23bd..5fcfd0ba7 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -1096,32 +1096,52 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { template_function_arity_0("cx->cursor"); template_function_arity_0("editor-focused-buffer-area"); - let mut template_function_arity_1 = |name: &str| { - builtin_editor_command_module.push_str(&format!( - r#" + let mut template_function_arity_1 = |name: &str, doc: &str| { + if generate_sources { + let docstring = format_docstring(doc); + builtin_editor_command_module.push_str(&format!( + r#" (provide {}) +;;@doc +{} (define ({} arg) (helix.{} *helix.cx* arg)) -"#, - name, name, name - )); + "#, + name, docstring, name, name + )); + } }; - template_function_arity_1("editor->doc-id"); - template_function_arity_1("editor-switch!"); - template_function_arity_1("editor-set-focus!"); - template_function_arity_1("editor-set-mode!"); - template_function_arity_1("editor-doc-in-view?"); - template_function_arity_1("set-scratch-buffer-name!"); - template_function_arity_1("editor-doc-exists?"); - template_function_arity_1("editor->text"); - template_function_arity_1("editor-document->path"); - template_function_arity_1("register->value"); + template_function_arity_1("editor->doc-id", "Get the document from a given view"); + template_function_arity_1("editor-switch!", "Open the document in a vertical split"); + template_function_arity_1("editor-set-focus!", "Set focus on the view"); + template_function_arity_1("editor-set-mode!", "Set the editor mode"); + template_function_arity_1( + "editor-doc-in-view?", + "Check whether the current view contains a document", + ); + template_function_arity_1( + "set-scratch-buffer-name!", + "Set the name of a scratch buffer", + ); + template_function_arity_1("editor-doc-exists?", "Check if a document exists"); + template_function_arity_1("editor->text", "Get the document text as a rope"); + template_function_arity_1("editor-document->path", "Get the path to a document"); + template_function_arity_1("register->value", "Get register value as a list of strings"); - template_function_arity_1("set-editor-clip-top!"); - template_function_arity_1("set-editor-clip-right!"); - template_function_arity_1("set-editor-clip-left!"); - template_function_arity_1("set-editor-clip-bottom!"); + template_function_arity_1("set-editor-clip-top!", "Set the editor clipping at the top"); + template_function_arity_1( + "set-editor-clip-right!", + "Set the editor clipping at the right", + ); + template_function_arity_1( + "set-editor-clip-left!", + "Set the editor clipping at the left", + ); + template_function_arity_1( + "set-editor-clip-bottom!", + "Set the editor clipping at the bottom", + ); let mut template_function_arity_2 = |name: &str| { builtin_editor_command_module.push_str(&format!( From ec53eb429a024c651db0aaf71c50b6fd5a87bbf4 Mon Sep 17 00:00:00 2001 From: piotrkwarcinski Date: Sun, 11 May 2025 23:05:21 +0200 Subject: [PATCH 4/5] dots --- helix-term/src/commands/engine/steel.rs | 35 ++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 5fcfd0ba7..66d60c86a 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -1112,35 +1112,40 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { } }; - template_function_arity_1("editor->doc-id", "Get the document from a given view"); - template_function_arity_1("editor-switch!", "Open the document in a vertical split"); - template_function_arity_1("editor-set-focus!", "Set focus on the view"); - template_function_arity_1("editor-set-mode!", "Set the editor mode"); + template_function_arity_1("editor->doc-id", "Get the document from a given view."); + template_function_arity_1("editor-switch!", "Open the document in a vertical split."); + template_function_arity_1("editor-set-focus!", "Set focus on the view."); + template_function_arity_1("editor-set-mode!", "Set the editor mode."); template_function_arity_1( "editor-doc-in-view?", - "Check whether the current view contains a document", + "Check whether the current view contains a document.", ); template_function_arity_1( "set-scratch-buffer-name!", - "Set the name of a scratch buffer", + "Set the name of a scratch buffer.", + ); + template_function_arity_1("editor-doc-exists?", "Check if a document exists."); + template_function_arity_1("editor->text", "Get the document as a rope."); + template_function_arity_1("editor-document->path", "Get the path to a document."); + template_function_arity_1( + "register->value", + "Get register value as a list of strings.", + ); + template_function_arity_1( + "set-editor-clip-top!", + "Set the editor clipping at the top.", ); - template_function_arity_1("editor-doc-exists?", "Check if a document exists"); - template_function_arity_1("editor->text", "Get the document text as a rope"); - template_function_arity_1("editor-document->path", "Get the path to a document"); - template_function_arity_1("register->value", "Get register value as a list of strings"); - - template_function_arity_1("set-editor-clip-top!", "Set the editor clipping at the top"); template_function_arity_1( "set-editor-clip-right!", - "Set the editor clipping at the right", + "Set the editor clipping at the right.", ); template_function_arity_1( "set-editor-clip-left!", - "Set the editor clipping at the left", + "Set the editor clipping at the left.", ); template_function_arity_1( "set-editor-clip-bottom!", - "Set the editor clipping at the bottom", + "Set the editor clipping at the bottom.", ); let mut template_function_arity_2 = |name: &str| { From de2496d46b674412fb102a1af476ca82d16dd187 Mon Sep 17 00:00:00 2001 From: piotrkwarcinski Date: Sun, 11 May 2025 23:14:48 +0200 Subject: [PATCH 5/5] formatting --- helix-term/src/commands/engine/steel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 66d60c86a..4cd07b1d7 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -1106,7 +1106,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { {} (define ({} arg) (helix.{} *helix.cx* arg)) - "#, +"#, name, docstring, name, name )); }