]> git.madduck.net Git - etc/lazyvim.git/blobdiff - .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:

Migrate to latest Lazyvim (neovim 0.11.4)
[etc/lazyvim.git] / .config / lazyvim / after / ftplugin / mail.lua
index b3d4005a731debe4d57fc1d4cad2000054a8f180..8118cef9dbf6a32eab0f1212e4da9a847ddc1a6f 100644 (file)
@@ -1,3 +1,4 @@
+-- {{{ markdown in mail
 local i, _ = string.find(vim.bo.filetype, "markdown")
 if not i then
   vim.opt_local.filetype = "mail.markdown"
@@ -13,10 +14,55 @@ vim.b.autoformat = false
 -- disable Treesitter format expression for Mail
 vim.opt_local.formatexpr = ""
 
-vim.opt_local.formatoptions:remove("o")
-vim.opt_local.formatoptions:remove("r")
-vim.opt_local.formatoptions:remove("l")
+-- Do not conceal anything (Markdown) in emails going out
+vim.opt_local.conceallevel = 0
+-- }}}
 
+-- {{{ 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
+-- }}}
+
+-- {{{ options
+vim.opt.number = false
+vim.opt.relativenumber = false
+vim.opt.signcolumn = "no"
+-- }}}
+
+-- {{{ autocmds
+vim.api.nvim_create_autocmd({ "BufWrite" }, {
+  buffer = 0,
+  group = vim.api.nvim_create_augroup("squashemptylines", { clear = true }),
+  callback = function()
+    local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
+    local ret = {}
+    local count = 0
+    local squash = false
+    for _, line in ipairs(lines) do
+      if line == "" then
+        if not squash then
+          squash = true
+          table.insert(ret, line)
+        else
+          count = count + 1
+        end
+      else
+        squash = false
+        table.insert(ret, line)
+      end
+    end
+    if count > 0 then
+      vim.notify("Squashed " .. count .. " empty line(s)")
+    end
+    vim.api.nvim_buf_set_lines(0, 0, -1, false, ret)
+  end,
+})
+-- }}}
+
+-- {{{ keymaps
 vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
 vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
 
@@ -34,6 +80,8 @@ vim.keymap.set(
   { buffer = true, desc = "remove old subjects" }
 )
 
+-- {{{ profiles
+
 vim.keymap.set("n", "<leader>p", "", { buffer = true, desc = "mailplate profiles" })
 
 vim.keymap.set(
@@ -52,7 +100,7 @@ local function profile_keymap(key, profile)
   )
 end
 
-profile_keymap("F1", "official")
+profile_keymap("F1", "main")
 profile_keymap("F2", "pobox")
 profile_keymap("F3", "tahi")
 profile_keymap("F4", "toni")
@@ -62,9 +110,13 @@ profile_keymap("F7", "siby")
 profile_keymap("F8", "debian")
 profile_keymap("F9", "uniwh")
 profile_keymap("F10", "mtfk")
-profile_keymap("F11", "sudetia")
 profile_keymap("F12", "default")
 
+-- }}} profiles
+-- }}}
+
+-- {{{ write mail backups
+
 local function write_mail_backup()
   local tmpdir = vim.fn.expand(os.getenv("TMPDIR") or "/tmp") .. "/mail-backups"
   vim.fn.mkdir(tmpdir, "p", "0o700")
@@ -84,7 +136,9 @@ vim.api.nvim_create_autocmd({ "BufWrite" }, {
   buffer = 0,
 })
 
-vim.cmd.runtime("greeting_abbrevs.vim")
+-- }}}
+
+-- {{{ mail area detect
 
 local function mail_area_detect()
   local ts = vim.treesitter
@@ -96,11 +150,11 @@ local function mail_area_detect()
     return
   end
   if node:type():find("^body") ~= nil then
-    vim.opt_local.formatoptions:append("a")
-    vim.opt_local.formatoptions:append("w")
-    vim.opt_local.formatoptions:append("n")
-    vim.opt_local.formatoptions:append("t")
-    vim.opt_local.formatoptions:append("c")
+    vim.opt_local.formatoptions:append("a") -- turn on auto-reflow
+    vim.opt_local.formatoptions:append("w") -- trailing whitespace for format=flowed
+    vim.opt_local.formatoptions:append("n") -- numbered lists
+    vim.opt_local.formatoptions:append("t") -- autowrap with textwidth
+    vim.opt_local.formatoptions:append("c") -- autowrap and insert quote (comment) leader
     vim.w.in_body = true
   else
     vim.opt_local.formatoptions:remove("a")
@@ -119,3 +173,9 @@ vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
   callback = mail_area_detect,
 })
 mail_area_detect()
+
+vim.cmd.runtime("greeting_abbrevs.vim")
+
+-- }}}
+
+-- vim:foldmethod=marker:foldlevel=0