From 7189898849a6e4ecde89f86d624a77f9717f68a1 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 13 Sep 2023 00:45:13 -0500 Subject: [PATCH] feat(nvim): allow StripTrailSpace save to be toggleable --- dots/.config/nvim/lua/core/autocmds.lua | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/dots/.config/nvim/lua/core/autocmds.lua b/dots/.config/nvim/lua/core/autocmds.lua index e2c3cc9e..459f019d 100644 --- a/dots/.config/nvim/lua/core/autocmds.lua +++ b/dots/.config/nvim/lua/core/autocmds.lua @@ -10,10 +10,35 @@ M.setup = function() end, }) + local strip_trail_space = true + vim.api.nvim_create_user_command("ToggleStripTrailSpace", function() + strip_trail_space = not strip_trail_space + local intercept_state = "`Enabled`" + if not strip_trail_space then + intercept_state = "`Disabled`" + end + vim.notify("Strip Trail Space set to " .. intercept_state, vim.log.levels.INFO, + { + title = "Strip Trail Space", + ---@param win integer The window handle + on_open = function(win) + vim.api.nvim_buf_set_option( + vim.api.nvim_win_get_buf(win), + "filetype", + "markdown" + ) + end + }) + end, { desc = "Toggles intercepting BufWritePre to strip trail space" }) + -- NOTE: Remove trailing whitespace on save vim.api.nvim_create_autocmd("BufWritePre", { group = augroup, - command = "StripTrailSpace", + callback = function() + if strip_trail_space then + vim.cmd.StripTrailSpace() + end + end }) -- NOTE: Disables status column elements in Terminal buffer