neovim conf part 4 i think

This commit is contained in:
RafayAhmad7548 2025-05-01 07:50:51 +05:00
parent ac7ba4097d
commit d6c19e2e92
12 changed files with 154 additions and 166 deletions

View file

@ -2,19 +2,22 @@ local function starts_with(str, prefix)
return string.find(str, '^' .. prefix) ~= nil
end
---get the window for the right dock
---@return integer | nil window window id if exists, nil otherwise
local function get_dock_win()
local windows = vim.api.nvim_list_wins()
for _, win in ipairs(windows) do
if vim.api.nvim_win_get_tabpage(win) == vim.api.nvim_get_current_tabpage() then
local width = vim.api.nvim_win_get_width(win)
if width == 60 or width == 40 then
return win
end
local width = vim.api.nvim_win_get_width(win)
if width == 60 or width == 40 then
return win
end
end
return nil
end
---get the buffer which starts with prefix
---@param prefix string prefix of the name of buffer
---@return integer | nil buf buffer id if exists, nil otherwise
local function get_dock_buf(prefix)
local buffers = vim.api.nvim_list_bufs()
for _, buf in ipairs(buffers) do
@ -28,6 +31,22 @@ local function get_dock_buf(prefix)
return nil
end
---get number of windows that are not docks i.e. right dock
---@param tabpage integer tabpage id of the tab to look in, 0 for current
---@return integer count count of non-dock windows
local function get_no_of_nondock_wins(tabpage)
local wins = vim.api.nvim_tabpage_list_wins(tabpage)
local count = 0
for _, win in ipairs(wins) do
local buf = vim.api.nvim_win_get_buf(win)
local buf_name = vim.api.nvim_buf_get_name(buf)
if not(starts_with(buf_name, 'term://') or starts_with(buf_name, 'oil://')) then
count = count + 1
end
end
return count
end
return {
open_in_right_dock = function (prefix)
@ -60,7 +79,7 @@ return {
end
-- no dock window at this point so create new
vim.cmd.vnew()
vim.cmd.vsplit()
vim.api.nvim_win_set_width(0, width)
-- get existing buf if exists
@ -80,6 +99,6 @@ return {
else
vim.cmd('Oil')
end
end,
end
}