Go to file
2022-08-11 16:08:04 -04:00
dist Update demo asciinema 2022-03-12 18:29:57 -05:00
kakplugin Implement box function 2022-08-11 16:07:26 -04:00
src Implement invert function 2022-08-11 16:08:04 -04:00
.gitignore Add initial code 2022-01-22 16:29:02 -05:00
Cargo.lock Add basic autocomplete 2022-07-06 22:11:41 -04:00
Cargo.toml Add basic autocomplete 2022-07-06 22:11:41 -04:00
README.adoc Update docs 2022-07-10 16:36:14 -04:00
rustfmt.toml Format import granularity 2022-02-21 18:30:32 -05:00

= kakutils-rs

Sort by regular expression or lexicographically, find uniqes, shuffle, or evaluate rust selections without spawning a new command for each.

[![asciicast](https://asciinema.org/a/dIQh9NtLRkzVEENxmij5qBaai.svg)](https://asciinema.org/a/dIQh9NtLRkzVEENxmij5qBaai)

== Example

. Imagine you want to sort these stages
+
[source,groovy]
----
stage("Build") { # Step 1
    8+3
}

stage("Compile") { # Step 5
    math::log2(8)
}

stage("Assemble") { # Step 10
    2^9+math::log2(10)
}

stage("Make") { # Step 100
    not_a_formula
}
----

. Select the stage and stage body with: `%sstage<ret>MLM`
. Sort the selection by step number with: `:utils sort #\d+<ret>` (sort on whole capture) or `:utils sort "'.+?#(\d).+?'"` (sort on first capture group, which contains only the digits)
. Note if you just run `:utils sort<ret>`

== Configuration

[source,sh,title='sh']
----
cargo install --git https://github.com/austenadler/kakutils-rs
----

[source,title='kakrc']
----
define-command utils -params .. -shell-script-candidates %{
    # use kak_token_to_complete;
    kakutils-rs shell-script-candidates
} %{
    eval -save-regs '"' %{
        eval %sh{
            # use kak_command_fifo kak_response_fifo;
            kakutils-rs "$@"
        }
    }
}
----

== Usage

* Make multiple selections
* Run `utils sort` to sort the selections lexicographically
* Run `utils sort REGEX` to sort by regex match
** If the regex does not contain a capture group
** If the regex contains at least one capture group

== TODO

* I don't know what will happen with multiline strings and regex
* Figure out how to change the `no_skip_whitespace` option name in the source
* Get sort by selections working