This commit is contained in:
Austen Adler 2022-10-02 13:12:58 -04:00
parent 3ac74d08af
commit e0be452bdb
12 changed files with 20 additions and 64 deletions

View File

@ -25,7 +25,6 @@ pub fn get_selections(keys: Option<&'_ str>) -> Result<Vec<Selection>, KakError>
/// # Errors
///
/// Will return `Err` if command fifo could not be opened, read from, or written to
// TODO: Use AsRef
pub fn get_selections_desc<S>(keys: Option<S>) -> Result<Vec<SelectionDesc>, KakError>
where
S: AsRef<str>,
@ -41,7 +40,6 @@ where
/// # Errors
///
/// Will return `Err` if command fifo could not be opened, read from, or written to
// TODO: Use AsRef
pub fn get_selections_desc_unordered<S>(keys: Option<S>) -> Result<Vec<SelectionDesc>, KakError>
where
S: AsRef<str>,

View File

@ -163,8 +163,6 @@ impl SelectionDesc {
match (b.contains(&a.left), b.contains(&a.right), a.contains(&b)) {
(false, false, false) => {
// There is no intersection
// TODO: Do the weird boundary ones
// None
if a.right.row == b.left.row && a.right.col == b.left.col.saturating_sub(1) {
Some(Self {
left: a.left,

View File

@ -1,6 +1,6 @@
use evalexpr::{eval, Value};
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
use std::{borrow::Cow, io::Write};
use kakplugin::{get_selections, set_selections, KakError};
use std::borrow::Cow;
#[derive(clap::StructOpt, Debug)]
pub struct Options {

View File

@ -1,8 +1,6 @@
use kakplugin::{
get_selections_desc, set_selections_desc, types::MaybeSplit, AnchorPosition, KakError,
SelectionDesc,
get_selections_desc, set_selections_desc, types::MaybeSplit, KakError, SelectionDesc,
};
use std::{fs, str::FromStr};
#[derive(clap::StructOpt, Debug)]
pub struct Options {
#[clap(short, long, help = "Do not include newlines")]

View File

@ -5,8 +5,6 @@
// Cannot be fixed
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::struct_excessive_bools)]
// TODO: Remove
#![allow(dead_code, unused_imports)]
#![feature(slice_group_by)]
#![feature(slice_take)]
#![feature(array_chunks)]

View File

@ -1,6 +1,6 @@
use evalexpr::{eval, Value};
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
use std::{borrow::Cow, io::Write};
use kakplugin::{get_selections, set_selections, KakError};
use std::borrow::Cow;
#[derive(clap::StructOpt, Debug)]
pub struct Options;

View File

@ -1,7 +1,6 @@
use crate::utils::split_newlines;
use evalexpr::{eval, Value};
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
use std::{borrow::Cow, io::Write};
use kakplugin::{get_selections, set_selections, KakError};
use std::borrow::Cow;
#[derive(clap::StructOpt, Debug)]
pub struct Options {
@ -35,7 +34,7 @@ pub fn pad(options: &Options) -> Result<String, KakError> {
Some(len) => {
num_padded += 1;
let fill = options.fill.to_string().repeat(len);
let mut ret = leading_newlines.to_string();
let mut ret = (*leading_newlines).to_string();
if options.right {
ret.push_str(s);
ret.push_str(&fill);

View File

@ -1,13 +1,12 @@
// use crate::utils;
use clap::ArgEnum;
use kakplugin::{
get_selections, get_selections_with_desc, set_selections, set_selections_desc, types::Register,
KakError, Selection, SelectionWithDesc,
get_selections, get_selections_with_desc, set_selections_desc, types::Register, KakError,
Selection,
};
use linked_hash_map::LinkedHashMap;
use linked_hash_set::LinkedHashSet;
use regex::Regex;
use std::{collections::HashSet, io::Write, str::FromStr};
use std::{io::Write, str::FromStr};
#[derive(clap::StructOpt, Debug)]
pub struct Options {
@ -299,22 +298,16 @@ fn key_set_operation<'a>(
Operation::Intersect => left_keys
.intersection(right_keys)
// .into_iter()
// TODO: Remove this
.copied()
.collect(),
Operation::Subtract => left_keys
.difference(right_keys)
.into_iter()
// TODO: Remove this
.copied()
.collect(),
Operation::Compare | Operation::Union => left_keys
.union(right_keys)
.into_iter()
// TODO: Remove this
.copied()
.collect(),
// TODO: Symmetric difference?
Operation::Compare | Operation::Union => {
left_keys.union(right_keys).into_iter().copied().collect()
} // TODO: Symmetric difference?
}
}

View File

@ -20,7 +20,6 @@ pub struct Options {
no_lexicographic_sort: bool,
#[clap(short, long, help = "Reverse sorting")]
reverse: bool,
// TODO: Allow ignoring case
#[clap(short, long, help = "Ignore case when sorting")]
ignore_case: bool,
}

View File

@ -6,6 +6,7 @@ use std::{
};
pub fn get_key(
// TODO: Use Cow
selection: &Selection,
skip_whitespace: bool,
regex: Option<&Regex>,
@ -54,23 +55,7 @@ pub fn get_hash(
hasher.finish()
}
/// Splits an `&str` into (string_value, trailing_newlines)
///
/// # Examples
///
/// ```
/// assert_eq!(split_trailing_newlines("asdf\n"), ("asdf", "\n"));
/// assert_eq!(split_trailing_newlines("asdf\n\nhjk\n"), ("asdf\n\nhjk", "\n"));
/// assert_eq!(split_trailing_newlines("asdf"), ("asdf", ""));
/// assert_eq!(split_trailing_newlines(""), ("", ""));
/// ```
pub fn split_trailing_newlines<'a>(s: &'a str) -> (&'a str, &'a str) {
s.rfind(|c| c != '\n')
.map(|idx| s.split_at(idx + 1))
.unwrap_or((s, ""))
}
/// Splits an `&str` into (leading_newlines, string_value, trailing_newlines)
/// Splits an `&str` into (`leading_newlines`, `string_value`, `trailing_newlines`)
///
/// # Examples
///
@ -82,16 +67,12 @@ pub fn split_trailing_newlines<'a>(s: &'a str) -> (&'a str, &'a str) {
/// assert_eq!(split_newlines("\n\n\nasdf"), ("\n\n\n", "asdf", ""));
/// assert_eq!(split_newlines(""), ("", "", ""));
/// ```
pub fn split_newlines<'a>(s: &'a str) -> (&'a str, &'a str, &'a str) {
let (leading_newlines, s) = s
.find(|c| c != '\n')
.map(|idx| s.split_at(idx))
.unwrap_or(("", s));
pub fn split_newlines(s: &'_ str) -> (&'_ str, &'_ str, &'_ str) {
let (leading_newlines, s) = s.find(|c| c != '\n').map_or(("", s), |idx| s.split_at(idx));
let (s, trailing_newlines) = s
.rfind(|c| c != '\n')
.map(|idx| s.split_at(idx + 1))
.unwrap_or((s, ""));
.map_or((s, ""), |idx| s.split_at(idx + 1));
(leading_newlines, s, trailing_newlines)
}

View File

@ -1,6 +1,5 @@
use kakplugin::{get_selections_with_desc, set_selections_failable, KakError};
use std::{
borrow::Cow,
io::{BufRead, BufReader, Write},
process::{Command, Stdio},
};

View File

@ -1,18 +1,11 @@
use crate::utils::get_hash;
use evalexpr::{eval, Value};
use kakplugin::{
get_selections, open_command_fifo, response, set_selections, types::Register, KakError,
Selection,
};
use kakplugin::{get_selections, set_selections, types::Register, KakError, Selection};
use std::{
borrow::Cow,
collections::{
btree_map::Entry::{Occupied, Vacant},
hash_map::DefaultHasher,
BTreeMap,
},
hash::{Hash, Hasher},
io::Write,
};
#[derive(clap::StructOpt, Debug)]