Skip to content

Commit d1413e1

Browse files
committed
(mini.starter) Optimize computation of whether something is shown.
Details: - Resolves #680. - Resolves #681.
1 parent 79b1b33 commit d1413e1

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

lua/mini/starter.lua

+11-9
Original file line numberDiff line numberDiff line change
@@ -1439,13 +1439,8 @@ end
14391439
H.is_something_shown = function()
14401440
-- Don't open Starter buffer if Neovim is opened to show something. That is
14411441
-- when at least one of the following is true:
1442-
-- - Current buffer has any lines (something opened explicitly).
1443-
-- NOTE: Usage of `line2byte(line('$') + 1) < 0` seemed to be fine, but it
1444-
-- doesn't work if some automated changed was made to buffer while leaving it
1445-
-- empty (returns 2 instead of -1). This was also the reason of not being
1446-
-- able to test with child Neovim process from 'tests/helpers'.
1447-
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
1448-
if #lines > 1 or (#lines == 1 and lines[1]:len() > 0) then return true end
1442+
-- - There are files in arguments (like `nvim foo.txt` with new file).
1443+
if vim.fn.argc() > 0 then return true end
14491444

14501445
-- - Several buffers are listed (like session with placeholder buffers). That
14511446
-- means unlisted buffers (like from `nvim-tree`) don't affect decision.
@@ -1455,8 +1450,15 @@ H.is_something_shown = function()
14551450
)
14561451
if #listed_buffers > 1 then return true end
14571452

1458-
-- - There are files in arguments (like `nvim foo.txt` with new file).
1459-
if vim.fn.argc() > 0 then return true end
1453+
-- - Current buffer has any lines (something opened explicitly).
1454+
-- NOTE: Usage of `line2byte(line('$') + 1) < 0` seemed to be fine, but it
1455+
-- doesn't work if some automated changed was made to buffer while leaving it
1456+
-- empty (returns 2 instead of -1). This was also the reason of not being
1457+
-- able to test with child Neovim process from 'tests/helpers'.
1458+
local n_lines = vim.api.nvim_buf_line_count(0)
1459+
if n_lines > 1 then return true end
1460+
local first_line = vim.api.nvim_buf_get_lines(0, 0, 1, true)[1]
1461+
if string.len(first_line) > 0 then return true end
14601462

14611463
return false
14621464
end

tests/test_starter.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,8 @@ end
11001100
T['Autoopening']['does not autoopen if Neovim started to show something'] = function()
11011101
local init_autoopen = 'tests/dir-starter/init-files/test-init.lua'
11021102

1103-
-- Current buffer has any lines (something opened explicitly)
1104-
child.restart({ '-u', init_autoopen, '-c', [[call setline(1, 'a')]] })
1103+
-- There are files in arguments (like `nvim foo.txt` with new file).
1104+
child.restart({ '-u', init_autoopen, 'new-file.txt' })
11051105
validate_starter_not_shown()
11061106

11071107
-- Several buffers are listed (like session with placeholder buffers)
@@ -1112,8 +1112,8 @@ T['Autoopening']['does not autoopen if Neovim started to show something'] = func
11121112
child.restart({ '-u', init_autoopen, '-c', 'e foo | set nobuflisted | e bar | set buflisted' })
11131113
validate_starter_shown()
11141114

1115-
-- There are files in arguments (like `nvim foo.txt` with new file).
1116-
child.restart({ '-u', init_autoopen, 'new-file.txt' })
1115+
-- Current buffer has any lines (something opened explicitly)
1116+
child.restart({ '-u', init_autoopen, '-c', [[call setline(1, 'a')]] })
11171117
validate_starter_not_shown()
11181118
end
11191119

0 commit comments

Comments
 (0)