Allow passing window options for the repl in repl.open

This commit is contained in:
Mathias Fussenegger 2020-07-14 23:03:01 +02:00
parent 7192104442
commit 254889c316

View file

@ -127,7 +127,14 @@ local function execute(text)
end
function M.open()
--- Toggle the REPL
--
--@param winopts optional table which may include:
-- `height` to set the window height
-- `width` to set the window width
-- Any other key/value pair, that will be treated as window
-- option.
function M.open(winopts)
if win and api.nvim_win_is_valid(win) and api.nvim_win_get_buf(win) == buf then
return
end
@ -160,6 +167,21 @@ function M.open()
win = api.nvim_get_current_win()
api.nvim_win_set_buf(win, buf)
api.nvim_set_current_win(current_win)
if winopts then
assert(
type(winopts) == 'table',
'winopts must be a table, not ' .. type(winopts) .. ': ' .. vim.inspect(winopts)
)
for k, v in pairs(winopts) do
if k == 'width' then
api.nvim_win_set_width(win, v)
elseif k == 'height' then
api.nvim_win_set_height(win, v)
else
api.nvim_win_set_option(win, k, v)
end
end
end
end