diff --git a/lua/perga/init.lua b/lua/perga/init.lua index 6b05f17..4a0e40f 100644 --- a/lua/perga/init.lua +++ b/lua/perga/init.lua @@ -1,11 +1,38 @@ 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.opt.commentstring = '-- %s' + 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 = { diff --git a/queries/perga/folds.scm b/queries/perga/folds.scm new file mode 100644 index 0000000..bc0b758 --- /dev/null +++ b/queries/perga/folds.scm @@ -0,0 +1,6 @@ +[ + (definition) + (block_comment) + (labs) + (pabs) +] @fold diff --git a/queries/perga/highlights.scm b/queries/perga/highlights.scm index ad6b321..dce2dde 100644 --- a/queries/perga/highlights.scm +++ b/queries/perga/highlights.scm @@ -6,6 +6,7 @@ [(star) (square)] @constant.builtin (comment) @comment +(block_comment) @comment [ "(" ")" ] @punctuation.bracket @@ -17,3 +18,6 @@ (param_block type: (expr) @type) + +(ascription + type: (expr) @type)