mcauley-penney / tidy.nvim

A small Neovim plugin to remove trailing whitespace and empty lines at end of file on every save
107 stars 15 forks source link

Provide option to run the cleanup manually #16

Closed tiyn closed 8 months ago

tiyn commented 8 months ago

In some cases (for example when using real-time preview for markdown or tex files) many saves can happen. This causes the plugin to repeatedly delete trailing whitespaces while writing. For situations like these it could be useful to stop the plugin and run it manually. A function to stop the plugin and a function to run the cleanup could be provided.

mcauley-penney commented 8 months ago

This is a reasonable request and mirrors the functionality provided by LSP. I'll work on this today 👍🏻

mcauley-penney commented 8 months ago

@tiyn I've added this functionality in the triggerable-tidy branch. If you find that its what you expected, I'll merge it.

If you are using lazy.nvim, you can test this branch out with the below configuration. With it, you can activate tidy using <leader>tr.

return {
    "mcauley-penney/tidy.nvim",
    branch = "triggerable-tidy",
    opts = {
      enabled_on_save = false,
      filetype_exclude = { "diff" }
    },
    init = function()
      vim.keymap.set('n', "<leader>te", require("tidy").toggle, {})
      vim.keymap.set('n', "<leader>tr", require("tidy").run, {})
    end
} 
tiyn commented 8 months ago

I've tested the provided branch for both manual and automatic cleanup. It looks really good to me and the new function fixes the problem described. Thank you!

mcauley-penney commented 8 months ago

Closed by 1cbed7676273057c8af22438deaae73cd5cb96b5