Skip to content

Ignore empty lines on fold, like treesitter #169

@yochem

Description

@yochem

Neovim version (nvim -v | head -n1)

NVIM v0.10.0-dev-743+g9b5f58185-Homebrew

Operating system/version

MacOS 14.0

How to reproduce the issue

  1. Use the following config for nvim-ufo (via lazy.nvim):
return {
	'kevinhwang91/nvim-ufo',
	init = function ()
		vim.keymap.set('n', 'zR', function ()
			require('ufo').openAllFolds()
		end)
		vim.keymap.set('n', 'zR', function ()
			require('ufo').closeAllFolds()
		end)
	end,
	opts = {
		provider_selector = function(bufnr, filetype, buftype)
			return {'treesitter', 'indent'}
		end
	},
	dependencies = {
		'kevinhwang91/promise-async'
	},
	event = "BufReadPost",
}
  1. Open markdown file and add something like this:
# test

test


# new header
  1. Move cursor to line under # test and fold (e.g. with zc)
  2. Notice it includes the empty lines. nvim-treesitter does not do this. It trims these emtpy lines from the region here.

Expected behavior

# test...


# new header

Expect it to use treesitter to get its folds, and thus exclude empty lines from fold. This behaviour can be seen by disabling nvim-ufo (in the lazy.nvim config above, add enabled = false). Restart nvim and run: set foldmethod=expr foldexpr=nvim_treesitter#foldexpr(). This should exclude the empty lines in the fold.

Actual behavior

# test...
# new header

It includes the empty lines in the fold.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions