Use get_register_selections

This commit is contained in:
Austen Adler 2022-11-04 16:04:16 -04:00
parent eda1d2bb96
commit d1957a47c1
2 changed files with 23 additions and 5 deletions

View File

@ -22,6 +22,23 @@ pub fn get_selections(keys: Option<&'_ str>) -> Result<Vec<Selection>, KakError>
response("%val{selections}", keys)
}
pub fn get_register_selections<R>(r: R) -> Result<Vec<Selection>, KakError>
where
R: AsRef<Register>,
{
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

View File

@ -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<String, KakError> {
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)
}