-- {{{ markdown in mail local i, _ = string.find(vim.bo.filetype, "markdown") if not i then vim.opt_local.filetype = "mail.markdown" -- this should trigger a reload of the ftplugin return end -- There are no diagnostics for mail, but we do not want the -- Markdown standards imposed on mail header and signature… vim.diagnostic.enable(false) vim.b.autoformat = false -- disable Treesitter format expression for Mail vim.opt_local.formatexpr = "" -- Do not conceal anything (Markdown) in emails going out vim.opt_local.conceallevel = 0 -- }}} -- {{{ formatting vim.opt_local.formatoptions:remove("o") -- would insert current comment leader for o/O vim.opt_local.formatoptions:remove("r") -- would insert current comment leader for vim.opt_local.formatoptions:remove("l") -- would not break lines that were long before insert vim.opt_local.commentstring = "> %s" -- commenting means quoting in mails -- }}} -- {{{ autocmds vim.api.nvim_create_autocmd({ "BufWrite" }, { buffer = 0, group = vim.api.nvim_create_augroup("squashemptylines", { clear = true }), callback = function() local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) local ret = {} local count = 0 local squash = false for _, line in ipairs(lines) do if line == "" then if not squash then squash = true table.insert(ret, line) else count = count + 1 end else squash = false table.insert(ret, line) end end if count > 0 then vim.notify("Squashed " .. count .. " empty line(s)") end vim.api.nvim_buf_set_lines(0, 0, -1, false, ret) end, }) -- }}} -- {{{ keymaps vim.keymap.set("n", "m", "", { buffer = true, desc = "mail functions" }) vim.keymap.set("n", "ms", "", { buffer = true, desc = "subject manipulation" }) vim.keymap.set( "n", "msn", ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1 (was: \\4),e:set nohlsWhi", -- set nohlsf li", { buffer = true, desc = "make a new subject" } ) vim.keymap.set( "n", "msd", '1G/\\v^Subject:(.|\\_s\\s+)+was:/e:set nohls"_dab', { buffer = true, desc = "remove old subjects" } ) -- {{{ profiles vim.keymap.set("n", "p", "", { buffer = true, desc = "mailplate profiles" }) vim.keymap.set( "n", "pp", ":w:%!mailplate --auto --keep-unknown 2>/dev/null", { buffer = true, desc = "Automatically determine mailplate profile" } ) local function profile_keymap(key, profile) vim.keymap.set( "n", "p<" .. key .. ">", ":w:%!mailplate --keep-unknown " .. profile .. "", { buffer = true, desc = "Switch to mailplate profile '" .. profile .. "'" } ) end profile_keymap("F1", "main") profile_keymap("F2", "pobox") profile_keymap("F3", "tahi") profile_keymap("F4", "toni") profile_keymap("F5", "kbkg") profile_keymap("F6", "krafftwerk") profile_keymap("F7", "siby") profile_keymap("F8", "debian") profile_keymap("F9", "uniwh") profile_keymap("F10", "mtfk") profile_keymap("F12", "default") -- }}} profiles -- }}} -- {{{ write mail backups local function write_mail_backup() local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups" vim.fn.mkdir(tmpdir, "p", "0o700") local filename = os.date("%Y-%m-%d-%H%M%S") .. ".msg" local file = io.open(tmpdir .. "/" .. filename, "a") if file ~= nil then local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) or {} local content = table.concat(lines, "\n") file:write(content) file:close() vim.notify("Saved a backup to " .. filename, vim.log.levels.INFO) end end vim.api.nvim_create_autocmd({ "BufWrite" }, { callback = write_mail_backup, buffer = 0, }) -- }}} -- {{{ mail area detect local function mail_area_detect() local ts = vim.treesitter if not ts then return end local node = vim.treesitter.get_node() if not node then return end if node:type():find("^body") ~= nil then vim.opt_local.formatoptions:append("a") -- turn on auto-reflow vim.opt_local.formatoptions:append("w") -- trailing whitespace for format=flowed vim.opt_local.formatoptions:append("n") -- numbered lists vim.opt_local.formatoptions:append("t") -- autowrap with textwidth vim.opt_local.formatoptions:append("c") -- autowrap and insert quote (comment) leader vim.w.in_body = true else vim.opt_local.formatoptions:remove("a") vim.opt_local.formatoptions:remove("w") vim.opt_local.formatoptions:remove("n") vim.opt_local.formatoptions:remove("t") vim.opt_local.formatoptions:remove("c") vim.w.in_body = false end end local cmdgroup = vim.api.nvim_create_augroup("mailarea", { clear = true }) vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { buffer = 0, group = cmdgroup, callback = mail_area_detect, }) mail_area_detect() vim.cmd.runtime("greeting_abbrevs.vim") -- }}} -- vim:foldmethod=marker:foldlevel=0