Skip to content

Commit

Permalink
fix: option issue (closes #252)
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk committed Jun 29, 2022
1 parent c0d6b69 commit 7538e8f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lua/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local command = vim.api.nvim_command
local create_augroup = vim.api.nvim_create_augroup
local create_autocmd = vim.api.nvim_create_autocmd
local create_user_command = vim.api.nvim_create_user_command
local buf_get_option = vim.api.nvim_buf_get_option
local defer_fn = vim.defer_fn
local notify = vim.notify
local tbl_extend = vim.tbl_extend
Expand Down Expand Up @@ -77,8 +78,9 @@ function bufferline.enable()

create_autocmd('BufModifiedSet', {
callback = function()
if vim.bo.modified ~= vim.b.checked then
vim.b.checked = vim.bo.modified
local is_modified = buf_get_option(0, 'modified')
if is_modified ~= vim.b.checked then
vim.b.checked = is_modified
bufferline.update()
end
end,
Expand Down
6 changes: 4 additions & 2 deletions lua/bufferline/bbye.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ local set_current_buf = vim.api.nvim_set_current_buf
local set_current_win = vim.api.nvim_set_current_win
local win_get_buf = vim.api.nvim_win_get_buf
local win_is_valid = vim.api.nvim_win_is_valid
local buf_get_option = vim.api.nvim_buf_get_option
local buf_set_option = vim.api.nvim_buf_set_option

local reverse = require'bufferline.utils'.reverse

Expand Down Expand Up @@ -99,7 +101,7 @@ function bbye.delete(action, force, buffer, mods)
return
end

local is_modified = vim.bo[buffer_number].modified
local is_modified = buf_get_option(buffer_number, 'modified')
local has_confirm = vim.o.confirm or (string_match(mods, 'conf') ~= nil)

if is_modified and not (force or has_confirm) then
Expand All @@ -112,7 +114,7 @@ function bbye.delete(action, force, buffer, mods)
-- If the buffer is set to delete and it contains changes, we can't switch
-- away from it. Hide it before eventual deleting:
if is_modified and force then
vim.bo[buffer_number].bufhidden = 'hide'
buf_set_option(buffer_number, 'bufhidden', 'hide')
end

-- For cases where adding buffers causes new windows to appear or hiding some
Expand Down
3 changes: 2 additions & 1 deletion lua/bufferline/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local table_concat = table.concat

local buf_get_name = vim.api.nvim_buf_get_name
local buf_is_valid = vim.api.nvim_buf_is_valid
local buf_get_option = vim.api.nvim_buf_get_option
local bufwinnr = vim.fn.bufwinnr
local get_current_buf = vim.api.nvim_get_current_buf
local matchlist = vim.fn.matchlist
Expand Down Expand Up @@ -42,7 +43,7 @@ local function get_name(opts, number)
local name = buf_is_valid(number) and buf_get_name(number) or nil

if name then
name = vim.bo[number].buftype == 'terminal' and terminalname(name) or utils.basename(name)
name = buf_get_option(number, 'buftype') == 'terminal' and terminalname(name) or utils.basename(name)
elseif opts.no_name_title ~= nil and opts.no_name_title ~= vim.NIL then
name = opts.no_name_title
end
Expand Down
3 changes: 2 additions & 1 deletion lua/bufferline/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local min = math.min
local table_insert = table.insert

local strwidth = vim.api.nvim_strwidth
local buf_get_option = vim.api.nvim_buf_get_option
local tabpagenr = vim.fn.tabpagenr

local Buffer = require'bufferline.buffer'
Expand Down Expand Up @@ -53,7 +54,7 @@ local function calculate_buffers_width(state, base_width)
local is_pinned = state.is_pinned(buffer_number)

if opts.closable or is_pinned then
local is_modified = vim.bo[buffer_number].modified
local is_modified = buf_get_option(buffer_number, 'modified')
local icon = is_pinned and opts.icon_pinned or
(not is_modified -- close-icon
and opts.icon_close_tab
Expand Down
7 changes: 4 additions & 3 deletions lua/bufferline/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local string_rep = string.rep
local table_insert = table.insert

local get_current_buf = vim.api.nvim_get_current_buf
local buf_get_option = vim.api.nvim_buf_get_option
local has = vim.fn.has
local strcharpart = vim.fn.strcharpart
local strwidth = vim.api.nvim_strwidth
Expand Down Expand Up @@ -191,7 +192,7 @@ local function render(update_names)
local current = get_current_buf()

-- Store current buffer to open new ones next to this one
if vim.bo[current].buflisted then
if buf_get_option(current, 'buflisted') then
if vim.b.empty_buffer then
state.last_current_buffer = nil
else
Expand Down Expand Up @@ -224,7 +225,7 @@ local function render(update_names)
local is_inactive = activity == 0
-- local is_visible = activity == 1
local is_current = activity == 2
local is_modified = vim.bo[buffer_number].modified
local is_modified = buf_get_option(buffer_number, 'modified')
-- local is_closing = buffer_data.closing
local is_pinned = state.is_pinned(buffer_number)

Expand Down Expand Up @@ -275,7 +276,7 @@ local function render(update_names)
else

if has_icons then
local iconChar, iconHl = icons.get_icon(buffer_name, vim.bo[buffer_number].filetype, status)
local iconChar, iconHl = icons.get_icon(buffer_name, buf_get_option(buffer_number, 'filetype'), status)
local hlName = is_inactive and 'BufferInactive' or iconHl
iconPrefix = has_icon_custom_colors and hl_tabline('Buffer' .. status .. 'Icon') or hlName and hl_tabline(hlName) or namePrefix
icon = iconChar .. ' '
Expand Down
13 changes: 7 additions & 6 deletions lua/bufferline/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local buf_get_name = vim.api.nvim_buf_get_name
local buf_get_var = vim.api.nvim_buf_get_var
local buf_is_valid = vim.api.nvim_buf_is_valid
local buf_line_count = vim.api.nvim_buf_line_count
local buf_get_option = vim.api.nvim_buf_get_option
local bufadd = vim.fn.bufadd
local bufwinnr = vim.fn.bufwinnr
local command = vim.api.nvim_command
Expand Down Expand Up @@ -239,20 +240,20 @@ end

local function set_current_win_listed_buffer()
local current = get_current_buf()
local is_listed = vim.bo[current].buflisted
local is_listed = buf_get_option(current, 'buflisted')

-- Check previous window first
if not is_listed then
command('wincmd p')
current = get_current_buf()
is_listed = vim.bo[current].buflisted
is_listed = buf_get_option(current, 'buflisted')
end
-- Check all windows now
if not is_listed then
local wins = list_wins()
for _, win in ipairs(wins) do
current = win_get_buf(win)
is_listed = vim.bo[current].buflisted
is_listed = buf_get_option(current, 'buflisted')
if is_listed then
set_current_win(win)
break
Expand Down Expand Up @@ -321,12 +322,12 @@ local function get_buffer_list()

for _, buffer in ipairs(buffers) do

if not vim.bo[buffer].buflisted then
if not buf_get_option(buffer, 'buflisted') then
goto continue
end

if not utils.is_nil(exclude_ft) then
local ft = vim.bo[buffer].filetype
local ft = buf_get_option(buffer, 'filetype')
if utils.has(exclude_ft, ft) then
goto continue
end
Expand Down Expand Up @@ -761,7 +762,7 @@ function M.restore_buffers(bufnames)
-- and create useless empty buffers.
for _,bufnr in ipairs(list_bufs()) do
if buf_get_name(bufnr) == ''
and vim.bo[bufnr].buftype == ''
and buf_get_option(bufnr, 'buftype') == ''
and buf_line_count(bufnr) == 1
and buf_get_lines(bufnr, 0, 1, true)[1] == '' then
buf_delete(bufnr, {})
Expand Down

0 comments on commit 7538e8f

Please sign in to comment.