Cleanup
This commit is contained in:
parent
3ac74d08af
commit
e0be452bdb
@ -25,7 +25,6 @@ pub fn get_selections(keys: Option<&'_ str>) -> Result<Vec<Selection>, KakError>
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Will return `Err` if command fifo could not be opened, read from, or written to
|
/// 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>
|
pub fn get_selections_desc<S>(keys: Option<S>) -> Result<Vec<SelectionDesc>, KakError>
|
||||||
where
|
where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
@ -41,7 +40,6 @@ where
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Will return `Err` if command fifo could not be opened, read from, or written to
|
/// 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>
|
pub fn get_selections_desc_unordered<S>(keys: Option<S>) -> Result<Vec<SelectionDesc>, KakError>
|
||||||
where
|
where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
|
@ -163,8 +163,6 @@ impl SelectionDesc {
|
|||||||
match (b.contains(&a.left), b.contains(&a.right), a.contains(&b)) {
|
match (b.contains(&a.left), b.contains(&a.right), a.contains(&b)) {
|
||||||
(false, false, false) => {
|
(false, false, false) => {
|
||||||
// There is no intersection
|
// 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) {
|
if a.right.row == b.left.row && a.right.col == b.left.col.saturating_sub(1) {
|
||||||
Some(Self {
|
Some(Self {
|
||||||
left: a.left,
|
left: a.left,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use evalexpr::{eval, Value};
|
use evalexpr::{eval, Value};
|
||||||
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
|
use kakplugin::{get_selections, set_selections, KakError};
|
||||||
use std::{borrow::Cow, io::Write};
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use kakplugin::{
|
use kakplugin::{
|
||||||
get_selections_desc, set_selections_desc, types::MaybeSplit, AnchorPosition, KakError,
|
get_selections_desc, set_selections_desc, types::MaybeSplit, KakError, SelectionDesc,
|
||||||
SelectionDesc,
|
|
||||||
};
|
};
|
||||||
use std::{fs, str::FromStr};
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
#[clap(short, long, help = "Do not include newlines")]
|
#[clap(short, long, help = "Do not include newlines")]
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
// Cannot be fixed
|
// Cannot be fixed
|
||||||
#![allow(clippy::multiple_crate_versions)]
|
#![allow(clippy::multiple_crate_versions)]
|
||||||
#![allow(clippy::struct_excessive_bools)]
|
#![allow(clippy::struct_excessive_bools)]
|
||||||
// TODO: Remove
|
|
||||||
#![allow(dead_code, unused_imports)]
|
|
||||||
#![feature(slice_group_by)]
|
#![feature(slice_group_by)]
|
||||||
#![feature(slice_take)]
|
#![feature(slice_take)]
|
||||||
#![feature(array_chunks)]
|
#![feature(array_chunks)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use evalexpr::{eval, Value};
|
use evalexpr::{eval, Value};
|
||||||
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
|
use kakplugin::{get_selections, set_selections, KakError};
|
||||||
use std::{borrow::Cow, io::Write};
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
pub struct Options;
|
pub struct Options;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::utils::split_newlines;
|
use crate::utils::split_newlines;
|
||||||
use evalexpr::{eval, Value};
|
use kakplugin::{get_selections, set_selections, KakError};
|
||||||
use kakplugin::{get_selections, open_command_fifo, set_selections, KakError, Selection};
|
use std::borrow::Cow;
|
||||||
use std::{borrow::Cow, io::Write};
|
|
||||||
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
@ -35,7 +34,7 @@ pub fn pad(options: &Options) -> Result<String, KakError> {
|
|||||||
Some(len) => {
|
Some(len) => {
|
||||||
num_padded += 1;
|
num_padded += 1;
|
||||||
let fill = options.fill.to_string().repeat(len);
|
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 {
|
if options.right {
|
||||||
ret.push_str(s);
|
ret.push_str(s);
|
||||||
ret.push_str(&fill);
|
ret.push_str(&fill);
|
||||||
|
19
src/set.rs
19
src/set.rs
@ -1,13 +1,12 @@
|
|||||||
// use crate::utils;
|
// use crate::utils;
|
||||||
use clap::ArgEnum;
|
|
||||||
use kakplugin::{
|
use kakplugin::{
|
||||||
get_selections, get_selections_with_desc, set_selections, set_selections_desc, types::Register,
|
get_selections, get_selections_with_desc, set_selections_desc, types::Register, KakError,
|
||||||
KakError, Selection, SelectionWithDesc,
|
Selection,
|
||||||
};
|
};
|
||||||
use linked_hash_map::LinkedHashMap;
|
use linked_hash_map::LinkedHashMap;
|
||||||
use linked_hash_set::LinkedHashSet;
|
use linked_hash_set::LinkedHashSet;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{collections::HashSet, io::Write, str::FromStr};
|
use std::{io::Write, str::FromStr};
|
||||||
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
@ -299,22 +298,16 @@ fn key_set_operation<'a>(
|
|||||||
Operation::Intersect => left_keys
|
Operation::Intersect => left_keys
|
||||||
.intersection(right_keys)
|
.intersection(right_keys)
|
||||||
// .into_iter()
|
// .into_iter()
|
||||||
// TODO: Remove this
|
|
||||||
.copied()
|
.copied()
|
||||||
.collect(),
|
.collect(),
|
||||||
Operation::Subtract => left_keys
|
Operation::Subtract => left_keys
|
||||||
.difference(right_keys)
|
.difference(right_keys)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
// TODO: Remove this
|
|
||||||
.copied()
|
.copied()
|
||||||
.collect(),
|
.collect(),
|
||||||
Operation::Compare | Operation::Union => left_keys
|
Operation::Compare | Operation::Union => {
|
||||||
.union(right_keys)
|
left_keys.union(right_keys).into_iter().copied().collect()
|
||||||
.into_iter()
|
} // TODO: Symmetric difference?
|
||||||
// TODO: Remove this
|
|
||||||
.copied()
|
|
||||||
.collect(),
|
|
||||||
// TODO: Symmetric difference?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ pub struct Options {
|
|||||||
no_lexicographic_sort: bool,
|
no_lexicographic_sort: bool,
|
||||||
#[clap(short, long, help = "Reverse sorting")]
|
#[clap(short, long, help = "Reverse sorting")]
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
// TODO: Allow ignoring case
|
|
||||||
#[clap(short, long, help = "Ignore case when sorting")]
|
#[clap(short, long, help = "Ignore case when sorting")]
|
||||||
ignore_case: bool,
|
ignore_case: bool,
|
||||||
}
|
}
|
||||||
|
29
src/utils.rs
29
src/utils.rs
@ -6,6 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_key(
|
pub fn get_key(
|
||||||
|
// TODO: Use Cow
|
||||||
selection: &Selection,
|
selection: &Selection,
|
||||||
skip_whitespace: bool,
|
skip_whitespace: bool,
|
||||||
regex: Option<&Regex>,
|
regex: Option<&Regex>,
|
||||||
@ -54,23 +55,7 @@ pub fn get_hash(
|
|||||||
hasher.finish()
|
hasher.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splits an `&str` into (string_value, trailing_newlines)
|
/// Splits an `&str` into (`leading_newlines`, `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)
|
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # 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("\n\n\nasdf"), ("\n\n\n", "asdf", ""));
|
||||||
/// assert_eq!(split_newlines(""), ("", "", ""));
|
/// assert_eq!(split_newlines(""), ("", "", ""));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn split_newlines<'a>(s: &'a str) -> (&'a str, &'a str, &'a str) {
|
pub fn split_newlines(s: &'_ str) -> (&'_ str, &'_ str, &'_ str) {
|
||||||
let (leading_newlines, s) = s
|
let (leading_newlines, s) = s.find(|c| c != '\n').map_or(("", s), |idx| s.split_at(idx));
|
||||||
.find(|c| c != '\n')
|
|
||||||
.map(|idx| s.split_at(idx))
|
|
||||||
.unwrap_or(("", s));
|
|
||||||
|
|
||||||
let (s, trailing_newlines) = s
|
let (s, trailing_newlines) = s
|
||||||
.rfind(|c| c != '\n')
|
.rfind(|c| c != '\n')
|
||||||
.map(|idx| s.split_at(idx + 1))
|
.map_or((s, ""), |idx| s.split_at(idx + 1));
|
||||||
.unwrap_or((s, ""));
|
|
||||||
|
|
||||||
(leading_newlines, s, trailing_newlines)
|
(leading_newlines, s, trailing_newlines)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use kakplugin::{get_selections_with_desc, set_selections_failable, KakError};
|
use kakplugin::{get_selections_with_desc, set_selections_failable, KakError};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
|
||||||
io::{BufRead, BufReader, Write},
|
io::{BufRead, BufReader, Write},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
use crate::utils::get_hash;
|
use crate::utils::get_hash;
|
||||||
use evalexpr::{eval, Value};
|
use kakplugin::{get_selections, set_selections, types::Register, KakError, Selection};
|
||||||
use kakplugin::{
|
|
||||||
get_selections, open_command_fifo, response, set_selections, types::Register, KakError,
|
|
||||||
Selection,
|
|
||||||
};
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::{
|
collections::{
|
||||||
btree_map::Entry::{Occupied, Vacant},
|
btree_map::Entry::{Occupied, Vacant},
|
||||||
hash_map::DefaultHasher,
|
|
||||||
BTreeMap,
|
BTreeMap,
|
||||||
},
|
},
|
||||||
hash::{Hash, Hasher},
|
|
||||||
io::Write,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(clap::StructOpt, Debug)]
|
#[derive(clap::StructOpt, Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user