How to set an option to "all other file types"?

I’d like to configure the smarttab mode using smarttab.kak. I know how to configure the mode for files of various types, but how do I set the default mode to expandtab while setting the mode to smarttab or noexpandtab for certain file types?

I tried to this and it didn’t work:

plug "andreyorst/smarttab.kak" defer smarttab %{
  # when `backspace' is pressed, 4 spaces are deleted at once
  set-option global softtabstop 4
} config %{
  hook global WinSetOption .* expandtab    # default

  ## override defaults??
  # these languages will use `noexpandtab' behavior
  hook global WinSetOption filetype=(makefile|gas) noexpandtab
  # these languages will use `smarttab' behavior
  hook global WinSetOption filetype=(c|cpp) smarttab
  # these languages will use `expandtab' behavior
  hook global WinSetOption filetype=(rust|markdown|lisp|scheme|sh|perl|purescript|elm|css|scss|html|javascript) expandtab
}

When I edit a makefile, the mode is set to expandtab instead of noexpandtab, even though the file type is correctly set to makefile.

I’m clearly missing something about how Kakoune sets options. Help!

This hook will be run on all options set on window, not only filetype:

  hook global WinSetOption .* expandtab    # default

Try changing it to:

  hook global WinSetOption filetype=.* expandtab    # default

This should be enough as hooks are run in the order they are registered.

You can debug which hooks gets run by running set window debug hooks, output is in the *debug* buffer.

1 Like

Yeah, the hook order should do the trick, just put the most specific ones last.
It’s also possible to create a regex that matches everything but some file types, like hook global WinSetOption filetype=(?!kak)(?!sh).*

3 Likes