mirror of
https://github.com/NotAShelf/specs.nvim.git
synced 2025-02-21 10:58:03 +00:00
Attempting to add per-instance options
This commit is contained in:
parent
e043580a65
commit
5e2dd8ee92
1 changed files with 31 additions and 7 deletions
|
@ -40,33 +40,56 @@ function M.should_show_specs(start_win_id)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.show_specs()
|
function M.show_specs(popup)
|
||||||
local start_win_id = vim.api.nvim_get_current_win()
|
local start_win_id = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
if not M.should_show_specs(start_win_id) then
|
if not M.should_show_specs(start_win_id) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function dcopy (t)
|
||||||
|
local orig_type = type(orig)
|
||||||
|
local copy
|
||||||
|
if orig_type == 'table' then
|
||||||
|
copy = {}
|
||||||
|
for orig_key, orig_value in next, orig, nil do
|
||||||
|
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||||
|
end
|
||||||
|
setmetatable(copy, deepcopy(getmetatable(orig)))
|
||||||
|
else -- number, string, boolean, etc
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
|
if popup == nil then
|
||||||
|
popup = opts.popup
|
||||||
|
end
|
||||||
|
|
||||||
|
local originalOptions = deep_copy(opts)
|
||||||
|
local instanceOptions = deep_copy(opts)
|
||||||
|
instanceOptions.popup = popup
|
||||||
|
|
||||||
local cursor_col = vim.fn.wincol()-1
|
local cursor_col = vim.fn.wincol()-1
|
||||||
local cursor_row = vim.fn.winline()-1
|
local cursor_row = vim.fn.winline()-1
|
||||||
local bufh = vim.api.nvim_create_buf(false, true)
|
local bufh = vim.api.nvim_create_buf(false, true)
|
||||||
local win_id = vim.api.nvim_open_win(bufh, false, {
|
local win_id = vim.api.nvim_open_win(bufh, false, {
|
||||||
relative='win',
|
relative= 'win',
|
||||||
width = 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
col = cursor_col,
|
col = cursor_col,
|
||||||
row = cursor_row,
|
row = cursor_row,
|
||||||
style = 'minimal'
|
style = 'minimal'
|
||||||
})
|
})
|
||||||
vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:'.. opts.popup.winhl)
|
vim.api.nvim_win_set_option(win_id, 'winhl', 'Normal:'.. instanceOptions.popup.winhl)
|
||||||
vim.api.nvim_win_set_option(win_id, "winblend", opts.popup.blend)
|
vim.api.nvim_win_set_option(win_id, "winblend", instanceOptions.popup.blend)
|
||||||
|
|
||||||
local cnt = 0
|
local cnt = 0
|
||||||
local config = vim.api.nvim_win_get_config(win_id)
|
local config = vim.api.nvim_win_get_config(win_id)
|
||||||
local timer = vim.loop.new_timer()
|
local timer = vim.loop.new_timer()
|
||||||
local closed = false
|
local closed = false
|
||||||
|
|
||||||
vim.loop.timer_start(timer, opts.popup.delay_ms, opts.popup.inc_ms, vim.schedule_wrap(function()
|
vim.loop.timer_start(timer, instanceOptions.popup.delay_ms, instanceOptions.popup.inc_ms, vim.schedule_wrap(function()
|
||||||
if closed or vim.api.nvim_get_current_win() ~= start_win_id then
|
if closed or vim.api.nvim_get_current_win() ~= start_win_id then
|
||||||
if not closed then
|
if not closed then
|
||||||
pcall(vim.loop.close, timer)
|
pcall(vim.loop.close, timer)
|
||||||
|
@ -75,14 +98,15 @@ function M.show_specs()
|
||||||
-- Callbacks might stack up before the timer actually gets closed, track that state
|
-- Callbacks might stack up before the timer actually gets closed, track that state
|
||||||
-- internally here instead
|
-- internally here instead
|
||||||
closed = true
|
closed = true
|
||||||
|
opts = originalOptions
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.api.nvim_win_is_valid(win_id) then
|
if vim.api.nvim_win_is_valid(win_id) then
|
||||||
local bl = opts.popup.fader(opts.popup.blend, cnt)
|
local bl = instanceOptions.popup.fader(instanceOptions.popup.blend, cnt)
|
||||||
local dm = opts.popup.resizer(opts.popup.width, cursor_col, cnt)
|
local dm = instanceOptions.popup.resizer(instanceOptions.popup.width, cursor_col, cnt)
|
||||||
|
|
||||||
if bl ~= nil then
|
if bl ~= nil then
|
||||||
vim.api.nvim_win_set_option(win_id, "winblend", bl)
|
vim.api.nvim_win_set_option(win_id, "winblend", bl)
|
||||||
|
|
Loading…
Add table
Reference in a new issue