Browse Source

check if group exists before removing

Chris 4 years ago
parent
commit
2a16537216
1 changed files with 15 additions and 9 deletions
  1. 15 9
      lua/lv-neoformat/init.lua

+ 15 - 9
lua/lv-neoformat/init.lua

@@ -1,12 +1,18 @@
 -- autoformat
 if O.format_on_save then
-  require("lv-utils").define_augroups {
-    autoformat = {
-      {
-        "BufWritePre",
-        "*",
-        [[try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry]],
-      },
-    },
-  }
+	require("lv-utils").define_augroups({
+		autoformat = {
+			{
+				"BufWritePre",
+				"*",
+				[[try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry]],
+			},
+		},
+	})
+end
+
+if not O.format_on_save then
+	vim.cmd([[if exists('#autoformat#BufWritePre')
+	:autocmd! autoformat
+	endif]])
 end