Scripting Kakoune with external tools

Thanks for the suggestions and feedback, everyone!

My initial concern about Lua was that it uses 1-based indexing, but so does AWK, so I can’t complain about that anymore. :slight_smile:

My bigger worry about Lua is that, as I understand it, it’s intended to be vendored into each system that uses it, so the ecosystem is pretty lax about breaking changes. Debian offers me five separate versions of Lua (5.0, 5.1, 5.2, 5.3, 5.4), but only one version of Python (3.9), two versions of Perl (5.30 and 5.32), one version of Ruby (2.7) and one version of tcl (8.6). Also, my understanding is that Lua’s standard library is very small - if I write a plugin using Python or Perl, I can call just about every function in the C standard library and bunch of other useful stuff besides (XML, JSON, MIME, date arithmetic) without having to teach anybody about a language-specific packaging tool.

Of course, that’s not a hard rule; I hope there are and continue to be Kakoune plugins that draw deeply from CPAN and PyPI and crates.io and RubyGems and LuaRocks and NPM, but for my own plugins I want to make installation as painless as possible.

My expectation is that bash is not as widely available as one might hope; certainly it’s everywhere on Linux, but I think the BSDs hate it and macOS only ships an ancient version because Apple is terrified of GPLv3. But, I haven’t actually done a survey or anything, so maybe it would actually be practical as a plugin helper?

Whoa, that’s amazing. I hadn’t heard of hyperfine before, but it’s pretty, and it lets you benchmark shell functions! That’s pretty great.

Unfortunately it seems to gripe about timing things that take less than 5ms, which is annoying since ideally all of these interpreters would startup in less than 5ms, but at least it’s a more relatable number than “startups in 5 seconds”.

Anyway, thanks to hyperfine here’s the same interpreter startup times as before, plus the new ones people have mentioned:

Benchmark #1: bash -c ''
  Time (mean ± σ):       2.7 ms ±   0.4 ms    [User: 1.7 ms, System: 1.2 ms]
Benchmark #2: python3 -S -c ''
  Time (mean ± σ):      21.4 ms ±   0.7 ms    [User: 15.8 ms, System: 5.5 ms]
Benchmark #3: lua5.4 -e ''
  Time (mean ± σ):       2.4 ms ±   0.3 ms    [User: 1.5 ms, System: 1.1 ms]
Benchmark #4: perl -e ''
  Time (mean ± σ):       3.8 ms ±   0.4 ms    [User: 1.9 ms, System: 2.2 ms]
Benchmark #5: gawk 'BEGIN {}'
  Time (mean ± σ):       3.9 ms ±   0.4 ms    [User: 1.9 ms, System: 2.2 ms]
Benchmark #6: mawk 'BEGIN {}'
  Time (mean ± σ):       1.7 ms ±   0.3 ms    [User: 1.1 ms, System: 0.8 ms]
Benchmark #7: sed -e '' </dev/null
  Time (mean ± σ):       2.4 ms ±   0.4 ms    [User: 1.4 ms, System: 1.2 ms]
Benchmark #8: /bin/dash -c ''
  Time (mean ± σ):       1.3 ms ±   0.4 ms    [User: 1.0 ms, System: 0.6 ms]
Benchmark #9: python3 -c ''
  Time (mean ± σ):      74.5 ms ±   3.7 ms    [User: 61.7 ms, System: 11.8 ms]

Summary
  '/bin/dash -c ''' ran
    1.29 ± 0.46 times faster than 'mawk 'BEGIN {}''
    1.85 ± 0.60 times faster than 'lua5.4 -e '''
    1.85 ± 0.62 times faster than 'sed -e '' </dev/null'
    2.08 ± 0.68 times faster than 'bash -c '''
    2.90 ± 0.90 times faster than 'perl -e '''
    2.93 ± 0.93 times faster than 'gawk 'BEGIN {}''
   16.22 ± 4.85 times faster than 'python3 -S -c '''
   56.86 ± 13.73 times faster than 'python3 -c '''
3 Likes