summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-fold.lua
blob: f88761408128b81caf912e15618b6adfa25191d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
--
-- 50-fold.lua
--
-- * Creates an autocommand to fold with treesitter automatically and close all folds on 'FileType'.
-- * Sets 'foldlevel' to 99 so that new text will not fold while editing.
--

local function fold_with_treesitter()
	if vim.api.nvim_win_get_config(0).relative ~= "" or vim.treesitter.get_parser(0) == nil then
		return
	end
	vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()"
	vim.opt_local.foldmethod = "expr"
	vim.cmd("silent! %foldclose!")
end

----------------------------------------------------------------------------------------------------

vim.api.nvim_create_autocmd("FileType", {
	desc = "Initialize folds",
	group = vim.g.dotfiles.augroup,
	callback = fold_with_treesitter,
})

vim.opt.foldenable = true
vim.opt.foldlevel = 99