1 local treesitter = require('nvim-treesitter')
4 install_dir = vim.fn.stdpath('data') .. '/site',
24 local function foldlevel(lnum, exclude_start)
25 if lnum < 1 or lnum > vim.api.nvim_buf_line_count(0) then
28 local value = vim.treesitter.foldexpr(lnum)
29 local level = tonumber(value:match('%d+')) or 0
30 -- A '>N' starts a new fold even when adjacent folds have the same level.
31 return math.max(0, level - (exclude_start and value:sub(1, 1) == '>' and 1 or 0))
34 function _G.DotfilesFoldExpr()
35 local line = vim.v.lnum
36 -- Keep only levels spanning the previous, current, and next lines.
37 -- Default foldminlines keeps interiors of fewer than two lines visible.
38 return math.min(foldlevel(line - 1), foldlevel(line, true), foldlevel(line + 1, true))
41 local function enable(buf)
42 vim.wo[0][0].foldexpr = '0'
43 if not pcall(vim.treesitter.start, buf) then
47 vim.wo[0][0].foldexpr = 'v:lua.DotfilesFoldExpr()'
48 vim.wo[0][0].foldmethod = 'expr'
51 vim.api.nvim_create_autocmd('FileType', {
52 callback = function(args) enable(args.buf) end,
55 -- Startup filetype detection can precede this config being sourced.
56 if vim.bo.filetype ~= '' then