feat: quickfile

This commit is contained in:
Folke Lemaitre 2024-11-03 15:32:55 +01:00
parent 787b53e763
commit d0ce6454f9
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

39
lua/snacks/quickfile.lua Normal file
View file

@ -0,0 +1,39 @@
---@class snacks.quickfile
local M = {}
---@class snacks.quickfile.Config
local defaults = {
-- any treesitter langs to exclude
exclude = { "latex" },
}
function M.setup()
local opts = Snacks.config.get("quickfile", defaults)
-- Skip if we already entered vim
if vim.v.vim_did_enter == 1 then
return
end
local buf = vim.api.nvim_get_current_buf()
-- Try to guess the filetype (may change later on during Neovim startup)
local ft = vim.filetype.match({ buf = buf })
if ft then
-- Add treesitter highlights and fallback to syntax
local lang = vim.treesitter.language.get_lang(ft)
-- disable treesitter for some langs
if vim.tbl_contains(opts.exclude, lang) then
lang = nil
end
if not (lang and pcall(vim.treesitter.start, buf, lang)) then
vim.bo[buf].syntax = ft
end
-- Trigger early redraw
vim.cmd([[redraw]])
end
end
return M