Enabling something (like kak-lsp) for a filetype while disabling it for specific files

I have a few language-specific tools that I have enabled for their associated filetype using the WinSetOption hook.


    hook global WinSetOption filetype=(clojure) %{
        parinfer-enable-window -smart

But there are specific config files (in this example, project.clj) that I’d like to disable the tool for. Is there a recommended way to do this?

I started typing this as a question, but think I figured it out while typing…

hook global WinSetOption filetype=(clojure|lisp|scheme|racket) %{
    evaluate-commands %sh{
        if ! expr $kak_buffile : $special_files_regex 1>/dev/null; then
            printf %s 'parinfer-enable-window -smart'

The key pieces here are:

  • A shell block for the conditional (if) expression
  • The $kak_buffile variable that gives us the file name (with the full path)
  • The expr command to match the filename(s) I want to ignore via regex
    • This took me quite a bit of digging to figure out (how to check if a string matches a regex in a posix shell), and would likely be useful for other cases

Congratulations on getting it working!

A piece of advice for the future, though: although that probably is the best way to match a full regex against a string, the shell has another pattern-matching system that’s more natural to work with: globs, the same patterns used in commands like ls *.clj.

For example:

case "$kak_buffile" in
        # we don't want to do anything for these files
        printf %s 'parinfer-enable-window -smart'