diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 1d11e288e..209fa0899 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -45,6 +45,7 @@ use std::{ borrow::Cow, collections::HashMap, error::Error, + io::Write, path::PathBuf, sync::{atomic::AtomicBool, Mutex, MutexGuard, RwLock, RwLockReadGuard}, time::{Duration, SystemTime}, @@ -1974,6 +1975,15 @@ impl super::PluginSystem for SteelScriptingEngine { } fn generate_sources(&self) { + fn format_markdown_doc(writer: &mut W, doc: &str) { + for line in doc.lines() { + if line.starts_with("# ") { + write!(writer, "###").unwrap(); + } + writeln!(writer, "{}", line).unwrap(); + } + } + // Generate sources directly with a fresh engine let mut engine = Engine::new(); configure_builtin_sources(&mut engine, true); @@ -1984,6 +1994,48 @@ impl super::PluginSystem for SteelScriptingEngine { // Generate markdown docs steel_doc::walk_dir(&mut writer, target, &mut engine).unwrap(); + + // Also generate docs for the built in modules + let module = engine.builtin_modules().get("helix/core/text").unwrap(); + + writeln!(&mut writer, "# helix/core/text").unwrap(); + writeln!( + &mut writer, + "To use, you can include with `(require-builtin helix/core/text)`" + ) + .unwrap(); + + let mut found_definitions = std::collections::HashSet::new(); + + let mut exported_functions: Vec<_> = module + .names() + .into_iter() + .filter(|name| !name.starts_with("#%")) + .collect(); + + exported_functions.sort(); + + for name in &exported_functions { + if let Some(value) = module.documentation().get(name) { + found_definitions.insert(name.to_string()); + + match value { + steel::steel_vm::builtin::Documentation::Markdown(m) => { + let escaped = name.replace("*", "\\*"); + writeln!(&mut writer, "### **{}**", escaped).unwrap(); + + format_markdown_doc(&mut writer, &m.0); + } + _ => {} + } + } + } + + for name in exported_functions { + if !found_definitions.contains(&name) { + writeln!(&mut writer, "### **{}**", name).unwrap(); + } + } } } diff --git a/steel-docs.md b/steel-docs.md index 06d12896a..76ccf2fc3 100644 --- a/steel-docs.md +++ b/steel-docs.md @@ -2732,3 +2732,110 @@ Check whether the given event is the key: keypad-begin (key-event-keypad-begin? event) ``` event: Event? +# helix/core/text +### **Rope?** +Check if the given value is a rope +### **rope->byte-slice** +Take a slice of this rope using byte offsets + +```scheme +(rope->byte-slice rope start end) -> Rope? +``` + +* rope: Rope? +* start: (and positive? int?) +* end: (and positive? int?) +### **rope->line** +Get the line at the given line index. Returns a rope. + +```scheme +(rope->line rope index) -> Rope? + +``` + +* rope : Rope? +* index : (and positive? int?) +### **rope->slice** +Take a slice from using character indices from the rope. +Returns a new rope value. + +```scheme +(rope->slice rope start end) -> Rope? +``` + +* rope : Rope? +* start: (and positive? int?) +* end: (and positive? int?) +### **rope->string** +Convert the given rope to a string +### **rope-byte->line** +Convert the given byte offset to a line offset for a given rope + +```scheme +(rope-byte->line rope byte-index) -> int? +``` + +* rope : Rope? +* byte-index : int? + + +### **rope-char->byte** +Convert the byte offset into a character offset for a given rope +### **rope-char->line** +Convert the given character offset to a line offset for a given rope + +```scheme +(rope-char->line rope char-index) -> int? +``` + +* rope : Rope? +* char-index : int? + + +### **rope-char-ref** +Get the character at the given index +### **rope-ends-with?** +Check if the rope ends with a given pattern +### **rope-insert-char** +Insert a character at the given index +### **rope-insert-string** +Insert a string at the given index into the rope +### **rope-len-bytes** +Get the length of the rope in bytes +### **rope-len-chars** +Get the length of the rope in characters +### **rope-len-lines** +Get the number of lines in the rope +### **rope-line->byte** +Convert the given line index to a byte offset for a given rope + +```scheme +(rope-line->byte rope line-offset) -> int? +``` + +* rope : Rope? +* line-offset: int? + +### **rope-line->char** +Convert the given line index to a character offset for a given rope + +```scheme +(rope-line->char rope line-offset) -> int? +``` + +* rope : Rope? +* line-offset: int? + +### **rope-starts-with?** +Check if the rope starts with a given pattern +### **rope-trim-start** +Remove the leading whitespace from the given rope +### **string->rope** +Converts a string into a rope. + +```scheme +(string->rope value) -> Rope? +``` + +* value : string? +