perga.nvim/lua/perga/init.lua

50 lines
1.3 KiB
Lua

local M = {}
local function get_indent(lnum)
local prev_line = vim.fn.getline(lnum - 1)
local curr_line = vim.fn.getline(lnum)
local prev_indent = vim.fn.indent(lnum - 1)
local shiftwidth = vim.bo.shiftwidth
if prev_line:match(';') then
return 0
end
if prev_line:match(':=') then
return prev_indent + shiftwidth
end
return prev_indent
end
function M.setup(opts)
vim.filetype.add({
extension = { pg = 'perga' }
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "perga",
callback = function()
_G.get_perga_indent = get_indent
vim.bo.indentexpr = 'v:lua.get_perga_indent(v:lnum)'
vim.bo.indentkeys = '0{,0},0),0],!^F,o,O,e,:,='
vim.opt_local.commentstring = '-- %s'
end
})
local parser_config = require 'nvim-treesitter.parsers'.get_parser_configs()
parser_config.perga = {
install_info = {
url = 'https://forgejo.ballcloud.cc/wball/tree-sitter-perga',
files = {'src/parser.c'},
branch = 'main',
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = 'pg',
}
end
return M