Fzf but without fzf.kak

There was an issue on fzf.kak, and there was this comment. Just thought about this way of using fzf inside Kakoune:

define-command fzf %{ evaluate-commands %{
    edit -scratch *fzf*
    map buffer normal '<ret>' ': fzf-operate edit<ret>'
    execute-keys -draft -buffer '*fzf*' '%d'
    fzf-prompt
}}

define-command fzf-prompt %{
    prompt "fzf: " -on-change %{
        execute-keys -draft '%d'
        execute-keys -draft "! find . | fzf -f %val{text}<ret>"
    } nop
}

define-command fzf-operate -params 1 %{ evaluate-commands -save-regs 'a' %{
    execute-keys <a-h><a-l>"ay
    evaluate-commands %sh{
        candidate=$(printf "$kak_reg_a" | sed "s/&/&&/g")
        case $1 in
            (edit) printf "%s\n" "edit -existing %&$candidate&" ;;
            (*) printf "%s\n" "fail %{Wrong command}" ;;
        esac
    }
}}

fzf is used as a filter and invoked on every key press. This way there’s no need for TMUX or terminal command to handle fzf. Maybe there’s another apps that could be used this way, via prompt command.

Cool! :sunglasses: Inspired by Turn Your fzf Into a Live REPL :: paweldu.dev — Pawel Duda's personal site and this one can make a live repl for for example python by changing fzf-prompt like so:

define-command fzf-prompt %{
    prompt "fzf: " -on-change %{
        reg c %val{text}
        execute-keys -draft '%d'
        execute-keys -draft '"cp'
        execute-keys -draft '%|python - 2>&1<ret>'
    } nop
}

edit: moved the errors from stderr to stdout instead of them ending up in *debug* buffer