Getting the current file path to set `formatcmd`

Hi, beginner question:

I’m trying to set formatcmd to be fourmolu -stdin-input-file [name-of-current-file]. [name-of-current-file] should be replaced by the full filename (including the path) of the currently edited file, whenever I invoke the :format command from Kakoune.

I preferably want to do this in a .kakrc.local file, which I’m sourcing if it exists:

      # Try loading local Kakoune config.
      try %{ source .kakrc.local }

Currently, I have the following in my .kakrc.local:

hook global WinSetOption filetype=(haskell) %{
  set-option window formatcmd "fourmolu --stdin-input-file xyz"
}

What should I place instead of xyz to make this work? :confused:

OK, found the answer myself:

hook global WinSetOption filetype=(haskell) %{
  set-option window formatcmd "fourmolu --stdin-input-file %val{buffile}"
}

seems to work :duck:.

2 Likes