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 -- {{{ markdown in mail
2 local i, _ = string.find(vim.bo.filetype, "markdown")
4 vim.opt_local.filetype = "mail.markdown"
5 -- this should trigger a reload of the ftplugin
9 -- There are no diagnostics for mail, but we do not want the
10 -- Markdown standards imposed on mail header and signature…
11 vim.diagnostic.enable(false)
12 vim.b.autoformat = false
14 -- disable Treesitter format expression for Mail
15 vim.opt_local.formatexpr = ""
19 vim.opt_local.formatoptions:remove("o") -- would insert current comment leader for o/O
20 vim.opt_local.formatoptions:remove("r") -- would insert current comment leader for <CR>
21 vim.opt_local.formatoptions:remove("l") -- would not break lines that were long before insert
23 vim.opt_local.commentstring = "> %s" -- commenting means quoting in mails
27 vim.api.nvim_create_autocmd({ "BufWrite" }, {
29 group = vim.api.nvim_create_augroup("squashemptylines", { clear = true }),
31 local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
35 for _, line in ipairs(lines) do
39 table.insert(ret, line)
45 table.insert(ret, line)
49 vim.notify("Squashed " .. count .. " empty line(s)")
51 vim.api.nvim_buf_set_lines(0, 0, -1, false, ret)
57 vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
58 vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
63 ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1 (was: \\4),e<CR>:set nohls<CR>Whi",
64 -- <CR><cmd>set nohls<CR>f li",
65 { buffer = true, desc = "make a new subject" }
70 '1G/\\v^Subject:(.|\\_s\\s+)+was:/e<CR>:set nohls<CR>"_dab',
71 { buffer = true, desc = "remove old subjects" }
76 vim.keymap.set("n", "<leader>p", "", { buffer = true, desc = "mailplate profiles" })
81 ":w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>",
82 { buffer = true, desc = "Automatically determine mailplate profile" }
85 local function profile_keymap(key, profile)
88 "<leader>p<" .. key .. ">",
89 ":w<CR>:%!mailplate --keep-unknown " .. profile .. "<CR>",
90 { buffer = true, desc = "Switch to mailplate profile '" .. profile .. "'" }
94 profile_keymap("F1", "official")
95 profile_keymap("F2", "pobox")
96 profile_keymap("F3", "tahi")
97 profile_keymap("F4", "toni")
98 profile_keymap("F5", "kbkg")
99 profile_keymap("F6", "krafftwerk")
100 profile_keymap("F7", "siby")
101 profile_keymap("F8", "debian")
102 profile_keymap("F9", "uniwh")
103 profile_keymap("F10", "mtfk")
104 profile_keymap("F11", "sudetia")
105 profile_keymap("F12", "default")
110 -- {{{ write mail backups
112 local function write_mail_backup()
113 local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups"
114 vim.fn.mkdir(tmpdir, "p", "0o700")
115 local filename = os.date("%Y-%m-%d-%H%M%S") .. ".msg"
116 local file = io.open(tmpdir .. "/" .. filename, "a")
118 local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) or {}
119 local content = table.concat(lines, "\n")
122 vim.notify("Saved a backup to " .. filename, vim.log.levels.INFO)
126 vim.api.nvim_create_autocmd({ "BufWrite" }, {
127 callback = write_mail_backup,
133 -- {{{ mail area detect
135 local function mail_area_detect()
136 local ts = vim.treesitter
140 local node = vim.treesitter.get_node()
144 if node:type():find("^body") ~= nil then
145 vim.opt_local.formatoptions:append("a") -- turn on auto-reflow
146 vim.opt_local.formatoptions:append("w") -- trailing whitespace for format=flowed
147 vim.opt_local.formatoptions:append("n") -- numbered lists
148 vim.opt_local.formatoptions:append("t") -- autowrap with textwidth
149 vim.opt_local.formatoptions:append("c") -- autowrap and insert quote (comment) leader
152 vim.opt_local.formatoptions:remove("a")
153 vim.opt_local.formatoptions:remove("w")
154 vim.opt_local.formatoptions:remove("n")
155 vim.opt_local.formatoptions:remove("t")
156 vim.opt_local.formatoptions:remove("c")
157 vim.w.in_body = false
161 local cmdgroup = vim.api.nvim_create_augroup("mailarea", { clear = true })
162 vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
165 callback = mail_area_detect,
169 vim.cmd.runtime("greeting_abbrevs.vim")
173 -- vim:foldmethod=marker:foldlevel=0