ci: format
This commit is contained in:
parent
9af6086959
commit
d06731a7fd
2 changed files with 47 additions and 11 deletions
|
|
@ -94,7 +94,9 @@ end
|
|||
|
||||
---@return nil
|
||||
function M.persist_folds()
|
||||
log.debug(('persist_folds: view=%s store=%s'):format(tostring(current_view), tostring(_store ~= nil)))
|
||||
log.debug(
|
||||
('persist_folds: view=%s store=%s'):format(tostring(current_view), tostring(_store ~= nil))
|
||||
)
|
||||
if current_view ~= 'category' or not _store then
|
||||
log.debug('persist_folds: early return (view or store)')
|
||||
return
|
||||
|
|
@ -107,14 +109,27 @@ function M.persist_folds()
|
|||
local folded = {}
|
||||
local seen = {}
|
||||
local wins = vim.fn.win_findbuf(bufnr)
|
||||
log.debug(('persist_folds: checking %d windows for bufnr=%d, meta has %d entries'):format(#wins, bufnr, #_meta))
|
||||
log.debug(
|
||||
('persist_folds: checking %d windows for bufnr=%d, meta has %d entries'):format(
|
||||
#wins,
|
||||
bufnr,
|
||||
#_meta
|
||||
)
|
||||
)
|
||||
for _, winid in ipairs(wins) do
|
||||
if vim.api.nvim_win_is_valid(winid) then
|
||||
vim.api.nvim_win_call(winid, function()
|
||||
for lnum, m in ipairs(_meta) do
|
||||
if m.type == 'header' and m.category and not seen[m.category] then
|
||||
local closed = vim.fn.foldclosed(lnum)
|
||||
log.debug(('persist_folds: win=%d lnum=%d cat=%s foldclosed=%d'):format(winid, lnum, m.category, closed))
|
||||
log.debug(
|
||||
('persist_folds: win=%d lnum=%d cat=%s foldclosed=%d'):format(
|
||||
winid,
|
||||
lnum,
|
||||
m.category,
|
||||
closed
|
||||
)
|
||||
)
|
||||
if closed ~= -1 then
|
||||
seen[m.category] = true
|
||||
table.insert(folded, m.category)
|
||||
|
|
@ -124,7 +139,9 @@ function M.persist_folds()
|
|||
end)
|
||||
end
|
||||
end
|
||||
log.debug(('persist_folds: saving %d folded categories: %s'):format(#folded, table.concat(folded, ', ')))
|
||||
log.debug(
|
||||
('persist_folds: saving %d folded categories: %s'):format(#folded, table.concat(folded, ', '))
|
||||
)
|
||||
_store:set_folded_categories(folded)
|
||||
end
|
||||
|
||||
|
|
@ -335,20 +352,35 @@ local function snapshot_folds(bufnr)
|
|||
end
|
||||
|
||||
local function restore_folds(bufnr)
|
||||
log.debug(('restore_folds: view=%s folding_enabled=%s'):format(
|
||||
tostring(current_view), tostring(config.resolve_folding().enabled)))
|
||||
log.debug(
|
||||
('restore_folds: view=%s folding_enabled=%s'):format(
|
||||
tostring(current_view),
|
||||
tostring(config.resolve_folding().enabled)
|
||||
)
|
||||
)
|
||||
if current_view ~= 'category' or not config.resolve_folding().enabled then
|
||||
return
|
||||
end
|
||||
for _, winid in ipairs(vim.fn.win_findbuf(bufnr)) do
|
||||
local state = _fold_state[winid]
|
||||
_fold_state[winid] = nil
|
||||
log.debug(('restore_folds: win=%d has_fold_state=%s initial_loaded=%s has_store=%s'):format(
|
||||
winid, tostring(state ~= nil), tostring(_initial_fold_loaded), tostring(_store ~= nil)))
|
||||
log.debug(
|
||||
('restore_folds: win=%d has_fold_state=%s initial_loaded=%s has_store=%s'):format(
|
||||
winid,
|
||||
tostring(state ~= nil),
|
||||
tostring(_initial_fold_loaded),
|
||||
tostring(_store ~= nil)
|
||||
)
|
||||
)
|
||||
if not state and not _initial_fold_loaded and _store then
|
||||
_initial_fold_loaded = true
|
||||
local cats = _store:get_folded_categories()
|
||||
log.debug(('restore_folds: loaded %d categories from store: %s'):format(#cats, table.concat(cats, ', ')))
|
||||
log.debug(
|
||||
('restore_folds: loaded %d categories from store: %s'):format(
|
||||
#cats,
|
||||
table.concat(cats, ', ')
|
||||
)
|
||||
)
|
||||
if #cats > 0 then
|
||||
state = {}
|
||||
for _, cat in ipairs(cats) do
|
||||
|
|
|
|||
|
|
@ -272,8 +272,12 @@ function M._setup_autocmds(bufnr)
|
|||
group = group,
|
||||
callback = function()
|
||||
local bnr = buffer.bufnr()
|
||||
log.debug(('VimLeavePre: bufnr=%s valid=%s'):format(
|
||||
tostring(bnr), tostring(bnr and vim.api.nvim_buf_is_valid(bnr))))
|
||||
log.debug(
|
||||
('VimLeavePre: bufnr=%s valid=%s'):format(
|
||||
tostring(bnr),
|
||||
tostring(bnr and vim.api.nvim_buf_is_valid(bnr))
|
||||
)
|
||||
)
|
||||
if bnr and vim.api.nvim_buf_is_valid(bnr) then
|
||||
buffer.persist_folds()
|
||||
get_store():save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue