Skip to content

Commit 7dff5f8

Browse files
committed
Improove window options configurations
## Changes Description This commit adds the ability to customize window options `vim.wo` for windows Overseer creates (e.g. the task_list, the output, etc.). It also fixes a problem where pre-defined window options are reset after the main buffer changes on the window.
1 parent 819bb88 commit 7dff5f8

File tree

4 files changed

+74
-40
lines changed

4 files changed

+74
-40
lines changed

lua/overseer/config.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ local default_config = {
2626
separator = "────────────────────────────────────────",
2727
-- Default direction. Can be "left", "right", or "bottom"
2828
direction = "left",
29+
-- You can set window options (see `:help vim.wo`) to be used when creating
30+
-- the Task List window, these are the defaults used:
31+
win_opts = {
32+
listchars = "tab:> ",
33+
winfixwidth = true,
34+
winfixheight = true,
35+
number = false,
36+
relativenumber = false,
37+
foldcolumn = "0",
38+
signcolumn = "no",
39+
statuscolumn = "",
40+
wrap = false,
41+
spell = false,
42+
},
2943
-- Set keymap to false to remove default behavior
3044
-- You can add custom keymaps here as well (anything vim.keymap.set accepts)
3145
bindings = {
@@ -51,6 +65,24 @@ local default_config = {
5165
["<C-j>"] = "ScrollOutputDown",
5266
["q"] = "Close",
5367
},
68+
-- When the Task List is positioned at the bottom, it will show its output
69+
-- window on the right side of the split. The next configuration table
70+
-- tweaks options for such window
71+
output = {
72+
-- You can set window options (see `:help vim.wo`) to be used when
73+
-- creating the Task List Output window, these are the defaults used:
74+
win_opts = {
75+
number = false,
76+
relativenumber = false,
77+
cursorline = false,
78+
cursorcolumn = false,
79+
foldcolumn = "0",
80+
signcolumn = "no",
81+
statuscolumn = "",
82+
spell = false,
83+
list = false,
84+
},
85+
},
5486
},
5587
-- See :help overseer-actions
5688
actions = {},

lua/overseer/task_list/sidebar.lua

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ function Sidebar:_get_preview_wins()
217217
return ret
218218
end
219219

220+
---@param winid number
221+
---@param bufnr number
222+
---@param window_opts vim.wo
223+
function Sidebar:_update_window_buf(winid, bufnr, window_opts)
224+
if vim.api.nvim_win_get_buf(winid) ~= bufnr then
225+
vim.api.nvim_win_set_buf(winid, bufnr)
226+
-- The documentation of `vim.api.nvim_win_set_buf` states that it will
227+
-- "Set the current buffer in a window, without side effects", but
228+
-- unfortunately, some window options are not kept when a "new" buffer is
229+
-- set to the window. For instance, the `winhighlight` and the experimental
230+
-- `statuscolumn` options may change with a new buffer, therefore, to make
231+
-- the appearance of the window consistent, we re-apply its window options
232+
-- when switching its current buffer.
233+
util.set_window_opts(window_opts, winid)
234+
util.scroll_to_end(winid)
235+
end
236+
end
237+
220238
function Sidebar:update_preview()
221239
local winids = self:_get_preview_wins()
222240
if vim.tbl_isempty(winids) then
@@ -240,9 +258,12 @@ function Sidebar:update_preview()
240258
end
241259

242260
for _, winid in ipairs(winids) do
243-
if vim.api.nvim_win_get_buf(winid) ~= display_buf then
244-
vim.api.nvim_win_set_buf(winid, display_buf)
245-
util.scroll_to_end(winid)
261+
-- We need to use different window options between the floating preview
262+
-- window and the output one
263+
if vim.wo[winid].previewwindow then
264+
self:_update_window_buf(winid, display_buf, config.task_win.win_opts)
265+
else
266+
self:_update_window_buf(winid, display_buf, config.task_list.output.win_opts)
246267
end
247268
end
248269
end

lua/overseer/util.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ M.scroll_to_end = function(winid)
147147
vim.api.nvim_set_option_value("scrolloff", scrolloff, { scope = "local", win = winid })
148148
end
149149

150+
---@param win_opts vim.wo
151+
---@param winid? number
152+
M.set_window_opts = function(win_opts, winid)
153+
winid = winid or 0
154+
for k, v in pairs(win_opts) do
155+
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
156+
end
157+
end
158+
150159
---@param bufnr number
151160
---@param ns number
152161
---@param highlights table
@@ -265,10 +274,12 @@ end
265274

266275
---Set the appropriate window options for a terminal buffer
267276
M.set_term_window_opts = function(winid)
268-
winid = winid or 0
269-
vim.api.nvim_set_option_value("number", false, { scope = "local", win = winid })
270-
vim.api.nvim_set_option_value("relativenumber", false, { scope = "local", win = winid })
271-
vim.api.nvim_set_option_value("signcolumn", "no", { scope = "local", win = winid })
277+
M.set_window_opts({
278+
number = false,
279+
relativenumber = false,
280+
signcolumn = "no",
281+
statuscolumn = "",
282+
}, winid)
272283
end
273284

274285
---@generic T : any

lua/overseer/window.lua

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ local function watch_for_win_closed()
2121
})
2222
end
2323

24-
local min_win_opts = {
25-
number = false,
26-
relativenumber = false,
27-
cursorline = false,
28-
cursorcolumn = false,
29-
foldcolumn = "0",
30-
signcolumn = "no",
31-
spell = false,
32-
list = false,
33-
}
34-
---@param winid integer
35-
local function set_minimal_win_opts(winid)
36-
for k, v in pairs(min_win_opts) do
37-
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
38-
end
39-
end
40-
4124
---@param direction "left"|"right"|"bottom"
4225
---@param existing_win integer
4326
local function create_overseer_window(direction, existing_win)
@@ -68,34 +51,21 @@ local function create_overseer_window(direction, existing_win)
6851
vim.bo[outbuf].bufhidden = "wipe"
6952
end
7053
util.go_buf_no_au(outbuf)
71-
set_minimal_win_opts(0)
54+
util.set_window_opts(config.task_list.output.win_opts, 0)
7255
util.go_win_no_au(winid)
7356
vim.w.overseer_output_win = output_win
7457
watch_for_win_closed()
7558
end
7659

7760
util.go_buf_no_au(bufnr)
78-
local default_opts = {
79-
listchars = "tab:> ",
80-
winfixwidth = true,
81-
winfixheight = true,
82-
number = false,
83-
signcolumn = "no",
84-
foldcolumn = "0",
85-
relativenumber = false,
86-
wrap = false,
87-
spell = false,
88-
}
89-
for k, v in pairs(default_opts) do
90-
vim.api.nvim_set_option_value(k, v, { scope = "local", win = 0 })
91-
end
61+
util.set_window_opts(config.task_list.win_opts, 0)
9262
vim.api.nvim_win_set_width(0, layout.calculate_width(nil, config.task_list))
9363
if direction == "bottom" then
9464
vim.api.nvim_win_set_height(0, layout.calculate_height(nil, config.task_list))
9565
end
9666
-- Set the filetype only after we enter the buffer so that FileType autocmds
9767
-- behave properly
98-
vim.bo[bufnr].filetype = "OverseerList"
68+
vim.api.nvim_set_option_value("filetype", "OverseerList", { buf = bufnr })
9969

10070
util.go_win_no_au(my_winid)
10171
return winid

0 commit comments

Comments
 (0)