gustavo-hms / peneira

A fuzzy finder crafted for Kakoune
GNU Lesser General Public License v2.1
35 stars 6 forks source link

Error when creating example buffer command #1

Closed jaredramirez closed 3 years ago

jaredramirez commented 3 years ago

Hey, first off this is super cool!

When I copy/paste the sample buffer code into my kakrc

peneira 'buffers: ' %{ printf '%s\n' $kak_quoted_buflist } %{
    buffer %arg{1}
}

I get the following error in the debug buffer:

config.kakrc:170:1: 'peneira' 5:5: 'lua' 1:2: 'eval' 1:1: 'peneira-finder' 37:5: 'peneira-fill-buffer' 3:5: 'execute-keys' no input handler in context
kakrc:29:1: 'evaluate-commands' 143:1: 'source' 170:1: 'peneira' 5:5: 'lua' 1:2: 'eval' 1:1: 'peneira-finder' 37:5: 'peneira-fill-buffer' 3:5: 'execute-keys' no input handler in context
error while parsing kakrc:
    1:1: 'source' 29:1: 'evaluate-commands' 143:1: 'source' 170:1: 'peneira' 5:5: 'lua' 1:2: 'eval' 1:1: 'peneira -finder' 37:5: 'peneira-fill-buffer' 3:5: 'execute-keys' no input handler in context

I don't think it's a problem with installed luar/peneira, as using peneira-files works completely fine. Here's the relevant part of my kakrc:

require-module luar
require-module peneira
set-option global peneira_files_command "rg --files --hidden"
map global normal <c-p> ': peneira-files<ret>' -docstring 'search files'
peneira 'buffers: ' %{ printf '%s\n' $kak_quoted_buflist } %{
    buffer %arg{1}
}
gustavo-hms commented 3 years ago

Hi, @jaredramirez ! I'm glad you like it!

When you call the peneira command, it executes the filter immediately. That means that, by calling peneira at your kakrc, it will be executed at startup, before any buffer or prompt or window is created. That explains the error message:

no input handler in context

It's still too early in Kakoune startup. Actually, it's supposed to be called the very moment you want to switch to a buffer. You can do that either by hand at the prompt or you can define a mapping:

define-command peneira-buffers %{
    peneira 'buffers: ' %( printf '%s\n' $kak_quoted_buflist ) %{
        buffer %arg{1}
    }
}

map global normal <c-b> ': peneira-buffers<ret>'

Please, tell me if it solves your problem.

Anyway, I do realise the docs can induce this kind of mistake, so I'm gonna update it. Thanks!

jaredramirez commented 3 years ago

ah, totally makes sense. Thank you!