beancount.lua (845B)
1 -- Don't wrap beancount files. 2 vim.opt_local.textwidth = 0 3 vim.opt_local.wrap = false 4 5 -- Format on save. 6 vim.api.nvim_create_autocmd("BufWritePost", { 7 desc = "Run bean-format on save", 8 callback = function(args) 9 local filepath = vim.api.nvim_buf_get_name(args.buf) 10 local filename = vim.fn.fnamemodify(filepath, ":t") -- just the tail name 11 local cmd 12 if vim.startswith(filename, "prices_") then 13 -- prices_* are formatted without a hardcoded currency column. 14 cmd = string.format("silent !bean-format %s -o %s", vim.fn.shellescape(filepath), vim.fn.shellescape(filepath)) 15 else 16 -- other beancount files are formatted with currency on 100th column. 17 cmd = string.format("silent !bean-format -c 100 %s -o %s", vim.fn.shellescape(filepath), vim.fn.shellescape(filepath)) 18 end 19 vim.cmd(cmd) 20 end, 21 })