From e0be452bdb7f4d6492659c8782767c2b9f306cef Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 2 Oct 2022 13:12:58 -0400 Subject: [PATCH] Cleanup --- kakplugin/src/lib.rs | 2 -- kakplugin/src/types.rs | 2 -- src/incr.rs | 4 ++-- src/invert.rs | 4 +--- src/main.rs | 2 -- src/math_eval.rs | 4 ++-- src/pad.rs | 7 +++---- src/set.rs | 19 ++++++------------- src/sort.rs | 1 - src/utils.rs | 29 +++++------------------------ src/xargs.rs | 1 - src/xlookup.rs | 9 +-------- 12 files changed, 20 insertions(+), 64 deletions(-) diff --git a/kakplugin/src/lib.rs b/kakplugin/src/lib.rs index dfa9cb8..1c52f1b 100644 --- a/kakplugin/src/lib.rs +++ b/kakplugin/src/lib.rs @@ -25,7 +25,6 @@ pub fn get_selections(keys: Option<&'_ str>) -> Result, 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(keys: Option) -> Result, KakError> where S: AsRef, @@ -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(keys: Option) -> Result, KakError> where S: AsRef, diff --git a/kakplugin/src/types.rs b/kakplugin/src/types.rs index 6dcabd8..3458ee6 100644 --- a/kakplugin/src/types.rs +++ b/kakplugin/src/types.rs @@ -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, diff --git a/src/incr.rs b/src/incr.rs index 90bf09a..b25ae07 100644 --- a/src/incr.rs +++ b/src/incr.rs @@ -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 { diff --git a/src/invert.rs b/src/invert.rs index 1953fdd..0314c64 100644 --- a/src/invert.rs +++ b/src/invert.rs @@ -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")] diff --git a/src/main.rs b/src/main.rs index 2563007..9b0d96e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)] diff --git a/src/math_eval.rs b/src/math_eval.rs index 86c26d0..8270cec 100644 --- a/src/math_eval.rs +++ b/src/math_eval.rs @@ -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; diff --git a/src/pad.rs b/src/pad.rs index 1f0373b..445cb66 100644 --- a/src/pad.rs +++ b/src/pad.rs @@ -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 { 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); diff --git a/src/set.rs b/src/set.rs index 2d7dc1a..adf0ad3 100644 --- a/src/set.rs +++ b/src/set.rs @@ -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? } } diff --git a/src/sort.rs b/src/sort.rs index 3b3928f..c558373 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -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, } diff --git a/src/utils.rs b/src/utils.rs index afadfb9..f17a66b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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) } diff --git a/src/xargs.rs b/src/xargs.rs index c2af9a1..4d1d0ee 100644 --- a/src/xargs.rs +++ b/src/xargs.rs @@ -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}, }; diff --git a/src/xlookup.rs b/src/xlookup.rs index 9538ac5..41475ec 100644 --- a/src/xlookup.rs +++ b/src/xlookup.rs @@ -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)]