summaryrefslogtreecommitdiff
path: root/helix-view/src/macros.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-09-03 03:36:06 +0000
committerBlaž Hrastnik2022-09-03 03:36:06 +0000
commit6ec4017a8d9f690dd9c9e5c54eadbafdff8be620 (patch)
tree28aaf88b84239f86e9646073b57793edce7232fc /helix-view/src/macros.rs
parent1caba2d3e8e16752d7d659b58c51931451a1cb47 (diff)
Expand doc/view macros to allow fetching specific id
This simplifies the code and hides away unwraps
Diffstat (limited to 'helix-view/src/macros.rs')
-rw-r--r--helix-view/src/macros.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs
index 04f8df94..53ab4346 100644
--- a/helix-view/src/macros.rs
+++ b/helix-view/src/macros.rs
@@ -14,7 +14,7 @@ macro_rules! current {
($editor:expr) => {{
let view = $crate::view_mut!($editor);
let id = view.doc;
- let doc = $editor.documents.get_mut(&id).unwrap();
+ let doc = $crate::doc_mut!($editor, &id);
(view, doc)
}};
}
@@ -32,6 +32,9 @@ macro_rules! current_ref {
/// Returns `&mut Document`
#[macro_export]
macro_rules! doc_mut {
+ ($editor:expr, $id:expr) => {{
+ $editor.documents.get_mut($id).unwrap()
+ }};
($editor:expr) => {{
$crate::current!($editor).1
}};
@@ -41,6 +44,9 @@ macro_rules! doc_mut {
/// Returns `&mut View`
#[macro_export]
macro_rules! view_mut {
+ ($editor:expr, $id:expr) => {{
+ $editor.tree.get_mut($id)
+ }};
($editor:expr) => {{
$editor.tree.get_mut($editor.tree.focus)
}};
@@ -50,6 +56,9 @@ macro_rules! view_mut {
/// Returns `&View`
#[macro_export]
macro_rules! view {
+ ($editor:expr, $id:expr) => {{
+ $editor.tree.get($id)
+ }};
($editor:expr) => {{
$editor.tree.get($editor.tree.focus)
}};
@@ -57,6 +66,9 @@ macro_rules! view {
#[macro_export]
macro_rules! doc {
+ ($editor:expr, $id:expr) => {{
+ $editor.documents[$id]
+ }};
($editor:expr) => {{
$crate::current_ref!($editor).1
}};