@@ -1241,7 +1241,7 @@ H.clean_confirm = function(paths)
1241
1241
if # paths_to_delete == 0 then return H .notify (' Nothing to delete' ) end
1242
1242
H .clean_delete (paths_to_delete )
1243
1243
end
1244
- H .show_confirm_buf (lines , ' mini-deps://confirm-clean' , finish_clean )
1244
+ H .show_confirm_buf (lines , { name = ' mini-deps://confirm-clean' , exec_on_write = finish_clean } )
1245
1245
1246
1246
-- Define basic highlighting
1247
1247
vim .cmd (' syntax region MiniDepsHint start="^\\ %1l" end="\\ %' .. n_header .. ' l$"' )
@@ -1364,25 +1364,11 @@ H.update_feedback_confirm = function(lines)
1364
1364
MiniDeps .update (names , { force = true , offline = true })
1365
1365
end
1366
1366
1367
- H .show_confirm_buf (report , ' mini-deps://confirm-update' , finish_update )
1367
+ H .show_confirm_buf (report , { name = ' mini-deps://confirm-update' , exec_on_write = finish_update , setup_folds = true } )
1368
1368
1369
1369
-- Define basic highlighting
1370
1370
vim .cmd (' syntax region MiniDepsHint start="^\\ %1l" end="\\ %' .. n_header .. ' l$"' )
1371
1371
H .update_add_syntax ()
1372
-
1373
- -- Enable folding
1374
- local is_title = function (l ) return l :find (' ^%-%-%-' ) or l :find (' ^%+%+%+' ) or l :find (' ^%!%!%!' ) end
1375
- -- stylua: ignore
1376
- MiniDeps ._confirm_foldexpr = function (lnum )
1377
- if lnum == 1 then return 0 end
1378
- if is_title (vim .fn .getline (lnum - 1 )) then return 1 end
1379
- if is_title (vim .fn .getline (lnum + 1 )) then return 0 end
1380
- return ' ='
1381
- end
1382
- -- - Use `:setlocal` for these options to not be inherited if some other
1383
- -- buffer is opened in the same window.
1384
- vim .cmd (' setlocal foldenable foldmethod=expr foldlevel=999' )
1385
- vim .cmd (' setlocal foldexpr=v:lua.MiniDeps._confirm_foldexpr(v:lnum)' )
1386
1372
end
1387
1373
1388
1374
H .update_add_syntax = function ()
@@ -1411,13 +1397,12 @@ H.update_feedback_log = function(lines)
1411
1397
end
1412
1398
1413
1399
-- Confirm --------------------------------------------------------------------
1414
- H .show_confirm_buf = function (lines , name , exec_on_write )
1400
+ H .show_confirm_buf = function (lines , opts )
1415
1401
-- Show buffer
1416
1402
local buf_id = vim .api .nvim_create_buf (true , true )
1417
- H .buf_set_name (buf_id , name )
1403
+ H .buf_set_name (buf_id , opts . name )
1418
1404
vim .api .nvim_buf_set_lines (buf_id , 0 , - 1 , false , lines )
1419
1405
vim .cmd (' tab sbuffer ' .. buf_id )
1420
- vim .bo .buftype , vim .bo .filetype , vim .bo .modified = ' acwrite' , ' minideps-confirm' , false
1421
1406
local tab_num , win_id = vim .api .nvim_tabpage_get_number (0 ), vim .api .nvim_get_current_win ()
1422
1407
1423
1408
local delete_buffer = vim .schedule_wrap (function ()
@@ -1426,10 +1411,27 @@ H.show_confirm_buf = function(lines, name, exec_on_write)
1426
1411
vim .cmd (' redraw' )
1427
1412
end )
1428
1413
1414
+ -- Define folding
1415
+ local is_title = function (l ) return l :find (' ^%-%-%-' ) or l :find (' ^%+%+%+' ) or l :find (' ^%!%!%!' ) end
1416
+ -- stylua: ignore
1417
+ MiniDeps ._confirm_foldexpr = function (lnum )
1418
+ if lnum == 1 then return 0 end
1419
+ if is_title (vim .fn .getline (lnum - 1 )) then return 1 end
1420
+ if is_title (vim .fn .getline (lnum + 1 )) then return 0 end
1421
+ return ' ='
1422
+ end
1423
+
1424
+ -- Possibly set up folding. Use `:setlocal` for these options to not be
1425
+ -- inherited if some other buffer is opened in the same window.
1426
+ if opts .setup_folds then
1427
+ vim .cmd (' setlocal foldenable foldmethod=expr foldlevel=999' )
1428
+ vim .cmd (' setlocal foldexpr=v:lua.MiniDeps._confirm_foldexpr(v:lnum)' )
1429
+ end
1430
+
1429
1431
-- Define action on accepting confirm
1430
1432
local finish = function ()
1431
1433
MiniDeps ._confirm_foldexpr = nil
1432
- exec_on_write (buf_id )
1434
+ opts . exec_on_write (buf_id )
1433
1435
delete_buffer ()
1434
1436
end
1435
1437
-- - Use `nested` to allow other events (`WinEnter` for 'mini.statusline')
@@ -1444,6 +1446,9 @@ H.show_confirm_buf = function(lines, name, exec_on_write)
1444
1446
delete_buffer ()
1445
1447
end
1446
1448
cancel_au_id = vim .api .nvim_create_autocmd (' WinClosed' , { nested = true , callback = on_cancel })
1449
+
1450
+ -- Set buffer-local options last (so that user autocmmands could override)
1451
+ vim .bo .buftype , vim .bo .filetype , vim .bo .modified = ' acwrite' , ' minideps-confirm' , false
1447
1452
end
1448
1453
1449
1454
-- CLI ------------------------------------------------------------------------
0 commit comments