column support for search matching, default colors for extensions

main
bhagwan 3 years ago
parent b4b56e2465
commit 2ae75cba96

@ -42,13 +42,10 @@ end
M.vimcmd_file = function(vimcmd, selected)
if not selected or #selected < 2 then return end
for i = 2, #selected do
-- check if the file contains line
local file, line = selected[i]:match("^([^:]+):(%d+)")
if file and line then
vim.cmd(string.format("%s +%s %s", vimcmd, line, vim.fn.fnameescape(file)))
else
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(selected[i]))
end
local entry = path.entry_to_file(selected[i])
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(entry.path))
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
vim.cmd("norm! zz")
end
end

@ -443,33 +443,52 @@ M.globals.nvim = {
}
M.globals.file_icon_colors = {
["lua"] = "blue",
["rockspec"] = "magenta",
["vim"] = "green",
["vifm"] = "green",
["sh"] = "cyan",
["zsh"] = "cyan",
["bash"] = "cyan",
["bat"] = "cyan",
["py"] = "green",
["md"] = "yellow",
["go"] = "magenta",
["c"] = "blue",
["cpp"] = "blue",
["h"] = "magenta",
["hpp"] = "magenta",
["sol"] = "magenta",
["abi"] = "yellow",
["js"] = "blue",
["ts"] = "cyan",
["tsx"] = "cyan",
["css"] = "magenta",
["hs"] = "blue",
["rs"] = "blue",
["rst"] = "yellow",
["xml"] = "yellow",
["yml"] = "yellow",
["yaml"] = "yellow",
["json"] = "yellow",
["toml"] = "yellow",
["conf"] = "yellow",
["ini"] = "red",
["conf"] = "red",
["config"] = "red",
["plist"] = "red",
["local"] = "red",
["build"] = "red",
["patch"] = "red",
["diff"] = "red",
["service"] = "red",
["desktop"] = "red",
["txt"] = "white",
["ico"] = "green",
["gif"] = "green",
["jpg"] = "green",
["png"] = "green",
["svg"] = "green",
["sol"] = "red",
["desktop"] = "magenta",
["otf"] = "green",
["ttf"] = "green",
}
function M.normalize_opts(opts, defaults)

@ -140,8 +140,8 @@ function M.entry_to_file(entry, cwd)
local bufnr = s[1]:match("%[(%d+)")
local idx = lastIndexOf(s[1], utils.nbsp) or 0
local noicons = string.sub(entry, idx+1)
local line = s[2]
local col = s[3]
local line = tonumber(s[2])
local col = tonumber(s[3])
if cwd and #cwd>0 and not M.starts_with_separator(file) then
file = M.join({cwd, file})
noicons = M.join({cwd, noicons})

@ -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

Loading…
Cancel
Save