tmhedberg / SimpylFold

No-BS Python code folding for Vim
BSD 3-Clause "New" or "Revised" License
653 stars 57 forks source link

Folds only exist after using zx (E490: No fold found) when using "telescope" fzf plugin #130

Closed wintermute-cell closed 2 years ago

wintermute-cell commented 2 years ago

Setup

I'm running nvim v0.6.0.

The following values are inspected to be set correctly: filetype=python foldexpr=SimpylFold#FoldExpr(v:lnum) foldmethod=expr

:scriptnames contains (among unrelated others):

~/.dotfiles/nvim/.config/nvim/plugged/SimpylFold/ftplugin/python/SimpylFold.vim
~/.dotfiles/nvim/.config/nvim/plugged/SimpylFold/autoload/SimpylFold.vim

I have done no SimpylFold related configuration (not necessary afaik?).

Problem

When opening a .py file in nvim, and trying to toggle a fold with za (or using zo, zc, etc..), no folding occurs, but nvim prints the error E490: No fold found. After using zx, all possible folds become folded, except the one where the cursor is located at. After this, folding with za works as intended.

EDIT: (I'm dumb not to test this earlier) The issue only occurs when opening a file through telescope (https://github.com/nvim-telescope/telescope.nvim). What could be going wrong here?

tmhedberg commented 2 years ago

This appears to be a bug in Telescope: https://github.com/nvim-telescope/telescope.nvim/issues/1277.

As a temporary workaround, maybe you could add an autocommand that updates folds after the file is loaded:

autocmd BufRead *.py normal zx

or perhaps

autocmd FileType python normal zx

I don't use nvim, nor am I familiar with Telescope, so it's not easy for me to test this myself, but something like that may help if you can't live with typing zx manually.

wintermute-cell commented 2 years ago

Knowing that's an active bug with telescope is answer enough for me! Thank you for finding the telescope issue that i apparently couldn't find, and I'll try out your temporary solution asap.

wintermute-cell commented 2 years ago

autocmd BufRead *.py normal zx zR works perfectly, opening the file with all folds open. Thanks again!

danielnehrig commented 2 years ago
  telescope.setup({
    pickers = {
      find_files = {
        hidden = true,
        attach_mappings = function(_)
          action_set.select:enhance({
            post = function()
              vim.cmd(":normal! zx")
            end,
          })
          return true
        end,
      },
    },
...
anuvyklack commented 2 years ago

@danielnehrig your solution, unfortunately, does not work.

anuvyklack commented 2 years ago

The solution I use:

autocmd BufRead * autocmd BufWinEnter * ++once normal! zx

or the same but with new autocmd API:

vim.api.nvim_create_autocmd('BufRead', {
   callback = function()
      vim.api.nvim_create_autocmd('BufWinEnter', {
         once = true,
         command = 'normal! zx'
      })
   end
})

BufWinEnter needed to take into account the modeline settings. And why it not used alone but after BufRead, because BufWinEnter need to be executed only once for each buffer.