Debug helpers: k9s0ke-dbg.kak

August vacations are over, Kakoune has a new release, and kstr0k / k9s0ke-dbg.kak · GitLab packages some of the debug commands / aliases I’ve been using while working with Kakoune. Some of them are tricky to get right, some save a lot of keystrokes over time, and some just minimize cognitive dissonance :slight_smile:

Without further ado, here’s a sampler (no aliases are installed for long-form functions by default, so as not to clash with yours; the setup instructions list the necessary init functions to call):

Display stuff

  • e'' %val{client_env_PATH} (or edit-string): open a *string* scratch buffer containing your args.
  • e* debug registers, or echo-dbg (with full command completion): capture *debug* output for specified command in an *output* scratch. When a def consistently refuses to run and produces copious *debug*, edit-dbg switches you directly to the output and can be easily repeated with :<up><ret>
  • :p %opt{ui_options} (echo-dbg-plstar): prints out compactly all args using Perl’s Data::Dumper (e.g. newlines appear as \n). Also: echo-dbg-plstar %arg{@} at the top of a def.

Define stuff

  • defp command-name %{ code-here %}: define a command that takes any number of arguments and uses its own code as a -docstring. Alias for def-params-dotdot
  • alias-args: alias not just a command (like alias), but also some prefix arguments. E.g. setg+ is defined as alias-args setg+ set -add global. Generates a hidden function helper to achieve this.

Execute stuff

  • nop-sh %{echo $1; ls $2} %val{session} .: like nop %sh{}, but takes explicit script arguments instead of deriving them implicitly from the surrounding command. Redirects stdout to stderr, so all echo / printf's output to *debug*.

In other news

I’m going to announce separately some of the stuff I’ve been working on:

  • f8ksh has a wealth of info on setting up busybox “just right” so that you get builtins for many shell external utilities (including sed, awk, and the core UNIX utils). Setting KAKOUNE_POSIX_SHELL to busybox sh halved my startup time. busybox sh also has $EPOCH_REALTIME (less-Heisenberged benchmarked), param slicing ("${@:2:1}"), substrings (${str:0:1}) and read -d '' (avoiding “$(cat)”); these features can be detected / optionally used in sh plugins.
  • t3st, a precise yet flexible TAP shell testing framework for most POSIX shells as well as bash and zsh. You can obviously test your plugin shell code, but also your plugin installation process (see the mru-files test branch).
  • many updates / optimizations for mru-files and the k9s0ke-shlib POSIX shell library (I’ve just noticed people having some issues; please, do report MRU problems / bugs)
  • sed-cached: built on top of sed-bin (which compiles sed scripts to executables), this showcases how to use the filesystem to map arbitrary cache keys to objects from simple shell scripts, which may be interesting to all of us interested in performance hacks.