Fix empty registers
This commit is contained in:
parent
526b6fef24
commit
64959d6069
@ -1,3 +1,4 @@
|
|||||||
|
use crate::Register;
|
||||||
use std::{fmt, fmt::Display, num::ParseIntError};
|
use std::{fmt, fmt::Display, num::ParseIntError};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -22,6 +23,8 @@ pub enum KakError {
|
|||||||
CustomStatic(&'static str),
|
CustomStatic(&'static str),
|
||||||
/// The selections/selections_desc list passed was empty
|
/// The selections/selections_desc list passed was empty
|
||||||
SetEmptySelections,
|
SetEmptySelections,
|
||||||
|
/// The register register has no content
|
||||||
|
EmptyRegister(Register),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for KakError {}
|
impl std::error::Error for KakError {}
|
||||||
@ -41,6 +44,9 @@ impl KakError {
|
|||||||
Self::SetEmptySelections => {
|
Self::SetEmptySelections => {
|
||||||
String::from("Attempted to set selections/selections_desc to empty list")
|
String::from("Attempted to set selections/selections_desc to empty list")
|
||||||
}
|
}
|
||||||
|
Self::EmptyRegister(r) => {
|
||||||
|
format!("Empty register: {r}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,6 +68,7 @@ impl Display for KakError {
|
|||||||
f,
|
f,
|
||||||
"Attempted to set selections/selections_desc to empty list"
|
"Attempted to set selections/selections_desc to empty list"
|
||||||
),
|
),
|
||||||
|
Self::EmptyRegister(r) => write!(f, "Register {r} has no content"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,5 +354,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reg(register: Register, keys: Option<&'_ str>) -> Result<Vec<String>, KakError> {
|
pub fn reg(register: Register, keys: Option<&'_ str>) -> Result<Vec<String>, KakError> {
|
||||||
response(format!("%reg{{{}}}", register.kak_expanded()), keys)
|
let ret = response(format!("%reg{{{}}}", register.kak_expanded()), keys)?;
|
||||||
|
|
||||||
|
// Kak returns a single empty line
|
||||||
|
if &ret[..] == [""] {
|
||||||
|
return Err(KakError::EmptyRegister(register));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user