fix: declare filetype when window init is done

This commit is contained in:
kiyan42 2020-06-15 15:30:18 +02:00
parent 8e9650f10a
commit d4e5b1bb51
2 changed files with 10 additions and 9 deletions

View File

@ -59,6 +59,7 @@ end
function M.window_options() function M.window_options()
local opts = {} local opts = {}
opts.winhl = 'EndOfBuffer:LuaTreeEndOfBuffer,Normal:LuaTreeNormal,CursorLine:LuaTreeCursorLine,VertSplit:LuaTreeVertSplit'
if vim.g.lua_tree_side == 'right' then if vim.g.lua_tree_side == 'right' then
opts.side = 'L' opts.side = 'L'
opts.open_command = 'h' opts.open_command = 'h'

View File

@ -222,24 +222,17 @@ end
local function create_buf() local function create_buf()
local options = { local options = {
bufhidden = 'delete'; bufhidden = 'wipe';
buftype = 'nofile'; buftype = 'nofile';
modifiable = false; modifiable = false;
} }
M.Tree.bufnr = api.nvim_create_buf(false, true) M.Tree.bufnr = api.nvim_create_buf(false, true)
api.nvim_buf_set_name(M.Tree.bufnr, M.Tree.buf_name) api.nvim_buf_set_name(M.Tree.bufnr, M.Tree.buf_name)
api.nvim_buf_set_option(M.Tree.bufnr, 'filetype', M.Tree.buf_name)
for opt, val in pairs(options) do for opt, val in pairs(options) do
api.nvim_buf_set_option(M.Tree.bufnr, opt, val) api.nvim_buf_set_option(M.Tree.bufnr, opt, val)
end end
for _, opt in pairs(M.Tree.buf_options) do
api.nvim_command('setlocal '..opt)
end
api.nvim_command('setlocal '..window_opts.split_command)
set_mappings() set_mappings()
end end
@ -253,7 +246,6 @@ local function create_win()
for opt, val in pairs(M.Tree.win_options) do for opt, val in pairs(M.Tree.win_options) do
api.nvim_win_set_option(M.Tree.winnr, opt, val) api.nvim_win_set_option(M.Tree.winnr, opt, val)
end end
api.nvim_command('setlocal winhighlight+=EndOfBuffer:LuaTreeEndOfBuffer,Normal:LuaTreeNormal,CursorLine:LuaTreeCursorLine,VertSplit:LuaTreeVertSplit')
end end
function M.close() function M.close()
@ -266,8 +258,16 @@ function M.open()
create_buf() create_buf()
create_win() create_win()
api.nvim_win_set_buf(M.Tree.winnr, M.Tree.bufnr) api.nvim_win_set_buf(M.Tree.winnr, M.Tree.bufnr)
for _, opt in pairs(M.Tree.buf_options) do
api.nvim_command('setlocal '..opt)
end
api.nvim_command('setlocal '..window_opts.split_command)
renderer.draw(M.Tree, not M.Tree.loaded) renderer.draw(M.Tree, not M.Tree.loaded)
M.Tree.loaded = true M.Tree.loaded = true
api.nvim_buf_set_option(M.Tree.bufnr, 'filetype', M.Tree.buf_name)
end end
function M.win_open() function M.win_open()