From 64959d606966e5d33a8b98f62d57774e4749de18 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 6 Oct 2022 21:09:13 -0400 Subject: [PATCH] Fix empty registers --- kakplugin/src/errors.rs | 7 +++++++ kakplugin/src/lib.rs | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/kakplugin/src/errors.rs b/kakplugin/src/errors.rs index 3d31abc..1b9dca2 100644 --- a/kakplugin/src/errors.rs +++ b/kakplugin/src/errors.rs @@ -1,3 +1,4 @@ +use crate::Register; use std::{fmt, fmt::Display, num::ParseIntError}; #[derive(Debug)] @@ -22,6 +23,8 @@ pub enum KakError { CustomStatic(&'static str), /// The selections/selections_desc list passed was empty SetEmptySelections, + /// The register register has no content + EmptyRegister(Register), } impl std::error::Error for KakError {} @@ -41,6 +44,9 @@ impl KakError { Self::SetEmptySelections => { 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, "Attempted to set selections/selections_desc to empty list" ), + Self::EmptyRegister(r) => write!(f, "Register {r} has no content"), } } } diff --git a/kakplugin/src/lib.rs b/kakplugin/src/lib.rs index 1c52f1b..872bdb0 100644 --- a/kakplugin/src/lib.rs +++ b/kakplugin/src/lib.rs @@ -354,5 +354,12 @@ where } pub fn reg(register: Register, keys: Option<&'_ str>) -> Result, 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) }