From 7538e8f99a9c0fba04fe839bde359de88804412f Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Tue, 28 Jun 2022 21:46:00 -0400 Subject: [PATCH] fix: option issue (closes #252) --- lua/bufferline.lua | 6 ++++-- lua/bufferline/bbye.lua | 6 ++++-- lua/bufferline/buffer.lua | 3 ++- lua/bufferline/layout.lua | 3 ++- lua/bufferline/render.lua | 7 ++++--- lua/bufferline/state.lua | 13 +++++++------ 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lua/bufferline.lua b/lua/bufferline.lua index 5563c049..32f891c5 100644 --- a/lua/bufferline.lua +++ b/lua/bufferline.lua @@ -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 @@ -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, diff --git a/lua/bufferline/bbye.lua b/lua/bufferline/bbye.lua index 75d7f382..ac79815b 100644 --- a/lua/bufferline/bbye.lua +++ b/lua/bufferline/bbye.lua @@ -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 @@ -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 @@ -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 diff --git a/lua/bufferline/buffer.lua b/lua/bufferline/buffer.lua index af9acdf3..8958a00e 100644 --- a/lua/bufferline/buffer.lua +++ b/lua/bufferline/buffer.lua @@ -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 @@ -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 diff --git a/lua/bufferline/layout.lua b/lua/bufferline/layout.lua index 86bdc3e5..f15de7cb 100644 --- a/lua/bufferline/layout.lua +++ b/lua/bufferline/layout.lua @@ -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' @@ -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 diff --git a/lua/bufferline/render.lua b/lua/bufferline/render.lua index 0d0cb818..4f1ce470 100644 --- a/lua/bufferline/render.lua +++ b/lua/bufferline/render.lua @@ -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 @@ -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 @@ -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) @@ -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 .. ' ' diff --git a/lua/bufferline/state.lua b/lua/bufferline/state.lua index cf06dec6..4e0013b8 100644 --- a/lua/bufferline/state.lua +++ b/lua/bufferline/state.lua @@ -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 @@ -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 @@ -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 @@ -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, {})