on master help sign in
Improve macro error handling
5326a05Ivan Tham
helix-term/src/commands.rs+10−16
@@ -6031,23 +6031,17 @@ fn record_macro(cx: &mut Context) {
6031
6031
6032fn play_macro(cx: &mut Context) {
6032fn play_macro(cx: &mut Context) {
6033 let reg = cx.register.unwrap_or('@');
6033 let reg = cx.register.unwrap_or('@');
6034− let keys = match cx
6034+ let keys: Vec<KeyEvent> = if let Some([keys]) = cx.editor.registers.read(reg) {
6035− .editor
6036− .registers
6037− .get(reg)
6038− .and_then(|reg| reg.read().get(0))
6039− .context("Register empty")
6040− .and_then(|s| {
6041− s.split_whitespace()
6035+ match keys.split_whitespace().map(str::parse).collect() {
6042− .map(str::parse::<KeyEvent>)
6043− .collect::<Result<Vec<_>, _>>()
6044− .context("Failed to parse macro")
6045− }) {
6046− Ok(keys) => keys,
6036+ Ok(keys) => keys,
6047− Err(e) => {
6037+ Err(err) => {
6048− cx.editor.set_error(format!("{}", e));
6038+ cx.editor.set_error(format!("Invalid macro: {}", err));
6049− return;
6039+ return;
6040+ }
6050 }
6041 }
6042+ } else {
6043+ cx.editor.set_error(format!("Register [{}] empty", reg));
6044+ return;
6051 };
6045 };
6052 let count = cx.count();
6046 let count = cx.count();
6053
6047