nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.03k stars 134 forks source link

Compatibility with nvim-ufo #599

Closed Zhou-Yicheng closed 1 year ago

Zhou-Yicheng commented 1 year ago

Describe the bug

Fold automatically every time type ESC in insert mode

Steps to reproduce

  1. Install Neovim
  2. Install nvim-orgmode with nvim-ufo
  3. Setup orgmode treesitter grammar
  4. Setup UFO with folding provider of treesitter indent
  5. Run :TSUpdate org
  6. Open an org file
  7. Enter insert mode then type ESC

Expected behavior

Back to normal mode without folding

Emacs functionality

No response

Minimal init.lua

    require('orgmode').setup()
    require('orgmode').setup_ts_grammar()
    require('ufo').setup({
      provider_selector = function(bufnr, filetype, buftype)
        return { 'treesitter', 'indent' }
      end,
    })

Screenshots and recordings

No response

OS / Distro

Gentoo 2.14

Neovim version/commit

v0.9.1

Additional context

No response

m3xan1k commented 1 year ago

Experiencing same issue

orhnk commented 1 year ago

It's reproducible yes. But strangely achieves the same thing while keeping the folds there!

[!NOTE] I face this issue in general when using nvim-ufo. (e.g) undoing inside a file (not specific to .org)

PriceHiller commented 1 year ago

This is really an issue with UFO in some aspects. A good work around is to disable UFO in org buffers. I ran into this myself just now while migrating to orgmode.

Here's how I disable UFO in certain buffers:

local ft_options = {
    norg = "", -- Neorg had the same issue
    org = "" -- We "disable" ufo in org files by giving back an empty provider to UFO
}

require('ufo').setup({
    provider_selector = function(_, filetype, _)
        return ft_options[filetype] or { "treesitter", "indent" }
    end,
})

I still get folding in org files without the weird "auto-folding" going on from UFO. Recommend you give it a shot.

orhnk commented 1 year ago

@treatybreaker This didn't solve the issue on #614 Thanks for sharing anyway! but using:

vim.cmd [[setlocal nofoldenable]] -- No folds initially

disables folds. You can use it with an autocmd.

PriceHiller commented 1 year ago

@treatybreaker This didn't solve the issue on #614 Thanks for sharing anyway! but using:

vim.cmd [[setlocal nofoldenable]] -- No folds initially

disables folds. You can use it with an autocmd.

It still seems as though UFO's folds are much superior to what we get out the gate with orgmode here.

nofoldenable still leads to some folds being incorrectly calculated like in #614, UFO works around that but introduces the esc/undo bug here.

Somewhat frustrating, I think I'll set aside some time later to find the root cause.

PriceHiller commented 1 year ago

Hey @Zhou-Yicheng, @UTFeight, @m3xan1k,

With the merging of #615 UFO should play nice with Orgmode if you set org_startup_folded to inherit or showeverything.

require("orgmode").setup({
    -- ...
    org_startup_folded = "inherit"
})

Give it a shot, that fixes UFO issues for me.

orhnk commented 1 year ago

The issue solved! Thanks for the PR!