|
|
|
@ -12,9 +12,6 @@ local Previewer = {}
|
|
|
|
|
-- signgleton instance used for our keymappings
|
|
|
|
|
local _self = nil
|
|
|
|
|
|
|
|
|
|
-- extensions to filetype mapping
|
|
|
|
|
local ext_to_ft = {}
|
|
|
|
|
|
|
|
|
|
setmetatable(Previewer, {
|
|
|
|
|
__call = function (cls, ...)
|
|
|
|
|
return cls:new(...)
|
|
|
|
@ -122,9 +119,9 @@ end
|
|
|
|
|
|
|
|
|
|
function Previewer:restore_winopts(win)
|
|
|
|
|
if not win or not api.nvim_win_is_valid(win) then return end
|
|
|
|
|
for opt, value in pairs(self.backups) do
|
|
|
|
|
vim.api.nvim_win_set_option(win, opt, value)
|
|
|
|
|
end
|
|
|
|
|
for opt, value in pairs(self.backups) do
|
|
|
|
|
vim.api.nvim_win_set_option(win, opt, value)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Previewer:set_winopts(win)
|
|
|
|
@ -133,9 +130,6 @@ function Previewer:set_winopts(win)
|
|
|
|
|
if utils.nvim_has_option(opt) then
|
|
|
|
|
api.nvim_win_set_option(win, opt, v)
|
|
|
|
|
end
|
|
|
|
|
--[[ api.nvim_win_call(win, function()
|
|
|
|
|
api.nvim_win_set_option(0, opt, v)
|
|
|
|
|
end) ]]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -196,30 +190,15 @@ function Previewer:do_syntax(entry)
|
|
|
|
|
))
|
|
|
|
|
end
|
|
|
|
|
if syntax_limit_reached == 0 then
|
|
|
|
|
-- greedy match anything after last dot
|
|
|
|
|
-- local ext = entry.path:match("[^.]*$")
|
|
|
|
|
--[[ local ext = entry.path:match("%.(.*)$")
|
|
|
|
|
if ext and #ext > 0 then
|
|
|
|
|
local ft = ext_to_ft[ext]
|
|
|
|
|
if not ft then
|
|
|
|
|
ft = utils.ft_detect(ext)
|
|
|
|
|
ext_to_ft[ext] = ft
|
|
|
|
|
end
|
|
|
|
|
if ft then
|
|
|
|
|
pcall(api.nvim_buf_set_option, bufnr, 'filetype', ft)
|
|
|
|
|
end
|
|
|
|
|
else ]]
|
|
|
|
|
-- prepend the buffer number to the path and
|
|
|
|
|
-- set as buffer name, this makes sure 'filetype detect'
|
|
|
|
|
-- gets the right filetype which enables the syntax
|
|
|
|
|
local tempname = path.join({tostring(bufnr), entry.path})
|
|
|
|
|
pcall(api.nvim_buf_set_name, bufnr, tempname)
|
|
|
|
|
-- no extension try to detect the filetype nontheless
|
|
|
|
|
-- nvim_buf_call has less side-effects than window switch
|
|
|
|
|
api.nvim_buf_call(bufnr, function()
|
|
|
|
|
vim.cmd('filetype detect')
|
|
|
|
|
end)
|
|
|
|
|
-- end
|
|
|
|
|
-- prepend the buffer number to the path and
|
|
|
|
|
-- set as buffer name, this makes sure 'filetype detect'
|
|
|
|
|
-- gets the right filetype which enables the syntax
|
|
|
|
|
local tempname = path.join({tostring(bufnr), entry.path})
|
|
|
|
|
pcall(api.nvim_buf_set_name, bufnr, tempname)
|
|
|
|
|
-- nvim_buf_call has less side-effects than window switch
|
|
|
|
|
api.nvim_buf_call(bufnr, function()
|
|
|
|
|
vim.cmd('filetype detect')
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|