I love the way Kakoune integrates with other scripting languages instead of requiring a particular language, but choosing which language to use requires some thought.
POSIX shell
Plugins can assume this is present, since Kakoune requires it. It has the basics (loops, conditionals) and some very simple string parsing (case
and prefix/suffix trimming) and formatting (printf
) options, but there’s no support for data structures, which is pretty limiting.
This little laptop can launch /bin/dash
3,398 times in five seconds.
sed
sed is often most people’s first tool when it comes to Unix text processing. While I’m pretty sure it’s Turing-complete, it seems more like an accident than deliberate. sed is reasonable if you need basic search-and-replace, but anything more complex that and you’ll need to enjoy intense puzzle-solving.
AWK
AWK is the great grandaddy of UNIX scripting. Not only does it have all the usual programming features, it has built-in support for processing tabular data, regexes, and it supports associative arrays too.
Unfortunately, various implementations of awk are… unreliable for handling UTF-8 data. Take the following AWK program, for example:
BEGIN {
print substr("üu", 1, 1)
}
This prints the first character in üu
, which I would expect to be ü
. Here’s how various implementations fared:
-
mawk (Debian’s default):
�
-
nawk (the original implementation):
�
-
plan9port awk:
üu
(!) -
gawk (GNU awk):
ü
Of those, only gawk produces the answer I expected. Sadly, it’s also the slowest implementation:
- mawk: 2714 invocations in 5 seconds (faster than GNU sed!)
- plan9port awk: 2158
- gawk: 1113
Perl
Perl was designed to be (as I understand it) the ultra-AWK: just as flexible, but more powerful and more sophisticated. It has a module system, it supports object-oriented programming, it’s still under active maintenance… but for modern tastes it’s very baroque. AWK and sed have the excuse that they’re very limited languages, but Perl is vastly larger and still feels very quirky.
At least Perl is broadly available (the perl-base
package is “Priority: required” in Debian), and it has possibly the best Unicode support of any language on any platform.
Perl 5.32.1 launches 1272 times in 5 seconds, on par with gawk and just a little slower than GNU sed.
Python 3
But enough about all these archaic and crufty languages, Kakoune let’s us write plugins in any language, so why not pick something clean and modern?
Python3 is broadly available, has a decent standard library and excellent third-party library support. It’s a great fit for just about anything your Kakoune plugin needs. Python 3.9.2 launches… wait, really? Is that a typo?
Apparently, Python 3.9.2 launches 54 times in five seconds, 1/23rd the speed of Perl 5. So, uh, maybe don’t use that for any hooks that fire often.
Conclusion
AWK is a pretty decent tool for intermediate Kakoune scripting, so long as you don’t mind depending on gawk instead of “any awk”.
Otherwise, maybe it’s about time I looked into learning Perl, even though it’s so… Perly.