Browse Source

nixpkgs/neovim: fix strip trailing whitespace formatter

Thomas Dy 3 months ago
parent
commit
7be27c6b5a
1 changed files with 11 additions and 1 deletions
  1. 11 1
      .config/nixpkgs/neovim/plugins.lua

+ 11 - 1
.config/nixpkgs/neovim/plugins.lua

@@ -288,6 +288,13 @@ local lsp_formatter = formatters.custom({
   end
 })
 
+-- the built-in formatter was not playing well with folds
+local whitespace_formatter = formatters.custom({
+  format = function()
+    vim.cmd('%s/\\s\\+$//e')
+  end
+})
+
 local js = {
   lsp_formatter,
   formatters.if_file_exists({
@@ -312,10 +319,13 @@ format_on_save.setup({
     javascript = js,
     typescript = js,
     typescriptreact = js,
+
+    -- don't format diffs
+    diff = {},
   },
 
   fallback_formatter = {
-    formatters.remove_trailing_whitespace,
+    whitespace_formatter,
     lsp_formatter,
   },
 })