Pārlūkot izejas kodu

[Bugfix]: Allow user autocmds (#1776)

Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
Subho Banerjee 3 gadi atpakaļ
vecāks
revīzija
281c54ba55
2 mainītis faili ar 60 papildinājumiem un 98 dzēšanām
  1. 3 0
      lua/lvim/config/init.lua
  2. 57 98
      lua/lvim/core/autocmds.lua

+ 3 - 0
lua/lvim/config/init.lua

@@ -27,6 +27,9 @@ function M:init()
   local settings = require "lvim.config.settings"
   settings.load_options()
 
+  local autocmds = require "lvim.core.autocmds"
+  lvim.autocommands = autocmds.load_augroups()
+
   local lvim_lsp_config = require "lvim.lsp.config"
   lvim.lsp = vim.deepcopy(lvim_lsp_config)
 

+ 57 - 98
lua/lvim/core/autocmds.lua

@@ -1,110 +1,69 @@
-local autocommands = {}
-local user_config_file = require("lvim.config"):get_user_config_path()
+local M = {}
 
-lvim.autocommands = {
-  _general_settings = {
-    {
-      "Filetype",
-      "*",
-      "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
-    },
-    {
-      "FileType",
-      "qf",
-      "nnoremap <silent> <buffer> q :q<CR>",
+--- Load the default set of autogroups and autocommands.
+function M.load_augroups()
+  local user_config_file = vim.fn.resolve(require("lvim.config"):get_user_config_path())
+
+  return {
+    _general_settings = {
+      {
+        "Filetype",
+        "*",
+        "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
+      },
+      { "FileType", "qf,help,man", "nnoremap <silent> <buffer> q :close<CR>" },
+      {
+        "TextYankPost",
+        "*",
+        "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
+      },
+      {
+        "BufWinEnter",
+        "dashboard",
+        "setlocal cursorline signcolumn=yes cursorcolumn number",
+      },
+      { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" },
+      { "FileType", "qf", "set nobuflisted" },
+      -- { "VimLeavePre", "*", "set title set titleold=" },
     },
-    {
-      "FileType",
-      "lsp-installer",
-      "nnoremap <silent> <buffer> q :q<CR>",
+    _formatoptions = {
+      {
+        "BufWinEnter,BufRead,BufNewFile",
+        "*",
+        "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+      },
     },
-    {
-      "TextYankPost",
-      "*",
-      "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
+    _filetypechanges = {
+      { "BufWinEnter", ".tf", "setlocal filetype=terraform" },
+      { "BufRead", "*.tf", "setlocal filetype=terraform" },
+      { "BufNewFile", "*.tf", "setlocal filetype=terraform" },
+      { "BufWinEnter", ".zsh", "setlocal filetype=sh" },
+      { "BufRead", "*.zsh", "setlocal filetype=sh" },
+      { "BufNewFile", "*.zsh", "setlocal filetype=sh" },
     },
-    {
-      "BufWinEnter",
-      "*",
-      "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+    _git = {
+      { "FileType", "gitcommit", "setlocal wrap" },
+      { "FileType", "gitcommit", "setlocal spell" },
     },
-    {
-      "BufWinEnter",
-      "dashboard",
-      "setlocal cursorline signcolumn=yes cursorcolumn number",
+    _markdown = {
+      { "FileType", "markdown", "setlocal wrap" },
+      { "FileType", "markdown", "setlocal spell" },
     },
-    {
-      "BufRead",
-      "*",
-      "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+    _buffer_bindings = {
+      { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
     },
-    {
-      "BufNewFile",
-      "*",
-      "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
+    _auto_resize = {
+      -- will cause split windows to be resized evenly if main window is resized
+      { "VimResized", "*", "tabdo wincmd =" },
     },
-    { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" },
-    {
-      "FileType",
-      "qf",
-      "set nobuflisted",
+    _general_lsp = {
+      { "FileType", "lspinfo,lsp-installer,null-ls-info", "nnoremap <silent> <buffer> q :close<CR>" },
     },
-    -- { "VimLeavePre", "*", "set title set titleold=" },
-  },
-  _filetypechanges = {
-    { "BufWinEnter", ".tf", "setlocal filetype=terraform" },
-    { "BufRead", "*.tf", "setlocal filetype=terraform" },
-    { "BufNewFile", "*.tf", "setlocal filetype=terraform" },
-    { "BufWinEnter", ".zsh", "setlocal filetype=sh" },
-    { "BufRead", "*.zsh", "setlocal filetype=sh" },
-    { "BufNewFile", "*.zsh", "setlocal filetype=sh" },
-  },
-  -- _solidity = {
-  --     {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'},
-  --     {'BufNewFile', '*.sol', 'setlocal filetype=solidity'}
-  -- },
-  -- _gemini = {
-  --     {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},
-  --     {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}
-  -- },
-  _git = {
-    { "FileType", "gitcommit", "setlocal wrap" },
-    { "FileType", "gitcommit", "setlocal spell" },
-  },
-  _markdown = {
-    { "FileType", "markdown", "setlocal wrap" },
-    { "FileType", "markdown", "setlocal spell" },
-  },
-  _buffer_bindings = {
-    { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
-  },
-  _auto_resize = {
-    -- will cause split windows to be resized evenly if main window is resized
-    { "VimResized", "*", "wincmd =" },
-  },
-  _packer_compile = {
-    -- will run PackerCompile after writing plugins.lua
-    { "BufWritePost", "plugins.lua", "PackerCompile" },
-  },
-  _general_lsp = {
-    { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
-  },
-
-  -- _fterm_lazygit = {
-  --   -- will cause esc key to exit lazy git
-  --   {"TermEnter", "*", "call LazyGitNativation()"}
-  -- },
-  -- _mode_switching = {
-  --   -- will switch between absolute and relative line numbers depending on mode
-  --   {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'},
-  --   {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'},
-  --   {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'},
-  --   {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'},
-  -- },
-  custom_groups = {},
-}
+    custom_groups = {},
+  }
+end
 
-function autocommands.define_augroups(definitions) -- {{{1
+function M.define_augroups(definitions) -- {{{1
   -- Create autocommand groups based on the passed definitions
   --
   -- The key will be the name of the group, and each definition
@@ -126,4 +85,4 @@ function autocommands.define_augroups(definitions) -- {{{1
   end
 end
 
-return autocommands
+return M