Set ctags tag file path

How can I tell Kakoune to search in the current directory then the parent directories for a tags file?

This would be the same behavior as set tags=tags; in vim.

The ctagspath option looked promising, but it seems that is a parameter passed to the ctags executable.

I have this workaround for my plugin fzf.kak:

path=$PWD
while [ "$path" != "$HOME" ]; do
    if [ -e "./$kak_opt_fzf_tag_file" ]; then
        break
    else
        cd ..
        path=$PWD
    fi
done

So it basically checks each dir for tags file. If file is found I modify the ctagsfiles option like soprintf "%s\n" "set-option -add window ctagsfiles %{$path/$kak_opt_fzf_tag_file}" and executes the ctags-search command. If not it prints the warning message.

$kak_opt_fzf_tag_file is just a variable that stores the name of a tags file

Thanks for the suggestion. I tried the following in my kakrc file:

hook global WinSetOption filetype=(c|cpp) %{
    clang-enable-autocomplete
    set-option global formatcmd 'clang-format'
    %sh{
        path="$PWD"
        while [ "$path" != "$HOME" ]; do
            if [ -e "./tags" ]; then
                printf "%s\n" "set-option -add window ctagsfiles %{$path/tags}"
                break
            else
                cd ..
                path="$PWD"
            fi
        done
    }
}

But the *debug* buffer reports: error running hook WinSetOption(filetype=c)/: no such command: 'set-option -add window ctagsfiles %{/path/to/my/tags}'. This command works fine if typed verbatim into kakoune’s command line. I’ve played around with the global/buffer/window/current scope, but couldn’t get anything to work. Any ideas?

It’s correct, there is no command named set-option -add window ctagsfiles %{/path/to/my/tags} all as one word.

You probably want to use execute-commands %sh{ rather than just bare %sh{ so that Kakoune will parse the output into new commands, rather than taking the entire %sh{} output as a single string command.

Thanks, that solves it! I’m still learning the kakrc syntax.