orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

Folding is not respected when using `org_move_subtree_up` or `org_move_subtree_down`

Open lyz-code opened this issue 10 months ago • 6 comments

Describe the bug

When moving headlines with those bindings the foldings are not respected

Steps to reproduce

Using the next file as a base:

* heading 1
** subheading 2
** subheading 3
*** subsubheading 1
    text
**** subsubsubheading1
    text
  • If you unfold the first level and use org_move_subtree_up on the subheading 3, it will move the headline but it will fold everything so that you only see heading 1
  • If you show the folds below subheading 3 (but not enough to see subsubsubheading1) and use org_move_subtree_down, then all folds are open:

Image

Expected behavior

Folds are respected when moving headlines around

Emacs functionality

No response

Minimal init.lua

local tmp_dir = vim.env.TMPDIR or vim.env.TMP or vim.env.TEMP or "/tmp"
local nvim_root = tmp_dir .. "/nvim_orgmode"
local lazy_root = nvim_root .. "/lazy"
local lazypath = lazy_root .. "/lazy.nvim"

for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = nvim_root .. "/" .. name
end

-- Install lazy.nvim if not already installed
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-orgmode/orgmode",
		event = "VeryLazy",
		ft = { "org" },
		config = function()
			require("orgmode").setup({
				org_agenda_files = {
					"*.org",
				},
			})
		end,
	},
}, {
	root = lazy_root,
	lockfile = nvim_root .. "/lazy.json",
	install = {
		missing = false,
	},
})

require("lazy").sync({
	wait = true,
	show = false,
})

Screenshots and recordings

No response

OS / Distro

Linux

Neovim version/commit

0.10.4

Additional context

No response

lyz-code avatar Feb 07 '25 12:02 lyz-code

Does it set up folds correctly after you recalculate them after with zx ? This is a common Neovim issue. When Things are moved around, recalculating folds is often necessary.

kristijanhusak avatar Feb 07 '25 14:02 kristijanhusak

Not perfectly but it does improve it a little bit. The problem is when you want to move a heading several steps up or down. You can always cut and paste it but still.

I'm fine with closing it if you feel it's a neovim issue

lyz-code avatar Feb 07 '25 16:02 lyz-code

Yes, it's usually a Neovim issue. If you check the docs https://neovim.io/doc/user/fold.html#zx, it mentions this issue:

Also forces recomputing folds. This is useful when using 'foldexpr' and the buffer is changed in a way that results in folds not to be updated properly.

kristijanhusak avatar Feb 07 '25 16:02 kristijanhusak

@lyz-code PR that maybe fixes this issue is merged. Can you give it another test with latest master? Thanks!

kristijanhusak avatar Sep 03 '25 13:09 kristijanhusak

Sadly it doesn't :( I've tried with the latest commit (994bb0f) with both nvim v0.11.3 and v0.12.0-dev-959+g9139c4f90f

The outcome is the same as above.

lyz-code avatar Sep 07 '25 20:09 lyz-code

@kristijanhusak I'm still facing the issue and it's driving me mad... I have to reopen the file continuously. Doesn't this happen to you?

It also happens when I remove some lines (I have not yet captured the exact actions that do this, but is quite often)

Is there anyway I can help to fix the bug?

lyz-code avatar Oct 16 '25 22:10 lyz-code