All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 local i, _ = string.find(vim.bo.filetype, "markdown")
3 vim.opt_local.filetype = "mail.markdown"
4 -- this should trigger a reload of the ftplugin
8 -- There are no diagnostics for mail, but we do not want the
9 -- Markdown standards imposed on mail header and signature…
10 vim.diagnostic.enable(false)
11 vim.b.autoformat = false
13 -- disable Treesitter format expression for Mail
14 vim.opt_local.formatexpr = ""
16 vim.opt_local.formatoptions:remove("o")
17 vim.opt_local.formatoptions:remove("r")
18 vim.opt_local.formatoptions:remove("l")
20 vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
21 vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
26 ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1 (was: \\4),e<CR>:set nohls<CR>Whi",
27 -- <CR><cmd>set nohls<CR>f li",
28 { buffer = true, desc = "make a new subject" }
33 '1G/\\v^Subject:(.|\\_s\\s+)+was:/e<CR>:set nohls<CR>"_dab',
34 { buffer = true, desc = "remove old subjects" }
37 vim.keymap.set("n", "<leader>p", "", { buffer = true, desc = "mailplate profiles" })
42 ":w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>",
43 { buffer = true, desc = "Automatically determine mailplate profile" }
46 local function profile_keymap(key, profile)
49 "<leader>p<" .. key .. ">",
50 ":w<CR>:%!mailplate --keep-unknown " .. profile .. "<CR>",
51 { buffer = true, desc = "Switch to mailplate profile '" .. profile .. "'" }
55 profile_keymap("F1", "official")
56 profile_keymap("F2", "pobox")
57 profile_keymap("F3", "tahi")
58 profile_keymap("F4", "toni")
59 profile_keymap("F5", "kbkg")
60 profile_keymap("F6", "krafftwerk")
61 profile_keymap("F7", "siby")
62 profile_keymap("F8", "debian")
63 profile_keymap("F9", "uniwh")
64 profile_keymap("F10", "mtfk")
65 profile_keymap("F11", "sudetia")
66 profile_keymap("F12", "default")
68 local function write_mail_backup()
69 local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups"
70 vim.fn.mkdir(tmpdir, "p", "0o700")
71 local filename = os.date("%Y-%m-%d-%H%M%S") .. ".msg"
72 local file = io.open(tmpdir .. "/" .. filename, "a")
74 local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) or {}
75 local content = table.concat(lines, "\n")
78 vim.notify("Saved a backup to " .. filename, vim.log.levels.INFO)
82 vim.api.nvim_create_autocmd({ "BufWrite" }, {
83 callback = write_mail_backup,
87 vim.cmd.runtime("greeting_abbrevs.vim")
89 local function mail_area_detect()
90 local ts = vim.treesitter
94 local node = vim.treesitter.get_node()
98 if node:type():find("^body") ~= nil then
99 vim.opt_local.formatoptions:append("a")
100 vim.opt_local.formatoptions:append("w")
101 vim.opt_local.formatoptions:append("n")
102 vim.opt_local.formatoptions:append("t")
103 vim.opt_local.formatoptions:append("c")
106 vim.opt_local.formatoptions:remove("a")
107 vim.opt_local.formatoptions:remove("w")
108 vim.opt_local.formatoptions:remove("n")
109 vim.opt_local.formatoptions:remove("t")
110 vim.opt_local.formatoptions:remove("c")
111 vim.w.in_body = false
115 local cmdgroup = vim.api.nvim_create_augroup("mailarea", { clear = true })
116 vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
119 callback = mail_area_detect,