Skip to content

Commit

Permalink
refactor: use vim.iter as needed
Browse files Browse the repository at this point in the history
This is alright now since we don't support pre-0.10 versions of Neovim
anymore.
  • Loading branch information
willothy committed Dec 29, 2024
1 parent 2bb52c6 commit e1ab20b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
45 changes: 16 additions & 29 deletions lua/flatten/guest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,23 @@ function M.init(host_pipe)
pattern = "*",
once = true,
callback = function()
local function filter_map(tbl, f)
local result = {}
for _, v in ipairs(tbl) do
local r = f(v)
if r ~= nil then
table.insert(result, r)
files = vim
.iter(vim.api.nvim_list_bufs())
:filter(function(buf)
local buftype = vim.bo[buf].buftype
if buftype ~= "" then
return false
end
end
return result
end
files = filter_map(vim.api.nvim_list_bufs(), function(buffer)
if not vim.api.nvim_buf_is_valid(buffer) then
return
end
local buftype = vim.api.nvim_get_option_value("buftype", {
buf = buffer,
})
if buftype ~= "" and buftype ~= "acwrite" then
return
end
local name = vim.api.nvim_buf_get_name(buffer)
if
name ~= ""
and vim.api.nvim_get_option_value("buflisted", {
buf = buffer,
})
then
return name
end
end)

return true
end)
:map(function(buf)
return vim.api.nvim_buf_get_name(buf)
end)
:filter(function(name)
return name ~= ""
end)
:totable()
nfiles = #files

-- No arguments, user is probably opening a nested session intentionally
Expand Down
5 changes: 4 additions & 1 deletion lua/flatten/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ Flatten.setup = function(opts)
local pipe_path = Flatten.config.callbacks.pipe_path()

if
pipe_path == nil or vim.tbl_contains(vim.fn.serverlist(), pipe_path, {})
pipe_path == nil
or vim.iter(vim.fn.serverlist()):find(function(path)
return path == pipe_path
end)
then
is_guest = false
return
Expand Down

0 comments on commit e1ab20b

Please sign in to comment.