From 186a664f79c2c3cbee2fce30c9471702cad23ac3 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 22 Oct 2023 13:17:24 -0400 Subject: [PATCH] Replace some instances of vim.cmd('set ...') --- lua/lean/infoview.lua | 10 ++++------ lua/tests/infoview/open_close_spec.lua | 9 ++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lua/lean/infoview.lua b/lua/lean/infoview.lua index 7427bd28..ccbb7cfa 100644 --- a/lua/lean/infoview.lua +++ b/lua/lean/infoview.lua @@ -261,16 +261,14 @@ function Infoview:__refresh() local valid_windows = {} self.info.__win_event_disable = true - for _, win in pairs({self.window, self.__diff_win}) do + for _, win in pairs{ self.window, self.__diff_win } do if win and vim.api.nvim_win_is_valid(win) then table.insert(valid_windows, win) end end for _, win in pairs(valid_windows) do - vim.api.nvim_win_call(win, function() - vim.cmd('set winfixwidth') - end) + vim.wo[win].winfixwidth = true end for _, win in pairs(valid_windows) do @@ -311,8 +309,8 @@ function Infoview:__refresh_diff() for _, win in pairs({self.__diff_win, self.window}) do vim.api.nvim_win_call(win, function() vim.cmd.diffthis() - vim.cmd("set foldmethod=manual") - vim.cmd("setlocal wrap") + vim.wo.foldmethod = 'manual' + vim.wo.wrap = true end) end diff --git a/lua/tests/infoview/open_close_spec.lua b/lua/tests/infoview/open_close_spec.lua index 186738fd..c1905147 100644 --- a/lua/tests/infoview/open_close_spec.lua +++ b/lua/tests/infoview/open_close_spec.lua @@ -47,7 +47,7 @@ describe('infoview open/close', function() it('remains open on splitting the current window', function(_) local windows = vim.api.nvim_tabpage_list_wins(0) - assert.is.equal(2, #windows) -- +1 above + assert.is.equal(2, #windows) assert.is.truthy( vim.tbl_contains(windows, infoview.get_current_infoview().window) ) @@ -64,6 +64,13 @@ describe('infoview open/close', function() assert.windows.are(windows) end) + it('is fixed width', function(_) + local windows = vim.api.nvim_tabpage_list_wins(0) + assert.is.equal(#windows, 2) + assert.is.truthy(vim.wo[infoview.get_current_infoview().window].winfixwidth) + assert.is.falsy(vim.wo[lean_window].winfixwidth) + end) + it('closes via its Lua API and stays closed', function(_) infoview.get_current_infoview():close() assert.windows.are(lean_window)