andreyorst / fzf.kak

FZF for Kakoune
MIT License
143 stars 33 forks source link

Grep with skim inserts characters and messes with buffers #92

Closed jtrees closed 3 years ago

jtrees commented 3 years ago

Problem description

Steps to reproduce

  1. cd $(mktemp -d)
  2. echo "alice\nbob\ncharlie" > foo.txt
  3. kak
  4. Invoke interactive grep with skim
  5. Type char<ret>

What should happen

What happens instead

Environment information

Kakoune version: Kakoune v2020.09.01 OS version: NixOS 21.05 sh executable version: GNU bash, version 4.4.23(1)-release (x86_64-unknown-linux-gnu) zsh version*: zsh 5.8 (x86_64-pc-linux-gnu) fzf version: 0.27.1 sk version: 0.9.4 rg version: 12.1.1

* I open kakoune from zsh, not sure if that matters.

EDIT: Added rg version.

andreyorst commented 3 years ago
  • I open kakoune from zsh, not sure if that matters.

This should not matter if you set KAKOUNE_POSIX_SHELL environment variable or if your sh simlinked to bash.

The buffer is modified. The first line looks like this: harliegxvclice

This is definitively unexpected. I'll try to look into this at the weekend.

andreyorst commented 3 years ago

Sorry, wasn't able to look at it during past weekend.

I've tried this now, and I can't reproduce the bug:

https://asciinema.org/a/zET23SMUJycvZal3XhCHjFfdU

Can you provide a bit more details on your configuration? A fzf.kak config for example, or better a minimal kakrc, which reproduces this bug?

jtrees commented 3 years ago

Ah, the minimal kakrc was a good idea. I was able to identify the problematic config and found a workaround too:

source "%val{config}/plugins/plug.kak/rc/plug.kak"

plug "andreyorst/fzf.kak" defer fzf-sk-grep %{
  set-option global fzf_sk_grep_command "rg"
}

To be honest, I don't really understand why the config shouldn't be deferred. According to the docs...

Each .kak file provides a Kakoune module, so any settings which alter variable values should be wrapped in ModuleLoaded hook.

... which I thought I was doing.

And it seems weird to me that setting the config too late or too early should result in this behaviour anyway. If that's really the issue shouldn't I just end up with the default grep command instead? It's all very strange...

EDIT: Oops, turns out the "workaround" I thought I found really did just leave me with the default grep command. Seems the issue is with the grep command itself.

EDIT 2: Found an even shorter config to reproduce.

jtrees commented 3 years ago

Oooooh. The real issue was that I wasn't outputting the line number in the grep command. rg -n works as expected.

Sorry for wasting your time.

jtrees commented 3 years ago

Thanks again for looking in to this and getting me on the right track.

andreyorst commented 3 years ago

Sorry for wasting your time.

It's ok :)

I still wonder why this changed the buffer, contents, might need a better guard somewhere, that verifies that grep results are correctly formatted. But I'm glad that this is fixed for you now