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

Mail area detection and &fo handling
[etc/lazyvim.git] / .config / lazyvim / after / ftplugin / mail.lua
index f0b87eb51afe46dd466f9e39158f95599611ee67..b3d4005a731debe4d57fc1d4cad2000054a8f180 100644 (file)
@@ -16,9 +16,6 @@ vim.opt_local.formatexpr = ""
 vim.opt_local.formatoptions:remove("o")
 vim.opt_local.formatoptions:remove("r")
 vim.opt_local.formatoptions:remove("l")
-vim.opt_local.formatoptions:append("a")
-vim.opt_local.formatoptions:append("w")
-vim.opt_local.formatoptions:append("n")
 
 vim.keymap.set("n", "<leader>m", "", { buffer = true, desc = "mail functions" })
 vim.keymap.set("n", "<leader>ms", "", { buffer = true, desc = "subject manipulation" })
@@ -88,3 +85,37 @@ vim.api.nvim_create_autocmd({ "BufWrite" }, {
 })
 
 vim.cmd.runtime("greeting_abbrevs.vim")
+
+local function mail_area_detect()
+  local ts = vim.treesitter
+  if not ts then
+    return
+  end
+  local node = vim.treesitter.get_node()
+  if not node then
+    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.w.in_body = true
+  else
+    vim.opt_local.formatoptions:remove("a")
+    vim.opt_local.formatoptions:remove("w")
+    vim.opt_local.formatoptions:remove("n")
+    vim.opt_local.formatoptions:remove("t")
+    vim.opt_local.formatoptions:remove("c")
+    vim.w.in_body = false
+  end
+end
+
+local cmdgroup = vim.api.nvim_create_augroup("mailarea", { clear = true })
+vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
+  buffer = 0,
+  group = cmdgroup,
+  callback = mail_area_detect,
+})
+mail_area_detect()