@@ -34,7 +34,6 @@ use movement::Movement;
3434
3535use crate::{
3636 compositor::{self, Component, Compositor},
37− key,
3837 ui::{self, Picker, Popup, Prompt, PromptEvent},
3938};
4039
@@ -48,7 +47,7 @@ use std::{
4847 path::{Path, PathBuf},
4948};
5049
51−use once_cell::sync::Lazy;
50+use once_cell::sync::{Lazy, OnceCell};
5251use serde::de::{self, Deserialize, Deserializer};
5352
5453pub struct Context<'a> {
@@ -3414,13 +3413,11 @@ fn select_register(cx: &mut Context) {
34143413}
34153414
34163415macro_rules! mode_info {
3417− // TODO: how to use one expr for both pat and expr?
3418− // TODO: how to use replaced function name as str at compile time?
3419− // TODO: extend to support multiple keys, but first solve the other two
3416+ // TODO: reuse $mode for $stat
34203417 (@join $first:expr $(,$rest:expr)*) => {
34213418 concat!($first, $(", ", $rest),*)
34223419 };
3423− {$mode:ident, $name:literal, $(#[doc = $desc:literal] $($key:expr),+ => $func:expr),+,} => {
3420+ {$mode:ident, $stat:ident, $name:literal, $(#[doc = $desc:literal] $($key:tt)|+ => $func:expr),+,} => {
34243421 #[doc = $name]
34253422 #[doc = ""]
34263423 #[doc = "<table><tr><th>key</th><th>desc</th></tr><tbody>"]
@@ -3439,12 +3436,14 @@ macro_rules! mode_info {
34393436 )+
34403437 #[doc = "</tbody></table>"]
34413438 pub fn $mode(cx: &mut Context) {
3442− cx.editor.autoinfo = Some(Info::key(
3439+ static $stat: OnceCell<Info> = OnceCell::new();
3440+ cx.editor.autoinfo = Some($stat.get_or_init(|| Info::key(
34433441 $name,
3444− vec![$((vec![$($key.parse().unwrap()),+], $desc)),+],
3445− ));
3442+ vec![$((&[$($key.parse().unwrap()),+], $desc)),+],
3443+ )));
34463444 use helix_core::hashmap;
3447− let mut map = hashmap! {
3445+ // TODO: try and convert this to match later
3446+ let map = hashmap! {
34483447 $($($key.parse::<KeyEvent>().unwrap() => $func as for<'r, 's> fn(&'r mut Context<'s>)),+),*
34493448 };
34503449 cx.on_next_key_mode(map);
@@ -3453,7 +3452,7 @@ macro_rules! mode_info {
34533452}
34543453
34553454mode_info! {
3456− space_mode, "space mode",
3455+ space_mode, SPACE_MODE, "space mode",
34573456 /// file picker
34583457 "f" => file_picker,
34593458 /// buffer picker