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

Implement squashing lines as a function
[etc/lazyvim.git] / .config / lazyvim / after / ftplugin / mail.lua
index 176382c30e9e39869ddfd4f495ee65af0e8cc0f3..8513a6d1ee1b406417af53386b617099f65fcfc1 100644 (file)
@@ -27,7 +27,29 @@ vim.opt_local.commentstring = "> %s" -- commenting means quoting in mails
 vim.api.nvim_create_autocmd({ "BufWrite" }, {
   buffer = 0,
   group = vim.api.nvim_create_augroup("squashemptylines", { clear = true }),
-  command = [[%s/\v(\n)\n+$/\1/ge]],
+  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,
 })
 -- }}}