mirror of https://github.com/helix-editor/helix
Merge pull request #24 from piotrkwarcinski/helix-plugin-register-value
commit
ef4fe804b7
|
@ -1038,6 +1038,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
|
||||||
// Arity 1
|
// Arity 1
|
||||||
module.register_fn("editor->text", document_id_to_text);
|
module.register_fn("editor->text", document_id_to_text);
|
||||||
module.register_fn("editor-document->path", document_path);
|
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| {
|
module.register_fn("set-editor-clip-right!", |cx: &mut Context, right: u16| {
|
||||||
cx.editor.editor_clipping.right = Some(right);
|
cx.editor.editor_clipping.right = Some(right);
|
||||||
|
@ -1095,31 +1096,57 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
|
||||||
template_function_arity_0("cx->cursor");
|
template_function_arity_0("cx->cursor");
|
||||||
template_function_arity_0("editor-focused-buffer-area");
|
template_function_arity_0("editor-focused-buffer-area");
|
||||||
|
|
||||||
let mut template_function_arity_1 = |name: &str| {
|
let mut template_function_arity_1 = |name: &str, doc: &str| {
|
||||||
builtin_editor_command_module.push_str(&format!(
|
if generate_sources {
|
||||||
r#"
|
let docstring = format_docstring(doc);
|
||||||
|
builtin_editor_command_module.push_str(&format!(
|
||||||
|
r#"
|
||||||
(provide {})
|
(provide {})
|
||||||
|
;;@doc
|
||||||
|
{}
|
||||||
(define ({} arg)
|
(define ({} arg)
|
||||||
(helix.{} *helix.cx* arg))
|
(helix.{} *helix.cx* arg))
|
||||||
"#,
|
"#,
|
||||||
name, name, name
|
name, docstring, name, name
|
||||||
));
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template_function_arity_1("editor->doc-id");
|
template_function_arity_1("editor->doc-id", "Get the document from a given view.");
|
||||||
template_function_arity_1("editor-switch!");
|
template_function_arity_1("editor-switch!", "Open the document in a vertical split.");
|
||||||
template_function_arity_1("editor-set-focus!");
|
template_function_arity_1("editor-set-focus!", "Set focus on the view.");
|
||||||
template_function_arity_1("editor-set-mode!");
|
template_function_arity_1("editor-set-mode!", "Set the editor mode.");
|
||||||
template_function_arity_1("editor-doc-in-view?");
|
template_function_arity_1(
|
||||||
template_function_arity_1("set-scratch-buffer-name!");
|
"editor-doc-in-view?",
|
||||||
template_function_arity_1("editor-doc-exists?");
|
"Check whether the current view contains a document.",
|
||||||
template_function_arity_1("editor->text");
|
);
|
||||||
template_function_arity_1("editor-document->path");
|
template_function_arity_1(
|
||||||
|
"set-scratch-buffer-name!",
|
||||||
template_function_arity_1("set-editor-clip-top!");
|
"Set the name of a scratch buffer.",
|
||||||
template_function_arity_1("set-editor-clip-right!");
|
);
|
||||||
template_function_arity_1("set-editor-clip-left!");
|
template_function_arity_1("editor-doc-exists?", "Check if a document exists.");
|
||||||
template_function_arity_1("set-editor-clip-bottom!");
|
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(
|
||||||
|
"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| {
|
let mut template_function_arity_2 = |name: &str| {
|
||||||
builtin_editor_command_module.push_str(&format!(
|
builtin_editor_command_module.push_str(&format!(
|
||||||
|
@ -3106,6 +3133,16 @@ fn cx_is_document_in_view(cx: &mut Context, doc_id: DocumentId) -> Option<helix_
|
||||||
.map(|(id, _)| id)
|
.map(|(id, _)| id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cx_register_value(cx: &mut Context, name: char) -> Vec<String> {
|
||||||
|
cx.editor
|
||||||
|
.registers
|
||||||
|
.read(name, cx.editor)
|
||||||
|
.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 {
|
fn cx_document_exists(cx: &mut Context, doc_id: DocumentId) -> bool {
|
||||||
cx.editor.documents.get(&doc_id).is_some()
|
cx.editor.documents.get(&doc_id).is_some()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue