diff --git a/kakplugin/src/lib.rs b/kakplugin/src/lib.rs index ab9809a..20f0135 100644 --- a/kakplugin/src/lib.rs +++ b/kakplugin/src/lib.rs @@ -22,6 +22,23 @@ pub fn get_selections(keys: Option<&'_ str>) -> Result, KakError> response("%val{selections}", keys) } +pub fn get_register_selections(r: R) -> Result, KakError> +where + R: AsRef, +{ + cmd(&format!( + r#" + evaluate-commands -draft %{{ + execute-keys '\"{}z'; + echo -quoting shell -to-file {} -- %val{{selections}}; + }}"#, + r.as_ref().kak_escaped(), + get_var("kak_response_fifo")? + ))?; + let selections = shell_words::split(&fs::read_to_string(&get_var("kak_response_fifo")?)?)?; + Ok(selections) +} + /// # Errors /// /// Will return `Err` if command fifo could not be opened, read from, or written to diff --git a/src/set.rs b/src/set.rs index 99f4bac..ed80cc9 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1,6 +1,7 @@ // use crate::utils; use kakplugin::{ - get_selections, get_selections_with_desc, reg, set_selections_desc, types::Register, KakError, + get_register_selections, get_selections, get_selections_with_desc, set_selections_desc, + types::Register, KakError, }; use linked_hash_map::LinkedHashMap; use linked_hash_set::LinkedHashSet; @@ -75,19 +76,19 @@ pub fn set<'sel>(options: &'_ Options) -> Result { let (left_selections, right_selections) = match (&left_register, &right_register) { (Register::Underscore, r) => { let l_selections = get_selections(None)?; - let r_selections = reg(*r, None)?; + let r_selections = get_register_selections(r)?; (l_selections, r_selections) } (l, Register::Underscore) => { let r_selections = get_selections(None)?; - let l_selections = reg(*l, None)?; + let l_selections = get_register_selections(l)?; (l_selections, r_selections) } (l, r) => { - let l_selections = reg(*l, None)?; - let r_selections = reg(*r, None)?; + let l_selections = get_register_selections(l)?; + let r_selections = get_register_selections(r)?; (l_selections, r_selections) }