]> git.madduck.net Git - etc/lazyvim.git/blob - .config/lazyvim/after/ftplugin/mail.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

36c6eade64709b8deff465c03905c2cf7d9c2136
[etc/lazyvim.git] / .config / lazyvim / after / ftplugin / mail.lua
1 local i, _ = string.find(vim.bo.filetype, "markdown")
2 if not i then
3   vim.opt_local.filetype = "mail.markdown"
4   -- this should trigger a reload of the ftplugin
5   return
6 end
7
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
12
13 -- disable Treesitter format expression for Mail
14 vim.opt_local.formatexpr = ""
15
16 vim.opt_local.formatoptions:remove("o")
17 vim.opt_local.formatoptions:remove("r")
18 vim.opt_local.formatoptions:remove("l")
19 vim.opt_local.formatoptions:append("a")
20 vim.opt_local.formatoptions:append("w")
21 vim.opt_local.formatoptions:append("n")
22
23 vim.keymap.set("n", "<leader>p", "", { buffer = true, desc = "mailplate profiles" })
24
25 vim.keymap.set(
26   "n",
27   "<leader>pp",
28   ":w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>",
29   { buffer = true, desc = "Automatically determine mailplate profile" }
30 )
31
32 local function profile_keymap(key, profile)
33   vim.keymap.set(
34     "n",
35     "<leader>p<" .. key .. ">",
36     ":w<CR>:%!mailplate --keep-unknown " .. profile .. "<CR>",
37     { buffer = true, desc = "Switch to mailplate profile '" .. profile .. "'" }
38   )
39 end
40
41 profile_keymap("F1", "official")
42 profile_keymap("F2", "pobox")
43 profile_keymap("F3", "tahi")
44 profile_keymap("F4", "toni")
45 profile_keymap("F5", "kbkg")
46 profile_keymap("F6", "krafftwerk")
47 profile_keymap("F7", "siby")
48 profile_keymap("F8", "debian")
49 profile_keymap("F9", "uniwh")
50 profile_keymap("F10", "mtfk")
51 profile_keymap("F11", "sudetia")
52 profile_keymap("F12", "default")
53
54 local function write_mail_backup()
55   local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups"
56   vim.fn.mkdir(tmpdir, "p", "0o700")
57   local filename = os.date("%Y-%m-%d-%H%M%S") .. ".msg"
58   local file = io.open(tmpdir .. "/" .. filename, "a")
59   if file ~= nil then
60     local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) or {}
61     local content = table.concat(lines, "\n")
62     file:write(content)
63     file:close()
64     vim.notify("Saved a backup to " .. filename, vim.log.levels.INFO)
65   end
66 end
67
68 vim.api.nvim_create_autocmd({ "BufWrite" }, {
69   callback = write_mail_backup,
70   buffer = 0,
71 })
72
73 vim.cmd.runtime("greeting_abbrevs.vim")