aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs29
-rw-r--r--helix-view/src/lib.rs3
-rw-r--r--helix-view/src/macros.rs29
3 files changed, 36 insertions, 25 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 24f43c0e..a1c93f75 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -101,19 +101,19 @@ impl Editor {
match action {
Action::Replace => {
- let view = self.view();
+ let view = view!(self);
let jump = (
view.doc,
self.documents[view.doc].selection(view.id).clone(),
);
- let view = self.view_mut();
+ let view = view_mut!(self);
view.jumps.push(jump);
view.last_accessed_doc = Some(view.doc);
view.doc = id;
view.first_line = 0;
- let (view, doc) = self.current();
+ let (view, doc) = current!(self);
// initialize selection for view
let selection = doc
@@ -238,27 +238,6 @@ impl Editor {
self.tree.is_empty()
}
- pub fn current(&mut self) -> (&mut View, &mut Document) {
- let view = self.tree.get_mut(self.tree.focus);
- let doc = &mut self.documents[view.doc];
- (view, doc)
- }
-
- pub fn current_with_registers(&mut self) -> (&mut View, &mut Document, &mut Registers) {
- let view = self.tree.get_mut(self.tree.focus);
- let doc = &mut self.documents[view.doc];
- let registers = &mut self.registers;
- (view, doc, registers)
- }
-
- pub fn view(&self) -> &View {
- self.tree.get(self.tree.focus)
- }
-
- pub fn view_mut(&mut self) -> &mut View {
- self.tree.get_mut(self.tree.focus)
- }
-
pub fn ensure_cursor_in_view(&mut self, id: ViewId) {
let view = self.tree.get_mut(id);
let doc = &self.documents[view.doc];
@@ -280,7 +259,7 @@ impl Editor {
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
- let view = self.view();
+ let view = view!(self);
let doc = &self.documents[view.doc];
let cursor = doc.selection(view.id).cursor();
if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs
index 7e253320..20613451 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -1,3 +1,6 @@
+#[macro_use]
+pub mod macros;
+
pub mod document;
pub mod editor;
pub mod register_selection;
diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs
new file mode 100644
index 00000000..a06d37e7
--- /dev/null
+++ b/helix-view/src/macros.rs
@@ -0,0 +1,29 @@
+#[macro_export]
+macro_rules! current {
+ ( $( $editor:ident ).+ ) => {{
+ let view = $crate::view_mut!( $( $editor ).+ );
+ let doc = &mut $( $editor ).+ .documents[view.doc];
+ (view, doc)
+ }};
+}
+
+#[macro_export]
+macro_rules! doc_mut {
+ ( $( $editor:ident ).+ ) => {{
+ $crate::current!( $( $editor ).+ ).1
+ }};
+}
+
+#[macro_export]
+macro_rules! view_mut {
+ ( $( $editor:ident ).+ ) => {{
+ $( $editor ).+ .tree.get_mut($( $editor ).+ .tree.focus)
+ }};
+}
+
+#[macro_export]
+macro_rules! view {
+ ( $( $editor:ident ).+ ) => {{
+ $( $editor ).+ .tree.get($( $editor ).+ .tree.focus)
+ }};
+}