Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/macros.rs')
-rw-r--r--helix-view/src/macros.rs80
1 files changed, 67 insertions, 13 deletions
diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs
index ee9cd411..f939d129 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 = $crate::doc_mut!($editor, &id);
+ let doc = $editor.documents.get_mut(&id).unwrap();
(view, doc)
}};
}
@@ -32,9 +32,6 @@ 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
}};
@@ -44,9 +41,6 @@ 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)
}};
@@ -56,9 +50,6 @@ 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)
}};
@@ -66,10 +57,73 @@ macro_rules! view {
#[macro_export]
macro_rules! doc {
- ($editor:expr, $id:expr) => {{
- &$editor.documents[$id]
- }};
($editor:expr) => {{
$crate::current_ref!($editor).1
}};
}
+
+// Keymap macros
+
+#[macro_export]
+macro_rules! key {
+ ($key:ident) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::$key,
+ modifiers: $crate::keyboard::KeyModifiers::NONE,
+ }
+ };
+ ($($ch:tt)*) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::Char($($ch)*),
+ modifiers: $crate::keyboard::KeyModifiers::NONE,
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! shift {
+ ($key:ident) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::$key,
+ modifiers: $crate::keyboard::KeyModifiers::SHIFT,
+ }
+ };
+ ($($ch:tt)*) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::Char($($ch)*),
+ modifiers: $crate::keyboard::KeyModifiers::SHIFT,
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! ctrl {
+ ($key:ident) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::$key,
+ modifiers: $crate::keyboard::KeyModifiers::CONTROL,
+ }
+ };
+ ($($ch:tt)*) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::Char($($ch)*),
+ modifiers: $crate::keyboard::KeyModifiers::CONTROL,
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! alt {
+ ($key:ident) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::$key,
+ modifiers: $crate::keyboard::KeyModifiers::ALT,
+ }
+ };
+ ($($ch:tt)*) => {
+ $crate::input::KeyEvent {
+ code: $crate::keyboard::KeyCode::Char($($ch)*),
+ modifiers: $crate::keyboard::KeyModifiers::ALT,
+ }
+ };
+}