11return {
2- " kevinhwang91/nvim-ufo" ,
3- dependencies = " kevinhwang91/promise-async" ,
4- event = " VimEnter" , -- needed for folds to load in time and comments closed
5- keys = {
2+ ' kevinhwang91/nvim-ufo' ,
3+ dependencies = ' kevinhwang91/promise-async' ,
4+ event = ' VimEnter' , -- needed for folds to load in time and comments closed
5+ keys = {
66 -- stylua: ignore start
77 { " zm" , function () require (" ufo" ).closeAllFolds () end , desc = " Close All Folds" },
88 { " zr" , function () require (" ufo" ).openFoldsExceptKinds { " comment" , " imports" } end , desc = " Open All Regular Folds" },
@@ -11,58 +11,60 @@ return {
1111 { " z2" , function () require (" ufo" ).closeFoldsWith (2 ) end , desc = " Close L2 Folds" },
1212 { " z3" , function () require (" ufo" ).closeFoldsWith (3 ) end , desc = " Close L3 Folds" },
1313 { " z4" , function () require (" ufo" ).closeFoldsWith (4 ) end , desc = " Close L4 Folds" },
14- -- stylua: ignore end
15- },
16- init = function ()
17- -- INFO fold commands usually change the foldlevel, which fixes folds, e.g.
18- -- auto-closing them after leaving insert mode, however ufo does not seem to
19- -- have equivalents for zr and zm because there is no saved fold level.
20- -- Consequently, the vim-internal fold levels need to be disabled by setting
21- -- them to 99
22- vim .opt .foldlevel = 99
23- vim .opt .foldlevelstart = 99
14+ -- stylua: ignore end
15+ },
16+ init = function ()
17+ -- INFO fold commands usually change the foldlevel, which fixes folds, e.g.
18+ -- auto-closing them after leaving insert mode, however ufo does not seem to
19+ -- have equivalents for zr and zm because there is no saved fold level.
20+ -- Consequently, the vim-internal fold levels need to be disabled by setting
21+ -- them to 99
22+ vim .opt .foldlevel = 99
23+ vim .opt .foldlevelstart = 99
24+ end ,
25+ opts = {
26+ provider_selector = function (_ , ft , _ )
27+ -- INFO some filetypes only allow indent, some only LSP, some only
28+ -- treesitter. However, ufo only accepts two kinds as priority,
29+ -- therefore making this function necessary :/
30+ local lspWithOutFolding = { ' markdown' , ' sh' , ' css' , ' html' , ' python' }
31+ if vim .tbl_contains (lspWithOutFolding , ft ) then
32+ return { ' treesitter' , ' indent' }
33+ end
34+ return { ' lsp' , ' indent' }
2435 end ,
25- opts = {
26- provider_selector = function (_ , ft , _ )
27- -- INFO some filetypes only allow indent, some only LSP, some only
28- -- treesitter. However, ufo only accepts two kinds as priority,
29- -- therefore making this function necessary :/
30- local lspWithOutFolding = { " markdown" , " sh" , " css" , " html" , " python" }
31- if vim .tbl_contains (lspWithOutFolding , ft ) then return { " treesitter" , " indent" } end
32- return { " lsp" , " indent" }
33- end ,
34- -- when opening the buffer, close these fold kinds
35- -- use `:UfoInspect` to get available fold kinds from the LSP
36- close_fold_kinds_for_ft = {
37- default = { " imports" , " comment" },
38- },
39- open_fold_hl_timeout = 800 ,
40- fold_virt_text_handler = function (virtText , lnum , endLnum , width , truncate )
41- local hlgroup = " NonText"
42- local newVirtText = {}
43- local suffix = " " .. tostring (endLnum - lnum )
44- local sufWidth = vim .fn .strdisplaywidth (suffix )
45- local targetWidth = width - sufWidth
46- local curWidth = 0
47- for _ , chunk in ipairs (virtText ) do
48- local chunkText = chunk [1 ]
49- local chunkWidth = vim .fn .strdisplaywidth (chunkText )
50- if targetWidth > curWidth + chunkWidth then
51- table.insert (newVirtText , chunk )
52- else
53- chunkText = truncate (chunkText , targetWidth - curWidth )
54- local hlGroup = chunk [2 ]
55- table.insert (newVirtText , { chunkText , hlGroup })
56- chunkWidth = vim .fn .strdisplaywidth (chunkText )
57- if curWidth + chunkWidth < targetWidth then
58- suffix = suffix .. (" " ):rep (targetWidth - curWidth - chunkWidth )
59- end
60- break
61- end
62- curWidth = curWidth + chunkWidth
63- end
64- table.insert (newVirtText , { suffix , hlgroup })
65- return newVirtText
66- end ,
36+ -- when opening the buffer, close these fold kinds
37+ -- use `:UfoInspect` to get available fold kinds from the LSP
38+ close_fold_kinds_for_ft = {
39+ default = { ' imports' , ' comment' },
6740 },
41+ open_fold_hl_timeout = 800 ,
42+ fold_virt_text_handler = function (virtText , lnum , endLnum , width , truncate )
43+ local hlgroup = ' NonText'
44+ local newVirtText = {}
45+ local suffix = ' ' .. tostring (endLnum - lnum )
46+ local sufWidth = vim .fn .strdisplaywidth (suffix )
47+ local targetWidth = width - sufWidth
48+ local curWidth = 0
49+ for _ , chunk in ipairs (virtText ) do
50+ local chunkText = chunk [1 ]
51+ local chunkWidth = vim .fn .strdisplaywidth (chunkText )
52+ if targetWidth > curWidth + chunkWidth then
53+ table.insert (newVirtText , chunk )
54+ else
55+ chunkText = truncate (chunkText , targetWidth - curWidth )
56+ local hlGroup = chunk [2 ]
57+ table.insert (newVirtText , { chunkText , hlGroup })
58+ chunkWidth = vim .fn .strdisplaywidth (chunkText )
59+ if curWidth + chunkWidth < targetWidth then
60+ suffix = suffix .. (' ' ):rep (targetWidth - curWidth - chunkWidth )
61+ end
62+ break
63+ end
64+ curWidth = curWidth + chunkWidth
65+ end
66+ table.insert (newVirtText , { suffix , hlgroup })
67+ return newVirtText
68+ end ,
69+ },
6870}
0 commit comments