107 lines
2.7 KiB
Lua
107 lines
2.7 KiB
Lua
local map, auto = core.misc.map, core.misc.auto
|
|
|
|
--- to highlight a buffer or not
|
|
---@param buf number buffer number
|
|
---@return boolean to_highlight
|
|
local function highlight(buf)
|
|
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
|
|
|
|
-- disable highlighting on big files
|
|
local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
|
|
if ok and stats and stats.size > (1000 * 100 * 10) --[[1MB]] then
|
|
return false
|
|
end
|
|
|
|
-- fts to stop highlighting in
|
|
if table.contains({
|
|
"diff", "tex"
|
|
}, ft) then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
--- to indent a buffer or not
|
|
---@param buf number buffer number
|
|
---@return boolean to_indent
|
|
local function indent(buf)
|
|
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
|
|
|
|
-- disable indentation on filetypes
|
|
if not table.contains({
|
|
"php"
|
|
}, ft) then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
return {
|
|
{ "nvim-treesitter/nvim-treesitter",
|
|
branch = "main",
|
|
disable = not vim.fn.has("nvim-0.11.0"),
|
|
config = function()
|
|
vim.cmd("TSUpdate")
|
|
end,
|
|
load = function()
|
|
local treesitter = require("nvim-treesitter")
|
|
|
|
-- seems to not be very async despite the docs saying it is
|
|
-- default parsers to install
|
|
-- treesitter.install { "c", "lua", "vim", "vimdoc", "markdown",
|
|
-- "markdown_inline", "java", "bash", "css", "html", "luadoc", "make"
|
|
-- }
|
|
|
|
-- enable highlighting
|
|
auto("FileType", {
|
|
callback = function(e)
|
|
-- I like both treesitter and default highlighting enabled
|
|
if highlight(e.buf) then
|
|
-- stop errors from showing up, I don't care
|
|
pcall(vim.treesitter.start)
|
|
vim.bo.syntax = "on"
|
|
end
|
|
|
|
-- indenting
|
|
if indent(e.buf) then
|
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
|
end
|
|
|
|
-- set the folding method
|
|
vim.opt.foldmethod = "expr"
|
|
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
|
end
|
|
})
|
|
end
|
|
},
|
|
|
|
{ "Wansmer/treesj",
|
|
disable = not vim.fn.has("nvim-0.9.0"),
|
|
reqs = "nvim-treesitter/nvim-treesitter",
|
|
lazy = function(load)
|
|
load:keymap("n", "<leader>j")
|
|
load:cmd("TSJToggle")
|
|
load:cmd("TSJSplit")
|
|
load:cmd("TSJJoin")
|
|
end,
|
|
load = function()
|
|
require("treesj").setup {
|
|
use_default_keymaps = false,
|
|
}
|
|
|
|
map("n", "<leader>j", require("treesj").toggle, { desc = "fold code" })
|
|
end
|
|
},
|
|
|
|
{ "windwp/nvim-ts-autotag",
|
|
reqs = "nvim-treesitter/nvim-treesitter",
|
|
disable = not vim.fn.has("nvim-0.9.5"),
|
|
-- lazy = dep_short.auto({ "BufReadPre", "BufNewFile" }),
|
|
load = function()
|
|
require("nvim-ts-autotag").setup {}
|
|
end
|
|
}
|
|
}
|