Skip to content

Commit 3ab5177

Browse files
committed
(mini.deps) Introduce folds in update confirmation buffer.
1 parent 6a1a442 commit 3ab5177

6 files changed

+223
-95
lines changed

lua/mini/deps.lua

+18-1
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ H.update_feedback_confirm = function(lines)
13431343
"Line `!!! <plugin_name> !!!` means plugin had an error and won't be updated.",
13441344
'See error details below it.',
13451345
'',
1346+
'Use regular fold keys (`zM`, `zR`, etc.) to manage shorter view.',
13461347
'To finish update, write this buffer (for example, with `:write` command).',
13471348
'To cancel update, close this window (for example, with `:close` command).',
13481349
'',
@@ -1368,6 +1369,20 @@ H.update_feedback_confirm = function(lines)
13681369
-- Define basic highlighting
13691370
vim.cmd('syntax region MiniDepsHint start="^\\%1l" end="\\%' .. n_header .. 'l$"')
13701371
H.update_add_syntax()
1372+
1373+
-- Enable folding
1374+
--stylua: ignore
1375+
MiniDeps._confirm_foldexpr = function(lnum)
1376+
local l, l_next = vim.fn.getline(lnum), vim.fn.getline(lnum + 1)
1377+
-- Not fold plugin titles and line before it
1378+
local is_not_in_fold = l:find('^%-%-%-') or l:find('^%+%+%+') or l:find('^%!%!%!')
1379+
or l_next:find('^%-%-%-') or l_next:find('^%+%+%+') or l_next:find('^%!%!%!')
1380+
return is_not_in_fold and 0 or 1
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)')
13711386
end
13721387

13731388
H.update_add_syntax = function()
@@ -1402,7 +1417,7 @@ H.show_confirm_buf = function(lines, name, exec_on_write)
14021417
H.buf_set_name(buf_id, name)
14031418
vim.api.nvim_buf_set_lines(buf_id, 0, -1, false, lines)
14041419
vim.cmd('tab sbuffer ' .. buf_id)
1405-
vim.bo[buf_id].buftype, vim.bo[buf_id].filetype, vim.bo[buf_id].modified = 'acwrite', 'minideps-confirm', false
1420+
vim.bo.buftype, vim.bo.filetype, vim.bo.modified = 'acwrite', 'minideps-confirm', false
14061421
local tab_num, win_id = vim.api.nvim_tabpage_get_number(0), vim.api.nvim_get_current_win()
14071422

14081423
local delete_buffer = vim.schedule_wrap(function()
@@ -1413,6 +1428,7 @@ H.show_confirm_buf = function(lines, name, exec_on_write)
14131428

14141429
-- Define action on accepting confirm
14151430
local finish = function()
1431+
MiniDeps._confirm_foldexpr = nil
14161432
exec_on_write(buf_id)
14171433
delete_buffer()
14181434
end
@@ -1422,6 +1438,7 @@ H.show_confirm_buf = function(lines, name, exec_on_write)
14221438
-- Define action to cancel confirm
14231439
local cancel_au_id
14241440
local on_cancel = function(data)
1441+
MiniDeps._confirm_foldexpr = nil
14251442
if tonumber(data.match) ~= win_id then return end
14261443
pcall(vim.api.nvim_del_autocmd, cancel_au_id)
14271444
delete_buffer()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--|---------|---------|---------|---------|---------|---------|
2+
01| [No Name] m//confirm-update X
3+
02| >> This is a confirmation report before an update.········
4+
03|
5+
04|!!! plugin_3 !!!
6+
05| >> ·······················································
7+
06|
8+
07|+++ plugin_2 +++
9+
08| >> Path: MOCKDIR/pack/deps/opt/plugin_2···········
10+
09|
11+
10|--- plugin_1 ---
12+
11| >> Path: MOCKDIR/pack/deps/opt/plugin_1·················
13+
12|~
14+
13|~
15+
14|~
16+
15|
17+
18+
--|---------|---------|---------|---------|---------|---------|
19+
01|000000000001111111111111111111000000000000000000000000000000
20+
02|222222222222222222222222222222222222222222222222222222222222
21+
03|333333333333333333333333333333333333333333333333333333333333
22+
04|444444444444444433333333333333333333333333333333333333333333
23+
05|222222222222222222222222222222222222222222222222222222222222
24+
06|333333333333333333333333333333333333333333333333333333333333
25+
07|555555555555555533333333333333333333333333333333333333333333
26+
08|222222222222222222222222222222222222222222222222222222222222
27+
09|333333333333333333333333333333333333333333333333333333333333
28+
10|666666666666666633333333333333333333333333333333333333333333
29+
11|222222222222222222222222222222222222222222222222222222222222
30+
12|777777777777777777777777777777777777777777777777777777777777
31+
13|777777777777777777777777777777777777777777777777777777777777
32+
14|777777777777777777777777777777777777777777777777777777777777
33+
15|888888888888888888888888888888888888888888888888888888888888

tests/screenshots/tests-test_deps.lua---update()---can-work-with-non-default-branches

+34-30
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
11|Line `!!! <plugin_name> !!!` means plugin had an error and won't be updated.
1313
12|See error details below it.
1414
13|
15-
14|To finish update, write this buffer (for example, with `:write` command).
16-
15|To cancel update, close this window (for example, with `:close` command).
17-
16|
18-
17|+++ plugin_1 +++
19-
18|Path: MOCKDIR/pack/deps/opt/plugin_1
20-
19|Source: https://github.com/user/plugin_1
21-
20|State before: sha1head
22-
21|State after: new1head (hello)
23-
22|
24-
23|Pending updates from `hello`:
25-
24|> new1head | 2024-01-02 01:01:01 +0200 | Neo McVim
26-
25| Added commit in checkout.
27-
26|
28-
27|Monitor updates from `world`:
29-
28|> new2head | 2024-01-02 02:02:02 +0200 | Neo McVim
30-
29| Added commit in monitor.
31-
30|
15+
14|Use regular fold keys (`zM`, `zR`, etc.) to manage shorter view.
16+
15|To finish update, write this buffer (for example, with `:write` command).
17+
16|To cancel update, close this window (for example, with `:close` command).
18+
17|
19+
18|+++ plugin_1 +++
20+
19|Path: MOCKDIR/pack/deps/opt/plugin_1
21+
20|Source: https://github.com/user/plugin_1
22+
21|State before: sha1head
23+
22|State after: new1head (hello)
24+
23|
25+
24|Pending updates from `hello`:
26+
25|> new1head | 2024-01-02 01:01:01 +0200 | Neo McVim
27+
26| Added commit in checkout.
28+
27|
29+
28|Monitor updates from `world`:
30+
29|> new2head | 2024-01-02 02:02:02 +0200 | Neo McVim
31+
30| Added commit in monitor.
32+
31|~
33+
32|
3234

3335
--|---------|---------|---------|---------|---------|---------|---------|---------|
3436
01|00000000000111111111111111111100000000000000000000000000000000000000000000000000
@@ -44,20 +46,22 @@
4446
11|22222222222222222222222222222222222222222222222222222222222222222222222222223333
4547
12|22222222222222222222222222233333333333333333333333333333333333333333333333333333
4648
13|33333333333333333333333333333333333333333333333333333333333333333333333333333333
47-
14|22222222222222222222222222222222222222222222222222222222222222222222222223333333
49+
14|22222222222222222222222222222222222222222222222222222222222222223333333333333333
4850
15|22222222222222222222222222222222222222222222222222222222222222222222222223333333
49-
16|33333333333333333333333333333333333333333333333333333333333333333333333333333333
50-
17|44444444444444443333333333333333333333333333333333333333333333333333333333333333
51-
18|33333333333333555555555555555555555555555555333333333333333333333333333333333333
52-
19|33333333333333555555555555555555555555555555553333333333333333333333333333333333
53-
20|33333333333333555555553333333333333333333333333333333333333333333333333333333333
54-
21|33333333333333555555553222222233333333333333333333333333333333333333333333333333
55-
22|33333333333333333333333333333333333333333333333333333333333333333333333333333333
51+
16|22222222222222222222222222222222222222222222222222222222222222222222222223333333
52+
17|33333333333333333333333333333333333333333333333333333333333333333333333333333333
53+
18|44444444444444443333333333333333333333333333333333333333333333333333333333333333
54+
19|33333333333333555555555555555555555555555555333333333333333333333333333333333333
55+
20|33333333333333555555555555555555555555555555553333333333333333333333333333333333
56+
21|33333333333333555555553333333333333333333333333333333333333333333333333333333333
57+
22|33333333333333555555553222222233333333333333333333333333333333333333333333333333
5658
23|33333333333333333333333333333333333333333333333333333333333333333333333333333333
57-
24|66666666666666666666666666666666666666666666666666333333333333333333333333333333
58-
25|33333333333333333333333333333333333333333333333333333333333333333333333333333333
59+
24|33333333333333333333333333333333333333333333333333333333333333333333333333333333
60+
25|66666666666666666666666666666666666666666666666666333333333333333333333333333333
5961
26|33333333333333333333333333333333333333333333333333333333333333333333333333333333
6062
27|33333333333333333333333333333333333333333333333333333333333333333333333333333333
61-
28|66666666666666666666666666666666666666666666666666333333333333333333333333333333
62-
29|33333333333333333333333333333333333333333333333333333333333333333333333333333333
63-
30|77777777777777777777777777777777777777777777777777777777777777777777777777777777
63+
28|33333333333333333333333333333333333333333333333333333333333333333333333333333333
64+
29|66666666666666666666666666666666666666666666666666333333333333333333333333333333
65+
30|33333333333333333333333333333333333333333333333333333333333333333333333333333333
66+
31|77777777777777777777777777777777777777777777777777777777777777777777777777777777
67+
32|88888888888888888888888888888888888888888888888888888888888888888888888888888888

tests/screenshots/tests-test_deps.lua---update()---shows-empty-monitor-log

+26-22
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
11|Line `!!! <plugin_name> !!!` means plugin had an error and won't be updated.
1313
12|See error details below it.
1414
13|
15-
14|To finish update, write this buffer (for example, with `:write` command).
16-
15|To cancel update, close this window (for example, with `:close` command).
17-
16|
18-
17|--- plugin_1 ---
19-
18|Path: MOCKDIR/pack/deps/opt/plugin_1
20-
19|Source: https://github.com/user/plugin_1
21-
20|State: sha1head (hello)
22-
21|
23-
22|Monitor updates from `world`:
24-
23|<Nothing>
25-
24|~
26-
25|
15+
14|Use regular fold keys (`zM`, `zR`, etc.) to manage shorter view.
16+
15|To finish update, write this buffer (for example, with `:write` command).
17+
16|To cancel update, close this window (for example, with `:close` command).
18+
17|
19+
18|--- plugin_1 ---
20+
19|Path: MOCKDIR/pack/deps/opt/plugin_1
21+
20|Source: https://github.com/user/plugin_1
22+
21|State: sha1head (hello)
23+
22|
24+
23|Monitor updates from `world`:
25+
24|<Nothing>
26+
25|~
27+
26|~
28+
27|
2729

2830
--|---------|---------|---------|---------|---------|---------|---------|---------|
2931
01|00000000000111111111111111111100000000000000000000000000000000000000000000000000
@@ -39,15 +41,17 @@
3941
11|22222222222222222222222222222222222222222222222222222222222222222222222222223333
4042
12|22222222222222222222222222233333333333333333333333333333333333333333333333333333
4143
13|33333333333333333333333333333333333333333333333333333333333333333333333333333333
42-
14|22222222222222222222222222222222222222222222222222222222222222222222222223333333
44+
14|22222222222222222222222222222222222222222222222222222222222222223333333333333333
4345
15|22222222222222222222222222222222222222222222222222222222222222222222222223333333
44-
16|33333333333333333333333333333333333333333333333333333333333333333333333333333333
45-
17|44444444444444443333333333333333333333333333333333333333333333333333333333333333
46-
18|33333333555555555555555555555555555555333333333333333333333333333333333333333333
47-
19|33333333555555555555555555555555555555553333333333333333333333333333333333333333
48-
20|33333333555555553222222233333333333333333333333333333333333333333333333333333333
49-
21|33333333333333333333333333333333333333333333333333333333333333333333333333333333
46+
16|22222222222222222222222222222222222222222222222222222222222222222222222223333333
47+
17|33333333333333333333333333333333333333333333333333333333333333333333333333333333
48+
18|44444444444444443333333333333333333333333333333333333333333333333333333333333333
49+
19|33333333555555555555555555555555555555333333333333333333333333333333333333333333
50+
20|33333333555555555555555555555555555555553333333333333333333333333333333333333333
51+
21|33333333555555553222222233333333333333333333333333333333333333333333333333333333
5052
22|33333333333333333333333333333333333333333333333333333333333333333333333333333333
51-
23|66666666633333333333333333333333333333333333333333333333333333333333333333333333
52-
24|77777777777777777777777777777777777777777777777777777777777777777777777777777777
53-
25|88888888888888888888888888888888888888888888888888888888888888888888888888888888
53+
23|33333333333333333333333333333333333333333333333333333333333333333333333333333333
54+
24|66666666633333333333333333333333333333333333333333333333333333333333333333333333
55+
25|77777777777777777777777777777777777777777777777777777777777777777777777777777777
56+
26|77777777777777777777777777777777777777777777777777777777777777777777777777777777
57+
27|88888888888888888888888888888888888888888888888888888888888888888888888888888888

0 commit comments

Comments
 (0)