aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tham2021-12-12 13:32:55 +0000
committerBlaž Hrastnik2021-12-27 01:13:18 +0000
commit5326a051176d30060e60a8c8d6e718c9ca8a32d7 (patch)
tree263730293aadb04775694d0c77c242c8aa691380
parentc7a59e24e6e1609dd65e5ee66fef52f76aabe9b7 (diff)
Improve macro error handling
-rw-r--r--helix-term/src/commands.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 7b1235f8..e3944cd7 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -6031,23 +6031,17 @@ fn record_macro(cx: &mut Context) {
fn play_macro(cx: &mut Context) {
let reg = cx.register.unwrap_or('@');
- let keys = match cx
- .editor
- .registers
- .get(reg)
- .and_then(|reg| reg.read().get(0))
- .context("Register empty")
- .and_then(|s| {
- s.split_whitespace()
- .map(str::parse::<KeyEvent>)
- .collect::<Result<Vec<_>, _>>()
- .context("Failed to parse macro")
- }) {
- Ok(keys) => keys,
- Err(e) => {
- cx.editor.set_error(format!("{}", e));
- return;
+ let keys: Vec<KeyEvent> = if let Some([keys]) = cx.editor.registers.read(reg) {
+ match keys.split_whitespace().map(str::parse).collect() {
+ Ok(keys) => keys,
+ Err(err) => {
+ cx.editor.set_error(format!("Invalid macro: {}", err));
+ return;
+ }
}
+ } else {
+ cx.editor.set_error(format!("Register [{}] empty", reg));
+ return;
};
let count = cx.count();