From c610d1ce1af107ae302b992f3d24f5e083ed5c78 Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Wed, 24 Aug 2022 14:54:19 +0300
Subject: [PATCH] Removed the need for my own augroup helper

---
 dotfiles/neovim/ftplugin/hkf.lua              |  1 +
 dotfiles/neovim/lua/my/helpers/augroup.lua    | 14 -----
 .../lua/my/helpers/update-nix-fetchgit.lua    |  6 +--
 dotfiles/neovim/lua/my/options/folding.lua    | 10 +---
 dotfiles/neovim/lua/my/plugins/comment.lua    | 26 ---------
 dotfiles/neovim/lua/my/plugins/init.lua       |  2 +-
 .../neovim/lua/my/plugins/lh-brackets.lua     | 53 -------------------
 dotfiles/neovim/lua/my/plugins/lspconfig.lua  | 13 +++--
 8 files changed, 12 insertions(+), 113 deletions(-)
 delete mode 100644 dotfiles/neovim/lua/my/helpers/augroup.lua
 delete mode 100644 dotfiles/neovim/lua/my/plugins/comment.lua
 delete mode 100644 dotfiles/neovim/lua/my/plugins/lh-brackets.lua

diff --git a/dotfiles/neovim/ftplugin/hkf.lua b/dotfiles/neovim/ftplugin/hkf.lua
index d1f855d..009ffd2 100644
--- a/dotfiles/neovim/ftplugin/hkf.lua
+++ b/dotfiles/neovim/ftplugin/hkf.lua
@@ -1 +1,2 @@
 vim.cmd("syntax hkf")
+vim.api.nvim_buf_set_option(0, "commentstring", "-- %s")
diff --git a/dotfiles/neovim/lua/my/helpers/augroup.lua b/dotfiles/neovim/lua/my/helpers/augroup.lua
deleted file mode 100644
index 12a6372..0000000
--- a/dotfiles/neovim/lua/my/helpers/augroup.lua
+++ /dev/null
@@ -1,14 +0,0 @@
-local M = {}
-
-function M.augroup(name, inside)
-    vim.cmd('augroup ' .. name)
-    vim.cmd('autocmd!')
-    inside()
-    vim.cmd('augroup END')
-end
-
-function M.autocmd(event, glob, action)
-    vim.cmd('autocmd ' .. event .. ' ' .. glob .. ' ' .. action)
-end
-
-return M
diff --git a/dotfiles/neovim/lua/my/helpers/update-nix-fetchgit.lua b/dotfiles/neovim/lua/my/helpers/update-nix-fetchgit.lua
index f49b62a..7ce4505 100644
--- a/dotfiles/neovim/lua/my/helpers/update-nix-fetchgit.lua
+++ b/dotfiles/neovim/lua/my/helpers/update-nix-fetchgit.lua
@@ -1,9 +1,9 @@
 local M = {}
 
 function M.update()
-    require("my.helpers").saveCursor(function()
-        vim.cmd(":%!update-nix-fetchgit")
-    end)
+  require("my.helpers").saveCursor(function()
+    vim.cmd(":%!update-nix-fetchgit")
+  end)
 end
 
 return M
diff --git a/dotfiles/neovim/lua/my/options/folding.lua b/dotfiles/neovim/lua/my/options/folding.lua
index 0d0fe48..e3b3266 100644
--- a/dotfiles/neovim/lua/my/options/folding.lua
+++ b/dotfiles/neovim/lua/my/options/folding.lua
@@ -1,15 +1,7 @@
 local M = {}
 
 function M.setup()
-    vim.o.foldmethod = "marker"
-
-    --     vim.cmd([[
-    --       augroup remember_folds
-    -- autocmd!
-    -- autocmd BufWinLeave *.* if &ft !=# 'help' | mkview | endif
-    -- autocmd BufWinEnter *.* if &ft !=# 'help' | silent! loadview | endif
-    --       augroup END
-    --     ]])
+  vim.o.foldmethod = "marker"
 end
 
 return M
diff --git a/dotfiles/neovim/lua/my/plugins/comment.lua b/dotfiles/neovim/lua/my/plugins/comment.lua
deleted file mode 100644
index 229d835..0000000
--- a/dotfiles/neovim/lua/my/plugins/comment.lua
+++ /dev/null
@@ -1,26 +0,0 @@
-local A = require("my.helpers.augroup")
-local M = {}
-
-local extraCommentStrings = { lean = "/- %s -/", bkf = "-- %s" }
-
--- Update comments for certain languages
-function M.setCommentString(extension, commentString)
-  A.augroup('set-commentstring-' .. extension, function()
-    local action =
-    ':lua vim.api.nvim_buf_set_option(0, "commentstring", "' ..
-        commentString .. '")'
-
-    A.autocmd('BufEnter', '*.' .. extension, action)
-    A.autocmd('BufFilePost', '*.' .. extension, action)
-  end)
-end
-
-function M.setup()
-  require('nvim_comment').setup()
-
-  for lang, commentString in pairs(extraCommentStrings) do
-    M.setCommentString(lang, commentString)
-  end
-end
-
-return M
diff --git a/dotfiles/neovim/lua/my/plugins/init.lua b/dotfiles/neovim/lua/my/plugins/init.lua
index d84c2aa..bb85c39 100644
--- a/dotfiles/neovim/lua/my/plugins/init.lua
+++ b/dotfiles/neovim/lua/my/plugins/init.lua
@@ -4,6 +4,7 @@ local M = {}
 function M.setup()
   require('nvim-autopairs').setup()
   require "gitlinker".setup()
+  require('nvim_comment').setup()
 
   vscode.unless(function()
     require("presence"):setup({})
@@ -20,7 +21,6 @@ function M.setup()
   end)
 
   require("my.plugins.neogit").setup()
-  require("my.plugins.comment").setup()
   require("my.plugins.telescope").setup()
 
   -- require("my.plugins.idris").setup()
diff --git a/dotfiles/neovim/lua/my/plugins/lh-brackets.lua b/dotfiles/neovim/lua/my/plugins/lh-brackets.lua
deleted file mode 100644
index f54977d..0000000
--- a/dotfiles/neovim/lua/my/plugins/lh-brackets.lua
+++ /dev/null
@@ -1,53 +0,0 @@
-local A = require("my.helpers.augroup")
-local arpeggio = require("my.plugins.arpeggio")
-local M = {}
-
-local extraBrackets = {
-  lean = { { "⟨", "⟩" } }, -- lean
-  all = {
-    -- {"(", ")"}, {"[", "]"}, {"'", "'"}, {'"', '"'}, {"{", "}"}, {"`", "`"}
-  } -- more general stuff
-}
-
-function M.createBracketCommand(lhs, rhs, isGlobal, opts)
-  local suffix = ""
-  if isGlobal then suffix = "!" end
-
-  return ":Brackets" .. suffix .. " " .. lhs .. " " .. rhs .. " " ..
-      (opts or "")
-end
-
-function M.createBracket(lhs, rhs, isGlobal, opts)
-  vim.cmd(M.createBracketCommand(lhs, rhs, isGlobal, opts))
-end
-
-function M.setup()
-
-  if arpeggio == nil then return end
-
-  vim.g.marker_define_jump_mappings = 0 -- disable automatic binding of marker jumping (conflicts with tmux-vim-navigator)
-
-  arpeggio.chord("nv", "sj", '<Plug>MarkersJumpF')
-  arpeggio.chord("nv", "sk", '<Plug>MarkersJumpB')
-  arpeggio.chord("nv", "mi", '<Plug>MarkersMark')
-  arpeggio.chord("nv", "ml", '<Plug>MarkersCloseAllAndJumpToLast')
-  arpeggio.chord("nv", "mo", '<Plug>MarkersJumpOutside')
-
-  for key, brackets in pairs(extraBrackets) do
-    A.augroup('custom-brackets' .. key, function()
-      for _, v in ipairs(brackets) do
-        local action = M.createBracketCommand(v[1], v[2], 0, v[3] or "")
-        local glob = '*.' .. key
-
-        if key == "all" then
-          -- The all key just matches everything
-          glob = "*"
-        end
-
-        A.autocmd('BufEnter', glob, action)
-      end
-    end)
-  end
-end
-
-return M
diff --git a/dotfiles/neovim/lua/my/plugins/lspconfig.lua b/dotfiles/neovim/lua/my/plugins/lspconfig.lua
index 72b4f06..e721fbb 100644
--- a/dotfiles/neovim/lua/my/plugins/lspconfig.lua
+++ b/dotfiles/neovim/lua/my/plugins/lspconfig.lua
@@ -1,7 +1,6 @@
 local M = {}
 
 local function map(buf, mode, lhs, rhs, opts)
-
   local options = { noremap = true, silent = true }
   if opts then options = vim.tbl_extend('force', options, opts) end
   vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options)
@@ -11,14 +10,14 @@ function M.on_attach(client, bufnr)
   -- Enable completion triggered by <c-x><c-o>
   vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
 
+
   if client.server_capabilities.documentFormattingProvider then
     print("Initializing formatter...")
-    vim.cmd([[
-            augroup LspFormatting
-                autocmd! * <buffer>
-                autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
-            augroup END
-            ]])
+
+    vim.api.nvim_create_autocmd("BufWritePre", {
+      group = vim.api.nvim_create_augroup("LspFormatting", {}),
+      callback = vim.lsp.buf.formatting_sync
+    })
   end
 
   print("Setting up keybinds...")