-
Contributing guidelines
Module(s)mini.starter QuestionCurrently, for each item in Worst case, The code can be optimized: MiniStarter.sections.recent_files = function(n, current_dir, show_path)
n = n or 5
if current_dir == nil then current_dir = false end
if show_path == nil then show_path = true end
if show_path == false then show_path = function() return '' end end
if show_path == true then
show_path = function(path) return string.format(' (%s)', vim.fn.fnamemodify(path, ':~:.')) end
end
if not vim.is_callable(show_path) then H.error('`show_path` should be boolean or callable.') end
return function()
local section = string.format('Recent files%s', current_dir and ' (current directory)' or '')
local sep = vim.loop.os_uname().sysname == 'Windows_NT' and [[%\]] or '%/'
local cwd_pattern = '^' .. vim.pesc(vim.fn.getcwd()) .. sep
local n_added = 0
local files = vim.tbl_filter(function(f)
-- Return early if there are enough items in the list
if n_added == n then return false end
-- Use only actual readable files
local result = vim.fn.filereadable(f) == 1
if current_dir then
-- Filter files from current directory and its subdirectories
result = result and f:find(cwd_pattern) ~= nil
end
n_added = result and n_added + 1 or n_added
return result
end, vim.v.oldfiles or {})
if #files == 0 then
local text = current_dir and 'There are no recent files in current directory'
or 'There are no recent files (`v:oldfiles` is empty)'
return { { name = text, action = '', section = section } }
end
-- Create items
local items = {}
for _, f in ipairs(files) do
local name = vim.fn.fnamemodify(f, ':t') .. show_path(f)
table.insert(items, { action = function() H.edit(f) end, name = name, section = section })
end
return items
end
Using the code above all tests pass. Would you allow a PR? If so, I'd also think that one message is sufficient in case the list is empty: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't think it has huge impact, but can be optimized, yeah.
Sure. Just not with
I think preserving current different messages which show more info is less ambiguous and better here. |
Beta Was this translation helpful? Give feedback.
PR