]> 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:

add mail functions for subject manipulation
[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>m", "", { buffer = true, desc = "mail functions" })
24 vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
25
26 vim.keymap.set(
27   "n",
28   "<leader>msn",
29   ":1,/^$/s,\\v(Subject:)\\s*((Re|AW):\\s*)*((.|\\_s\\s+)+),\\1  (was: \\4),e<CR>:set nohls<CR>Whi",
30   -- <CR><cmd>set nohls<CR>f li",
31   { buffer = true, desc = "make a new subject" }
32 )
33 vim.keymap.set(
34   "n",
35   "<leader>msd",
36   '1G/\\v^Subject:(.|\\_s\\s+)+was:/e<CR>:set nohls<CR>"_dab',
37   { buffer = true, desc = "remove old subjects" }
38 )
39
40 vim.keymap.set("n", "<leader>p", "", { buffer = true, desc = "mailplate profiles" })
41
42 vim.keymap.set(
43   "n",
44   "<leader>pp",
45   ":w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>",
46   { buffer = true, desc = "Automatically determine mailplate profile" }
47 )
48
49 local function profile_keymap(key, profile)
50   vim.keymap.set(
51     "n",
52     "<leader>p<" .. key .. ">",
53     ":w<CR>:%!mailplate --keep-unknown " .. profile .. "<CR>",
54     { buffer = true, desc = "Switch to mailplate profile '" .. profile .. "'" }
55   )
56 end
57
58 profile_keymap("F1", "official")
59 profile_keymap("F2", "pobox")
60 profile_keymap("F3", "tahi")
61 profile_keymap("F4", "toni")
62 profile_keymap("F5", "kbkg")
63 profile_keymap("F6", "krafftwerk")
64 profile_keymap("F7", "siby")
65 profile_keymap("F8", "debian")
66 profile_keymap("F9", "uniwh")
67 profile_keymap("F10", "mtfk")
68 profile_keymap("F11", "sudetia")
69 profile_keymap("F12", "default")
70
71 local function write_mail_backup()
72   local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups"
73   vim.fn.mkdir(tmpdir, "p", "0o700")
74   local filename = os.date("%Y-%m-%d-%H%M%S") .. ".msg"
75   local file = io.open(tmpdir .. "/" .. filename, "a")
76   if file ~= nil then
77     local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) or {}
78     local content = table.concat(lines, "\n")
79     file:write(content)
80     file:close()
81     vim.notify("Saved a backup to " .. filename, vim.log.levels.INFO)
82   end
83 end
84
85 vim.api.nvim_create_autocmd({ "BufWrite" }, {
86   callback = write_mail_backup,
87   buffer = 0,
88 })
89
90 vim.cmd.runtime("greeting_abbrevs.vim")