X-Git-Url: https://git.madduck.net/etc/lazyvim.git/blobdiff_plain/8b10fec3cea6c9b671aa4c3c5d0f6125332c3f72..2c071be78a0700505e18f226e2e4799485c27ece:/.config/lazyvim/after/ftplugin/mail.lua?ds=sidebyside diff --git a/.config/lazyvim/after/ftplugin/mail.lua b/.config/lazyvim/after/ftplugin/mail.lua index f0b87eb..39eaf3e 100644 --- a/.config/lazyvim/after/ftplugin/mail.lua +++ b/.config/lazyvim/after/ftplugin/mail.lua @@ -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" @@ -12,14 +13,17 @@ 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") -vim.opt_local.formatoptions:append("a") -vim.opt_local.formatoptions:append("w") -vim.opt_local.formatoptions:append("n") +-- {{{ 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 +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 +-- }}} + +-- {{{ keymaps vim.keymap.set("n", "m", "", { buffer = true, desc = "mail functions" }) vim.keymap.set("n", "ms", "", { buffer = true, desc = "subject manipulation" }) @@ -37,6 +41,8 @@ vim.keymap.set( { buffer = true, desc = "remove old subjects" } ) +-- {{{ profiles + vim.keymap.set("n", "p", "", { buffer = true, desc = "mailplate profiles" }) vim.keymap.set( @@ -68,6 +74,11 @@ 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") @@ -87,4 +98,46 @@ vim.api.nvim_create_autocmd({ "BufWrite" }, { buffer = 0, }) +-- }}} + +-- {{{ mail area detect + +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") -- 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") + 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() + vim.cmd.runtime("greeting_abbrevs.vim") + +-- }}} + +-- vim:foldmethod=marker:foldlevel=0