-vim.opt_local.formatoptions:remove("o")
-vim.opt_local.formatoptions:remove("r")
-vim.opt_local.formatoptions:remove("l")
-vim.opt_local.formatoptions:append("a")
-vim.opt_local.formatoptions:append("w")
-vim.opt_local.formatoptions:append("n")
+-- {{{ 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 = ""
+-- }}}
+
+-- {{{ 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 <CR>
+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
+-- }}}
+
+-- {{{ keymaps
+vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
+vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
+
+vim.keymap.set(
+ "n",
+ "<leader>msn",
+ ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1 (was: \\4),e<CR>:set nohls<CR>Whi",
+ -- <CR><cmd>set nohls<CR>f li",
+ { buffer = true, desc = "make a new subject" }
+)
+vim.keymap.set(
+ "n",
+ "<leader>msd",
+ '1G/\\v^Subject:(.|\\_s\\s+)+was:/e<CR>:set nohls<CR>"_dab',
+ { buffer = true, desc = "remove old subjects" }
+)
+
+-- {{{ profiles