aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs5
-rw-r--r--helix-view/src/macros.rs17
2 files changed, 17 insertions, 5 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index e5ff93ad..562c3c60 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -345,11 +345,6 @@ impl Editor {
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
}
- // pub fn current_document(&self) -> Document {
- // let id = self.view().doc;
- // let doc = &mut editor.documents[id];
- // }
-
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
let view = view!(self);
let doc = &self.documents[view.doc];
diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs
index a06d37e7..c9a04270 100644
--- a/helix-view/src/macros.rs
+++ b/helix-view/src/macros.rs
@@ -1,3 +1,14 @@
+//! These are macros to make getting very nested fields in the `Editor` struct easier
+//! These are macros instead of functions because functions will have to take `&mut self`
+//! However, rust doesn't know that you only want a partial borrow instead of borrowing the
+//! entire struct which `&mut self` says. This makes it impossible to do other mutable
+//! stuff to the struct because it is already borrowed. Because macros are expanded,
+//! this circumvents the problem because it is just like indexing fields by hand and then
+//! putting a `&mut` in front of it. This way rust can see that we are only borrowing a
+//! part of the struct and not the entire thing.
+
+/// Get the current view and document mutably as a tuple.
+/// Returns `(&mut View, &mut Document)`
#[macro_export]
macro_rules! current {
( $( $editor:ident ).+ ) => {{
@@ -7,6 +18,8 @@ macro_rules! current {
}};
}
+/// Get the current document mutably.
+/// Returns `&mut Document`
#[macro_export]
macro_rules! doc_mut {
( $( $editor:ident ).+ ) => {{
@@ -14,6 +27,8 @@ macro_rules! doc_mut {
}};
}
+/// Get the current view mutably.
+/// Returns `&mut View`
#[macro_export]
macro_rules! view_mut {
( $( $editor:ident ).+ ) => {{
@@ -21,6 +36,8 @@ macro_rules! view_mut {
}};
}
+/// Get the current view immutably
+/// Returns `&View`
#[macro_export]
macro_rules! view {
( $( $editor:ident ).+ ) => {{