update to use safer APIs

pull/8675/merge^2
mattwparas 1 year ago
parent 4213328ebd
commit c7687806a4

96
Cargo.lock generated

@ -34,8 +34,8 @@ dependencies = [
"abi_stable_shared", "abi_stable_shared",
"as_derive_utils", "as_derive_utils",
"core_extensions", "core_extensions",
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"rustc_version", "rustc_version",
"syn 1.0.109", "syn 1.0.109",
"typed-arena", "typed-arena",
@ -131,8 +131,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff3c96645900a44cf11941c111bd08a6573b0e2f9f69bc9264b179d8fae753c4" checksum = "ff3c96645900a44cf11941c111bd08a6573b0e2f9f69bc9264b179d8fae753c4"
dependencies = [ dependencies = [
"core_extensions", "core_extensions",
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -521,10 +521,10 @@ dependencies = [
"cc", "cc",
"codespan-reporting", "codespan-reporting",
"once_cell", "once_cell",
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"scratch", "scratch",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -539,9 +539,9 @@ version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -778,9 +778,9 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -1964,8 +1964,8 @@ checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
dependencies = [ dependencies = [
"beef", "beef",
"fnv", "fnv",
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"regex-syntax 0.6.29", "regex-syntax 0.6.29",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -2173,9 +2173,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.56" version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -2227,11 +2227,11 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.26" version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
] ]
[[package]] [[package]]
@ -2458,9 +2458,9 @@ version = "1.0.160"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -2480,9 +2480,9 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -2645,6 +2645,7 @@ dependencies = [
"serde_json", "serde_json",
"slotmap", "slotmap",
"smallvec", "smallvec",
"steel-derive",
"steel-gen", "steel-gen",
"steel-parser", "steel-parser",
"termimad", "termimad",
@ -2654,6 +2655,15 @@ dependencies = [
"which", "which",
] ]
[[package]]
name = "steel-derive"
version = "0.2.0"
dependencies = [
"proc-macro2 1.0.60",
"quote 1.0.28",
"syn 2.0.18",
]
[[package]] [[package]]
name = "steel-gen" name = "steel-gen"
version = "0.2.0" version = "0.2.0"
@ -2702,19 +2712,19 @@ version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.15" version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"unicode-ident", "unicode-ident",
] ]
@ -2789,9 +2799,9 @@ version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -2893,9 +2903,9 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 2.0.15", "syn 2.0.18",
] ]
[[package]] [[package]]
@ -3133,8 +3143,8 @@ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell", "once_cell",
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 1.0.109", "syn 1.0.109",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3145,7 +3155,7 @@ version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
dependencies = [ dependencies = [
"quote 1.0.26", "quote 1.0.28",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
@ -3155,8 +3165,8 @@ version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.60",
"quote 1.0.26", "quote 1.0.28",
"syn 1.0.109", "syn 1.0.109",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",

@ -48,7 +48,7 @@ chrono = { version = "0.4", default-features = false, features = ["alloc", "std"
etcetera = "0.7" etcetera = "0.7"
textwrap = "0.16.0" textwrap = "0.16.0"
steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests", "dylibs"] } steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests"] }
[dev-dependencies] [dev-dependencies]

@ -1,7 +1,12 @@
use steel::gc::unsafe_erased_pointers::CustomReference;
impl steel::rvals::Custom for crate::Position {} impl steel::rvals::Custom for crate::Position {}
struct SRopeSlice<'a>(crate::RopeSlice<'a>); struct SRopeSlice<'a>(crate::RopeSlice<'a>);
steel::custom_reference!(SRopeSlice<'a>);
impl<'a> CustomReference for SRopeSlice<'a> {}
impl<'a> SRopeSlice<'a> { impl<'a> SRopeSlice<'a> {
pub fn char_to_byte(&self, pos: usize) -> usize { pub fn char_to_byte(&self, pos: usize) -> usize {
self.0.char_to_byte(pos) self.0.char_to_byte(pos)

@ -67,7 +67,7 @@ grep-regex = "0.1.11"
grep-searcher = "0.1.11" grep-searcher = "0.1.11"
# plugin support # plugin support
steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests", "dylibs"] } steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests"] }
dlopen = "0.1.8" dlopen = "0.1.8"
dlopen_derive = "0.1.4" dlopen_derive = "0.1.4"

@ -54,6 +54,7 @@ use movement::Movement;
use crate::{ use crate::{
args, args,
commands::engine::CallbackQueue,
compositor::{self, Component, Compositor}, compositor::{self, Component, Compositor},
filter_picker_entry, filter_picker_entry,
job::Callback, job::Callback,
@ -189,6 +190,29 @@ macro_rules! static_commands {
impl MappableCommand { impl MappableCommand {
pub fn execute(&self, cx: &mut Context) { pub fn execute(&self, cx: &mut Context) {
log::info!("Running command");
// TODO: Move this out to a standalone function
while let Some(callback) = CallbackQueue::dequeue() {
log::info!("Found callback: {}", callback);
if let Err(e) = ENGINE.with(|x| {
let mut guard = x.borrow_mut();
{
let res = guard.run_with_reference::<Context, Context>(
cx,
"*context*",
&format!("({} *context*)", callback),
);
res
}
}) {
cx.editor.set_error(format!("{}", e));
}
}
match &self { match &self {
// TODO: @Matt - Add delegating to the engine to run scripts here // TODO: @Matt - Add delegating to the engine to run scripts here
Self::Typable { name, args, doc: _ } => { Self::Typable { name, args, doc: _ } => {

@ -165,6 +165,10 @@ pub fn run_initialization_script(cx: &mut Context) {
pub static KEYBINDING_QUEUE: Lazy<SharedKeyBindingsEventQueue> = pub static KEYBINDING_QUEUE: Lazy<SharedKeyBindingsEventQueue> =
Lazy::new(|| SharedKeyBindingsEventQueue::new()); Lazy::new(|| SharedKeyBindingsEventQueue::new());
// pub static CALLBACK_QUEUE: Lazy<CallBackQueue> = Lazy::new(|| )
pub static CALLBACK_QUEUE: Lazy<CallbackQueue> = Lazy::new(|| CallbackQueue::new());
pub static EXPORTED_IDENTIFIERS: Lazy<ExportedIdentifiers> = pub static EXPORTED_IDENTIFIERS: Lazy<ExportedIdentifiers> =
Lazy::new(|| ExportedIdentifiers::default()); Lazy::new(|| ExportedIdentifiers::default());
@ -207,6 +211,27 @@ impl Item for SteelVal {
} }
} }
pub struct CallbackQueue {
queue: Arc<Mutex<VecDeque<String>>>,
}
impl CallbackQueue {
pub fn new() -> Self {
Self {
queue: Arc::new(Mutex::new(VecDeque::new())),
}
}
pub fn enqueue(value: String) {
CALLBACK_QUEUE.queue.lock().unwrap().push_back(value);
}
// Dequeue should probably be a R/W lock?
pub fn dequeue() -> Option<String> {
CALLBACK_QUEUE.queue.lock().unwrap().pop_front()
}
}
/// In order to send events from the engine back to the configuration, we can created a shared /// In order to send events from the engine back to the configuration, we can created a shared
/// queue that the engine and the config push and pull from. Alternatively, we could use a channel /// queue that the engine and the config push and pull from. Alternatively, we could use a channel
/// directly, however this was easy enough to set up. /// directly, however this was easy enough to set up.
@ -252,6 +277,8 @@ impl Custom for PromptEvent {}
impl<'a> CustomReference for Context<'a> {} impl<'a> CustomReference for Context<'a> {}
steel::custom_reference!(Context<'a>);
fn get_editor<'a>(cx: &'a mut Context<'a>) -> &'a mut Editor { fn get_editor<'a>(cx: &'a mut Context<'a>) -> &'a mut Editor {
cx.editor cx.editor
} }
@ -389,6 +416,8 @@ fn configure_engine() -> std::rc::Rc<std::cell::RefCell<steel::steel_vm::engine:
// .to_string(), // .to_string(),
// ); // );
engine.register_fn("enqueue-callback!", CallbackQueue::enqueue);
// Get the current OS // Get the current OS
engine.register_fn("current-os!", || std::env::consts::OS); engine.register_fn("current-os!", || std::env::consts::OS);
engine.register_fn("new-component!", SteelDynamicComponent::new_dyn); engine.register_fn("new-component!", SteelDynamicComponent::new_dyn);
@ -655,6 +684,20 @@ fn configure_engine() -> std::rc::Rc<std::cell::RefCell<steel::steel_vm::engine:
let mut module = BuiltInModule::new("helix/core/static".to_string()); let mut module = BuiltInModule::new("helix/core/static".to_string());
for command in TYPABLE_COMMAND_LIST {
let func = |cx: &mut Context| {
let mut cx = compositor::Context {
editor: cx.editor,
scroll: None,
jobs: cx.jobs,
};
(command.fun)(&mut cx, &[], PromptEvent::Validate)
};
module.register_fn(command.name, func);
}
// Register everything in the static command list as well // Register everything in the static command list as well
// These just accept the context, no arguments // These just accept the context, no arguments
for command in MappableCommand::STATIC_COMMAND_LIST { for command in MappableCommand::STATIC_COMMAND_LIST {

@ -26,4 +26,4 @@ once_cell = "1.17"
log = "~0.4" log = "~0.4"
helix-view = { version = "0.6", path = "../helix-view", features = ["term"] } helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
helix-core = { version = "0.6", path = "../helix-core" } helix-core = { version = "0.6", path = "../helix-core" }
steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests", "dylibs"] } steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests"] }

@ -3,3 +3,5 @@ use crate::{buffer::Buffer, widgets::Widget};
use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom}; use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom};
impl CustomReference for Buffer {} impl CustomReference for Buffer {}
steel::custom_reference!(Buffer);

@ -46,7 +46,7 @@ which = "4.4"
parking_lot = "0.12.1" parking_lot = "0.12.1"
# plugin support # plugin support
steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests", "dylibs"] } steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow", "blocking_requests"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]

@ -2,70 +2,71 @@
(require-builtin helix/core/static as helix.static.) (require-builtin helix/core/static as helix.static.)
(require-builtin helix/core/keybindings as helix.keybindings.) (require-builtin helix/core/keybindings as helix.keybindings.)
(provide set-theme-dracula
(provide set-theme-dracula__doc__
set-theme-dracula set-theme-custom
set-theme-dracula__doc__ set-theme-custom__doc__
set-theme-custom theme-then-vsplit
set-theme-custom__doc__ theme-then-vsplit__doc__
theme-then-vsplit custom-undo
theme-then-vsplit__doc__ custom-undo__doc__
custom-undo lam
custom-undo__doc__ lam__doc__
lam delete-word-forward
lam__doc__ insert-string-at-selection
delete-word-forward highlight-to-matching-paren
insert-string-at-selection highlight-to-matching-paren__doc__
highlight-to-matching-paren delete-sexpr
highlight-to-matching-paren__doc__ delete-sexpr__doc__
delete-sexpr run-expr
delete-sexpr__doc__ run-highlight
run-expr make-minor-mode!
run-highlight git-status
make-minor-mode!
git-status reload-helix-scm
reload-helix-scm) static-format)
;;@doc ;;@doc
;; Sets the theme to be the dracula theme ;; Sets the theme to be the dracula theme
(define (set-theme-dracula cx) (define (set-theme-dracula cx)
(helix.theme cx (list "dracula") helix.PromptEvent::Validate)) (helix.theme cx (list "dracula") helix.PromptEvent::Validate))
(enqueue-callback! 'helix.static.format)
(enqueue-callback! 'set-theme-dracula)
;;@doc ;;@doc
;; Sets the theme to be the theme passed in ;; Sets the theme to be the theme passed in
(define (set-theme-custom cx entered-theme) (define (set-theme-custom cx entered-theme)
(helix.theme cx (list entered-theme) helix.PromptEvent::Validate)) (helix.theme cx (list entered-theme) helix.PromptEvent::Validate))
;;@doc ;;@doc
;; Switch theme to the entered theme, then split the current file into ;; Switch theme to the entered theme, then split the current file into
;; a vsplit ;; a vsplit
(define (theme-then-vsplit cx entered-theme) (define (theme-then-vsplit cx entered-theme)
(set-theme-custom cx entered-theme) (set-theme-custom cx entered-theme)
(helix.vsplit cx '() helix.PromptEvent::Validate)) (helix.vsplit cx '() helix.PromptEvent::Validate))
;;@doc ;;@doc
;; Perform an undo ;; Perform an undo
(define (custom-undo cx) (define (custom-undo cx)
(helix.static.undo cx)) (helix.static.undo cx))
;;@doc ;;@doc
;; Insert a lambda ;; Insert a lambda
(define (lam cx) (define (lam cx)
(helix.static.insert_char cx #\λ) (helix.static.insert_char cx #\λ)
(helix.static.insert_mode cx)) (helix.static.insert_mode cx))
;;@doc ;;@doc
;; Insert the string at the selection and go back into insert mode ;; Insert the string at the selection and go back into insert mode
(define (insert-string-at-selection cx str) (define (insert-string-at-selection cx str)
(helix.static.insert_string cx str) (helix.static.insert_string cx str)
(helix.static.insert_mode cx)) (helix.static.insert_mode cx))
;;@doc ;;@doc
;; Delete the word forward ;; Delete the word forward
(define (delete-word-forward cx) (define (delete-word-forward cx)
(helix.static.delete_word_forward cx)) (helix.static.delete_word_forward cx))
;;@doc ;;@doc
;; Registers a minor mode with the registered modifer and key map ;; Registers a minor mode with the registered modifer and key map
@ -76,102 +77,84 @@
;; (hash "P" ":lam")) ;; (hash "P" ":lam"))
;; ``` ;; ```
(define (make-minor-mode! modifier bindings) (define (make-minor-mode! modifier bindings)
(~> (hash "normal" (hash modifier bindings)) (~> (hash "normal" (hash modifier bindings))
(value->jsexpr-string) (value->jsexpr-string)
(helix.keybindings.set-keybindings!))) (helix.keybindings.set-keybindings!)))
(define-syntax minor-mode! (define-syntax minor-mode!
(syntax-rules (=>) (syntax-rules (=>)
[(minor-mode! modifier (key => function)) [(minor-mode! modifier (key => function))
(make-minor-mode! modifier (minor-mode-cruncher (key => function)))] (make-minor-mode! modifier (minor-mode-cruncher (key => function)))]
[(minor-mode! modifier (key => (function ...)))
(make-minor-mode! modifier (minor-mode-cruncher (key => (function ...))))]
[(minor-mode! modifier (key => function) remaining ...) [(minor-mode! modifier (key => (function ...)))
(make-minor-mode! modifier (minor-mode-cruncher (key => function) remaining ...))] (make-minor-mode! modifier (minor-mode-cruncher (key => (function ...))))]
[(minor-mode! modifier (key => (function ...)) remaining ...) [(minor-mode! modifier (key => function) remaining ...)
(make-minor-mode! modifier (minor-mode-cruncher (key => function) ... remaining ...))] (make-minor-mode! modifier (minor-mode-cruncher (key => function) remaining ...))]
[(minor-mode! modifier (key => (function ...)) remaining ...)
(make-minor-mode! modifier (minor-mode-cruncher (key => function) ... remaining ...))]))
))
(define-syntax minor-mode-cruncher (define-syntax minor-mode-cruncher
(syntax-rules (=>) (syntax-rules (=>)
[(minor-mode-cruncher (key => (function ...)))
(hash key (map (lambda (x)
(string-append ":" (symbol->string x)))
(quote (function ...))))]
[(minor-mode-cruncher (key => function)) [(minor-mode-cruncher (key => (function ...)))
(hash key (string-append ":" (symbol->string (quote function))))] (hash key (map (lambda (x) (string-append ":" (symbol->string x))) (quote (function ...))))]
[(minor-mode-cruncher (key => (function ...)) remaining ...) [(minor-mode-cruncher (key => function))
(hash-insert (hash key (string-append ":" (symbol->string (quote function))))]
(minor-mode-cruncher remaining ...)
key (map (lambda (x)
(string-append ":" (symbol->string x)))
(quote (function ...))))]
[(minor-mode-cruncher (key => function) remaining ...) [(minor-mode-cruncher (key => (function ...)) remaining ...)
(hash-insert (hash-insert (minor-mode-cruncher remaining ...)
(minor-mode-cruncher remaining ...) key
key (map (lambda (x) (string-append ":" (symbol->string x))) (quote (function ...))))]
(string-append ":" (symbol->string (quote function))))]
[(minor-mode-cruncher (key => function) remaining ...)
(hash-insert (minor-mode-cruncher remaining ...)
)) key
(string-append ":" (symbol->string (quote function))))]))
;;@doc ;;@doc
;; Highlight to the matching paren ;; Highlight to the matching paren
(define (highlight-to-matching-paren cx) (define (highlight-to-matching-paren cx)
(helix.static.select_mode cx) (helix.static.select_mode cx)
(helix.static.match_brackets cx)) (helix.static.match_brackets cx))
(define (run-expr cx) (define (run-expr cx)
(define current-selection (helix.static.current_selection cx)) (define current-selection (helix.static.current_selection cx))
(when (or (equal? "(" current-selection) (when (or (equal? "(" current-selection) (equal? ")" current-selection))
(equal? ")" current-selection)) (highlight-to-matching-paren cx)
(highlight-to-matching-paren cx) (helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx))
(helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx)) (helix.static.normal_mode cx)))
(helix.static.normal_mode cx)))
(define (run-highlight cx) (define (run-highlight cx)
(helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx))) (helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx)))
;;@doc ;;@doc
;; Delete the s-expression matching this bracket ;; Delete the s-expression matching this bracket
;; If the current selection is not on a bracket, this is a no-op ;; If the current selection is not on a bracket, this is a no-op
(define (delete-sexpr cx) (define (delete-sexpr cx)
(define current-selection (helix.static.current_selection cx)) (define current-selection (helix.static.current_selection cx))
(when (or (equal? "(" current-selection) (when (or (equal? "(" current-selection) (equal? ")" current-selection))
(equal? ")" current-selection)) (highlight-to-matching-paren cx)
(highlight-to-matching-paren cx) (helix.static.delete_selection cx)))
(helix.static.delete_selection cx)))
; (minor-mode! "+" ("l" => lam) ; (minor-mode! "+" ("l" => lam)
; ("q" => (set-theme-dracula lam))) ; ("q" => (set-theme-dracula lam)))
(minor-mode! "P" ("l" => lam) (minor-mode! "P"
("p" => highlight-to-matching-paren) ("l" => lam)
("d" => delete-sexpr) ("p" => highlight-to-matching-paren)
("r" => run-expr)) ("d" => delete-sexpr)
("r" => run-expr))
(make-minor-mode! "+" (hash "l" ":lam")) (make-minor-mode! "+" (hash "l" ":lam"))
(define (git-status cx) (define (git-status cx)
(helix.run-shell-command cx '("git" "status") helix.PromptEvent::Validate)) (helix.run-shell-command cx '("git" "status") helix.PromptEvent::Validate))
(minor-mode! "G" ("s" => git-status)) (minor-mode! "G" ("s" => git-status))
(define (reload-helix-scm cx) (define (reload-helix-scm cx)
(helix.static.run-in-engine! cx (helix.static.run-in-engine! cx
(string-append "(require \"" (helix.static.get-helix.scm-path) "\")"))) (string-append "(require \"" (helix.static.get-helix.scm-path) "\")")))

Loading…
Cancel
Save