summaryrefslogtreecommitdiff
path: root/src/config/keymap/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/keymap/mod.rs')
-rw-r--r--src/config/keymap/mod.rs54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/config/keymap/mod.rs b/src/config/keymap/mod.rs
index e9995f2..dc97ccc 100644
--- a/src/config/keymap/mod.rs
+++ b/src/config/keymap/mod.rs
@@ -9,33 +9,41 @@ use self::{
use super::{GlobalConfig, DUMMY_CONFIG};
use template::KeyMapSections;
-KeyMapSections!(
- ViewKeyMap => view,
- GlobalKeyMap => global,
-);
-
-#[derive(Debug, Default, Clone)]
-pub struct KeyMap {
- pub view: ViewKeyMap,
- pub global: GlobalKeyMap,
-}
-
pub mod event_from_string;
pub mod keymap_store;
pub mod template;
-impl KeyMap {
- pub const fn new() -> Self {
- Self {
- view: ViewKeyMap::new(),
- global: GlobalKeyMap::new(),
+macro_rules! KeyMap {
+ ($($name:ident => $key:ident),+ $(,)?) => {
+ KeyMapSections!($($name => $key,)*);
+
+ #[derive(Debug, Default, Clone)]
+ pub struct KeyMap {
+ $($key: $name,)*
}
- }
-}
-impl UserData for KeyMap {
- fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
- fields.add_field_function_get("view", |_, _| Ok(DUMMY_CONFIG.keymap.view.clone()));
- fields.add_field_function_get("global", |_, _| Ok(DUMMY_CONFIG.keymap.global.clone()));
- }
+ impl KeyMap {
+ pub const fn new() -> Self {
+ Self {
+ $($key: $name::new(),)*
+ }
+ }
+ }
+
+ impl UserData for KeyMap {
+ fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
+ $(
+ fields.add_field_function_get(stringify!($key), |_, _|
+ Ok(DUMMY_CONFIG.keymap.$key.clone()));
+ )*
+ }
+ }
+ };
}
+
+KeyMap!(
+ ViewKeyMap => view,
+ GlobalKeyMap => global,
+ EditorKeyMap => editor,
+);
+