-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurably autoclose the infoview if it has no Lean buffers updating it #43
Comments
I've set this up in my config with: local infoview = require('lean.infoview').get_current_infoview()
if infoview then
local tab_wins = vim.api.nvim_tabpage_list_wins(0)
local non_info_wins = vim.tbl_filter(function (w) return w ~= infoview.window end, tab_wins)
if #non_info_wins <= 1 then
infoview:close()
end
end Not sure if this is all that's required. I can submit a PR but I'm not sure how to test this. |
I am behind on lots of stuff so I haven't yet thought about this again -- I think what you have looks good for sticking in your own config but probably would want to be thought out very slightly more for actually merging. Specifically -- I think it's worth at least (re)considering whether to autoclose if it's the last window or whether, as the title here suggests, there's no other lean windows open. E.g. if I have I'm sure the "full implementation" is not far away from what you shared, but just want to set aside a tiny bit of time (or welcome more thoughts from you our anyone). Please feel free to ping if I don't follow up soon and you're keen, as if it stays open for much longer I'm inclined to nevertheless welcome what you have! |
I totally see what you mean now after working with this setup for a bit. I think that is the behavior I would want. I can see this as having three options for |
I've changed my setup to the following, though this only implements the more eager version of autoclose. I also disabled the default autoopen behavior because for this setup it needs to be triggered in local group = vim.api.nvim_create_augroup('LeanAutoOpenClose', {})
vim.api.nvim_create_autocmd('BufWinEnter', {
group = group,
pattern = {'*.lean'},
callback = function ()
require('lean.infoview').open()
end
})
vim.api.nvim_create_autocmd({'BufWinLeave', 'QuitPre'}, {
group = group,
pattern = {'*.lean'},
callback = function ()
local infoview = require('lean.infoview').get_current_infoview()
if infoview then
local tab_wins = vim.api.nvim_tabpage_list_wins(0)
local lean_wins = vim.tbl_filter(function (w)
local buf = vim.api.nvim_win_get_buf(w)
local buf_ft = vim.api.nvim_buf_get_option(buf, 'filetype')
return buf_ft == 'lean'
end, tab_wins)
if #lean_wins <= 1 then
infoview:close()
end
end
end
}) I suppose one additional complexity not handled here is that if the user explicitly closes the infoview it should not be reopened automatically. |
Another question is what should happen with |
I've been using #43 (comment), and it works great with a few modifications: (1) using vim.api.nvim_create_autocmd('BufWinEnter', {
group = group,
pattern = {'*.lean'},
callback = function ()
require('lean.infoview').open()
end
}) with
or
Simply removing this and using Having both
If just
since
The solution is to just activate on With the aforementioned modifications the snippet looks like local group = vim.api.nvim_create_augroup('LeanAutoOpenClose', {})
vim.api.nvim_create_autocmd('QuitPre', {
group = group,
pattern = {'*.lean'},
callback = function ()
local infoview = require('lean.infoview').get_current_infoview()
if infoview then
local tab_wins = vim.api.nvim_tabpage_list_wins(0)
local lean_wins = vim.tbl_filter(function (w)
local buf = vim.api.nvim_win_get_buf(w)
local buf_ft = vim.api.nvim_buf_get_option(buf, 'filetype')
return buf_ft == 'lean'
end, tab_wins)
if #lean_wins <= 1 then
infoview:close()
end
end
end
}) with |
Add a configuration option
infoview.autoclose = true (default)
which indicates the infoview should be closed if no Lean buffers are updating it anymore (e.g. particularly if it is the last remaining window).The text was updated successfully, but these errors were encountered: