refactor: replace direct API calls with helper functions for autocommands
This commit is contained in:
+9
-53
@@ -6,57 +6,9 @@
|
||||
local autogrp = vim.api.nvim_create_augroup
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
-- GIT CONFLICT MARKERS
|
||||
-- if there are conflicts, jump to first conflict, highlight conflict markers,
|
||||
-- and disable diagnostics (simplified version of `git-conflict.nvim`)
|
||||
-- autogrp("GitConflictMarkers", { clear = true })
|
||||
-- autocmd({ "BufEnter", "FocusGained" }, {
|
||||
-- group = "GitConflictMarkers",
|
||||
-- callback = function(ctx)
|
||||
-- local hlgroup = "DiagnosticVirtualTextInfo" -- CONFIG
|
||||
--
|
||||
-- if not vim.api.nvim_buf_is_valid(ctx.buf) then
|
||||
-- return
|
||||
-- end
|
||||
-- vim.system(
|
||||
-- { "git", "diff", "--check", "--", vim.api.nvim_buf_get_name(ctx.buf) },
|
||||
-- {},
|
||||
-- vim.schedule_wrap(function(out)
|
||||
-- local noConflicts = out.code == 0
|
||||
-- local noGitRepo =
|
||||
-- vim.startswith(out.stdout, "warning: Not a git repository")
|
||||
-- if noConflicts or noGitRepo then
|
||||
-- return
|
||||
-- end
|
||||
--
|
||||
-- local ns = vim.api.nvim_create_namespace("conflictMarkers")
|
||||
-- local firstConflict
|
||||
-- for conflictLnum in out.stdout:gmatch("(%d+): leftover conflict marker") do
|
||||
-- local lnum = tonumber(conflictLnum)
|
||||
-- vim.api.nvim_buf_add_highlight(ctx.buf, ns, hlgroup, lnum - 1, 0, -1)
|
||||
-- if not firstConflict then
|
||||
-- firstConflict = lnum
|
||||
-- end
|
||||
-- end
|
||||
-- if not firstConflict then
|
||||
-- return
|
||||
-- end
|
||||
--
|
||||
-- vim.api.nvim_win_set_cursor(0, { firstConflict, 0 })
|
||||
-- vim.diagnostic.enable(false, { bufnr = ctx.buf })
|
||||
-- vim.notify_once(
|
||||
-- "Conflict markers found.",
|
||||
-- nil,
|
||||
-- { title = "Git Conflicts" }
|
||||
-- )
|
||||
-- end)
|
||||
-- )
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
-- LazyGit root detection
|
||||
if pcall(require, "lazygit.utils") then
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
autocmd("BufEnter", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
require("lazygit.utils").project_root_dir()
|
||||
@@ -67,10 +19,10 @@ end
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━ Set up Qalc keymappings ━━━━━━━━━━━━━━━━━━━━━━━
|
||||
if pcall(require, "qalc") then
|
||||
-- Create a group for filetype-specific mappings
|
||||
vim.api.nvim_create_augroup("QalcFileTypeMappings", { clear = true })
|
||||
autogrp("QalcFileTypeMappings", { clear = true })
|
||||
|
||||
-- Create an autocommand for the qalc filetype
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
autocmd("FileType", {
|
||||
pattern = "qalc",
|
||||
group = "QalcFileTypeMappings",
|
||||
callback = function()
|
||||
@@ -108,6 +60,10 @@ local load_highlight = require("utils.highlight")
|
||||
load_highlight.setup_autocommands()
|
||||
load_highlight.setup_dashboard_highlight()
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ Set up cpp picker ━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- Adds a keymap for quicker picking when in cpp files
|
||||
require("data.autocmd").cpp_picker()
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ Set up nvim_exec ━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
-- Function to check and execute the NVIM_EXEC environment variable
|
||||
@@ -121,9 +77,9 @@ local function execute_nvim_exec()
|
||||
end
|
||||
|
||||
-- Define an autogroup for the autocmd
|
||||
vim.api.nvim_create_augroup("NvimExec", { clear = true })
|
||||
autogrp("NvimExec", { clear = true })
|
||||
-- Define an autocmd to run the function at startup
|
||||
vim.api.nvim_create_autocmd("VimEnter", {
|
||||
autocmd("VimEnter", {
|
||||
group = "NvimExec",
|
||||
callback = execute_nvim_exec,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user