Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/Fix]: - [Feat]: Allow to change the value of sign column in focused window from any buffer, bring exclude filetypes, buftypes comback - [Fix]: Prevent sign column from updating when buffer is disabled when buffer enter or out #113

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lua/focus/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ Focus.config = {
list = '+1', -- Set the comma-saperated list for the colorcolumn
},
signcolumn = true, -- Display signcolumn in the focussed window only
signcolumn_focused_value = 'auto', -- Set the value of signcolumn for the focused window only (yes, number, auto)
winhighlight = false, -- Auto highlighting for focussed/unfocussed windows
},
exclude = {
filetypes = {}, -- Filetypes to exclude from Focus
buftypes = {}, -- Buftypes to exclude from Focus
bufnames = {}, -- File names to exclude from Focus
},
}

--- Module setup
Expand Down Expand Up @@ -166,6 +172,7 @@ H.setup_config = function(config)
autoresize = { config.autoresize, 'table', true },
split = { config.split, 'table', true },
ui = { config.split, 'table', true },
exclude = { config.exclude, 'table', true },
})

vim.validate({
Expand Down Expand Up @@ -197,6 +204,10 @@ H.setup_config = function(config)
['ui.cursorcolumn'] = { config.ui.cursorcolumn, 'boolean' },
['ui.colorcolumn'] = { config.ui.colorcolumn, 'table', true },
['ui.signcolumn'] = { config.ui.signcolumn, 'boolean' },
['ui.signcolumn_focused_value'] = {
config.ui.signcolumn_focused_value,
'string',
},
['ui.winhighlight'] = { config.ui.winhighlight, 'boolean' },
})

Expand All @@ -205,6 +216,12 @@ H.setup_config = function(config)
['ui.colorcolumn.list'] = { config.ui.colorcolumn.list, 'string' },
})

vim.validate({
['exclude.filetypes'] = { config.exclude.filetypes, 'table' },
['exclude.buftypes'] = { config.exclude.buftypes, 'table' },
['exclude.bufnames'] = { config.exclude.bufnames, 'table' },
})

return config
end

Expand Down
63 changes: 58 additions & 5 deletions lua/focus/modules/autocmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ local M = {}

-- if focus auto signcolumn is set to true then
-- we assume it to be auto in case signcolumn = no
local function get_sign_column()
local default_signcolumn = 'auto'
local function get_sign_column(config)
local default_signcolumn = config.ui.signcolumn_focused_value or 'auto'
if vim.opt.signcolumn:get() == 'no' then
return default_signcolumn
else
Expand Down Expand Up @@ -91,13 +91,16 @@ function M.setup(config)
if utils.is_disabled() then
return
end
vim.wo.signcolumn = get_sign_column()
vim.wo.signcolumn = get_sign_column(config)
end,
desc = 'Enable signcolumn',
})
vim.api.nvim_create_autocmd({ 'BufLeave', 'WinLeave' }, {
group = augroup,
callback = function(_)
if utils.is_disabled() then
return
end
vim.wo.signcolumn = 'no'
end,
desc = 'Disable signcolumn',
Expand Down Expand Up @@ -158,7 +161,7 @@ function M.setup(config)
vim.wo.number = false
vim.wo.relativenumber = true
end,
desc = 'Absolutnumber unfoccused enter',
desc = 'Absolutenumber unfoccused enter',
})
vim.api.nvim_create_autocmd({ 'BufLeave', 'WinLeave' }, {
group = augroup,
Expand All @@ -169,7 +172,7 @@ function M.setup(config)
vim.wo.number = true
vim.wo.relativenumber = false
end,
desc = 'Absolutnumber unfoccused leave',
desc = 'Absolutenumber unfoccused leave',
})
else
vim.api.nvim_create_autocmd({ 'BufEnter', 'WinEnter' }, {
Expand Down Expand Up @@ -288,6 +291,56 @@ function M.setup(config)
desc = 'Color column leave',
})
end

if #config.exclude.filetypes > 0 then
vim.api.nvim_create_autocmd({ 'FileType' }, {
group = augroup,
callback = function(_)
if
vim.tbl_contains(config.exclude.filetypes, vim.bo.filetype)
then
vim.b.focus_disable = true
end
end,
desc = 'Disable focus autoresize for FileType',
})
end

if #config.exclude.buftypes > 0 then
vim.api.nvim_create_autocmd(
{ 'BufEnter', 'WinEnter', 'BufRead', 'BufNewFile' },
{
group = augroup,
callback = function(_)
if
vim.tbl_contains(
config.exclude.buftypes,
vim.bo.buftype
)
then
vim.b.focus_disable = true
end
end,
desc = 'Disable focus autoresize for BufType',
}
)
end

if #config.exclude.bufnames > 0 then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think buffer names should be included here. That's too specific, almost definitely better handled by an autocmd in the user's config

vim.api.nvim_create_autocmd({ 'BufEnter', 'WinEnter' }, {
group = augroup,
callback = function(_)
if
vim.tbl_contains(config.exclude.bufnames, vim.fn.bufname())
then
vim.b.focus_disable = true
end
end,
desc = 'Disable focus autoresize for BufName',
})
end

return M
end

return M