luafy AutoFmtToggle

Sun, 05 May 2024 13:39:31 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 05 May 2024 13:39:31 -0500
changeset 1158
0e7310186a57
parent 1157
a237720efee9
child 1159
9a19621f294c

luafy AutoFmtToggle

.config/nvim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
.config/nvim/lua/config/maps.lua file | annotate | diff | comparison | revisions
deleted file mode 100644
--- a/.config/nvim/autoload/vimrc.vim
+++ /dev/null
@@ -1,21 +0,0 @@
-func! vimrc#AutoFmtToggle() abort
-  if &formatoptions =~# 'a'
-    setl formatoptions-=a | echo '-a'
-  else
-    setl formatoptions+=a | echo '+a'
-  endif
-endfunc
-
-func! vimrc#SafeFilterFile(cmd)
-  let errors = tempname()
-  try
-    exec 'silent %!' . a:cmd . ' 2>' . shellescape(errors)
-    if v:shell_error
-      for line in readfile(errors)
-        echomsg line
-      endfor
-    endif
-  finally
-    call delete(errors)
-  endtry
-endfunc
--- a/.config/nvim/lua/config/maps.lua
+++ b/.config/nvim/lua/config/maps.lua
@@ -66,7 +66,16 @@ map("n", "<leader>te", ":Tabularize firs
 map("n", "<leader>tc", ":Tabularize first_colon<CR>")
 map("n", "<leader>tm", ":Tabularize methods<CR>")
 
-map("n", "<leader>a", ":call vimrc#AutoFmtToggle()<CR>")
+map("n", "<leader>a", function()
+  local fo = vim.bo.formatoptions
+  if fo:find("a") then
+    vim.bo.formatoptions = fo:gsub("a", "")
+    vim.print("-a")
+  else
+    vim.bo.formatoptions = fo .. "a"
+    vim.print("+a")
+  end
+end)
 
 -- LSP features
 

mercurial