diff --git a/Cargo.lock b/Cargo.lock index def244c8a..9ebe89ecd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2053,6 +2053,41 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-complex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +dependencies = [ + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -2063,6 +2098,29 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -2636,6 +2694,7 @@ dependencies = [ "lazy_static", "log", "logos", + "num", "once_cell", "pretty", "quickscope", @@ -2679,6 +2738,7 @@ name = "steel-parser" version = "0.2.0" dependencies = [ "logos", + "num-bigint", "serde", "serde_derive", ] diff --git a/helix-core/src/extensions.rs b/helix-core/src/extensions.rs index aa6dc227f..bf2fbdec0 100644 --- a/helix-core/src/extensions.rs +++ b/helix-core/src/extensions.rs @@ -1,6 +1,7 @@ use steel::gc::unsafe_erased_pointers::CustomReference; impl steel::rvals::Custom for crate::Position {} +impl steel::rvals::Custom for crate::Selection {} struct SRopeSlice<'a>(crate::RopeSlice<'a>); diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 2ee154402..97993bf75 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -858,9 +858,13 @@ fn call_indent_hook( } // TODO: Don't unwrap here, we don't want that - if LISP_WORDS.contains( - line.slice(offset..offset + end).as_str().unwrap(), - ) { + // if LISP_WORDS.contains( + // line.slice(offset..offset + end).as_str().unwrap(), + // ) { + // return Some(" ".repeat(offset + 1)); + // } + + if line.slice(offset..offset + end).as_str().map(|x| LISP_WORDS.contains(x)).unwrap_or_default() { return Some(" ".repeat(offset + 1)); } @@ -1023,6 +1027,10 @@ pub fn custom_indent_for_newline( return Some(" ".repeat(offset + 1)); } + // if line.slice(offset..offset + end).as_str().map(|x| LISP_WORDS.contains(x)).unwrap_or_default() { + // return Some(" ".repeat(offset + 1)); + // } + for _ in char_iter_from_paren .take_while(|(_, x)| x.is_whitespace()) { diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index e8c69deb6..2d92096dc 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -1,6 +1,6 @@ use fuzzy_matcher::FuzzyMatcher; -use helix_core::{graphemes, Tendril}; -use helix_view::{document::Mode, Document, DocumentId, Editor}; +use helix_core::{graphemes, Tendril, Selection}; +use helix_view::{document::Mode, Document, DocumentId, Editor, editor::Action}; use once_cell::sync::Lazy; use steel::{ gc::unsafe_erased_pointers::CustomReference, @@ -556,6 +556,12 @@ fn configure_engine() -> std::rc::Rcdoc-id", get_document_id); + engine.register_fn("editor-switch!", switch); + engine.register_fn("editor-set-focus!", Editor::focus); + engine.register_fn("editor-mode", editor_get_mode); + engine.register_fn("editor-set-mode!", editor_set_mode); + engine.register_fn("editor-doc-in-view?", is_document_in_view); + // engine.register_fn("editor->get-document", get_document); // TODO: These are some horrendous type annotations, however... they do work? @@ -634,8 +640,7 @@ fn configure_engine() -> std::rc::Rc std::rc::Rc String { doc.selection(view.id).primary().slice(text).to_string() } +fn current_selection(cx: &mut Context) -> Selection { + let (view, doc) = current_ref!(cx.editor); + doc.selection(view.id).clone() +} + +fn set_selection(cx: &mut Context, selection: Selection) { + let (view, doc) = current!(cx.editor); + doc.set_selection(view.id, selection) +} + +fn current_line_number(cx: &mut Context) -> usize { + let (view, doc) = current_ref!(cx.editor); + helix_core::coords_at_pos( + doc.text().slice(..), + doc + .selection(view.id) + .primary() + .cursor(doc.text().slice(..)), + ).row +} + fn get_selection(cx: &mut Context) -> String { let (view, doc) = current_ref!(cx.editor); let text = doc.text().slice(..); @@ -921,6 +954,10 @@ fn current_path(cx: &mut Context) -> Option { current_doc.and_then(|x| x.path().and_then(|x| x.to_str().map(|x| x.to_string()))) } +fn cx_current_focus(cx: &mut Context) -> helix_view::ViewId { + cx.editor.tree.focus +} + // TODO: Expose the below in a separate module, make things a bit more clear! fn current_focus(editor: &mut Editor) -> helix_view::ViewId { @@ -937,6 +974,10 @@ fn get_document(editor: &mut Editor, doc_id: DocumentId) -> &Document { editor.documents.get(&doc_id).unwrap() } +fn is_document_in_view(editor: &mut Editor, doc_id: DocumentId) -> Option { + editor.tree.traverse().find(|(_, v)| v.doc == doc_id).map(|(id, _)| id) +} + fn document_exists(editor: &mut Editor, doc_id: DocumentId) -> bool { editor.documents.get(&doc_id).is_some() } @@ -945,6 +986,32 @@ fn document_path(doc: &Document) -> Option { doc.path().and_then(|x| x.to_str()).map(|x| x.to_string()) } +fn switch(editor: &mut Editor, doc_id: DocumentId) { + editor.switch(doc_id, Action::VerticalSplit) +} + +// fn editor_set_focus(editor: &mut Editor, view_id: helix_view::ViewId) { +// editor.tree.focus = view_id +// } + +fn editor_get_mode(editor: &mut Editor) -> Mode { + editor.mode +} + +fn editor_set_mode(editor: &mut Editor, mode: Mode) { + editor.mode = mode +} + +// fn insert_text(cx: &mut Context, text: String) { +// let count = cx.count(); +// let reg_name = cx.register.unwrap_or('"'); +// let (view, doc) = current!(cx.editor); +// let registers = &mut cx.editor.registers; + +// if let Some(values) = registers.read(reg_name) { +// paste_impl(values, doc, view, pos, count, cx.editor.mode); +// } +// } // cx->editor // diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bb90dcf59..4f583d386 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -805,6 +805,8 @@ use futures_util::stream::{Flatten, Once}; impl steel::gc::unsafe_erased_pointers::CustomReference for Editor {} steel::custom_reference!(Editor); +impl steel::rvals::Custom for Mode {} + #[repr(C)] pub struct Editor { /// Current editing mode.