239 lines
4.9 KiB
Lua
239 lines
4.9 KiB
Lua
-- The MIT License (MIT)
|
|
--
|
|
-- Copyright © 2026 Scott E. Graves <scott.e.graves@protonmail.com>
|
|
--
|
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
-- and associated documentation files (the “Software”), to deal in the Software without restriction,
|
|
-- including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
-- sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
-- furnished to do so, subject to the following conditions:
|
|
--
|
|
-- The above copyright notice and this permission notice shall be included in all copies or
|
|
-- substantial portions of the Software.
|
|
--
|
|
-- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
-- BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
--
|
|
local utils = require("darcula.utils")
|
|
|
|
local group =
|
|
utils.augroup_with_autocmd(
|
|
"DarculaAutoCommands",
|
|
"BufReadPost",
|
|
"*",
|
|
function()
|
|
local pos = vim.fn.line('\'"')
|
|
if
|
|
pos >= 1 and pos <= vim.fn.line("$") and vim.bo.filetype ~= "commit" and
|
|
vim.bo.filetype ~= "rebase"
|
|
then
|
|
vim.cmd('normal! g`"')
|
|
end
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"FileChangedShellPost",
|
|
"*",
|
|
function()
|
|
local filename = utils.get_current_filename()
|
|
vim.notify("File changed on disk:\n" .. filename, vim.log.levels.WARN)
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
{"FocusGained", "BufEnter", "CursorHold", "CursorHoldI"},
|
|
"*",
|
|
function()
|
|
local m = vim.fn.mode(0)
|
|
if m ~= "c" and m ~= "cv" and m ~= "t" and vim.o.buftype ~= "nofile" then
|
|
vim.cmd("silent! checktime")
|
|
end
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"TextYankPost",
|
|
"*",
|
|
function()
|
|
vim.highlight.on_yank({timeout = 250})
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"FileType",
|
|
"lua",
|
|
function()
|
|
vim.cmd("hi luaParenError guibg=NONE")
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"ColorScheme",
|
|
"*",
|
|
function()
|
|
NV_DARCULA_COLOR_SCHEME =
|
|
vim.api.nvim_exec2("colorscheme", {output = true}).output
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"VimEnter",
|
|
"*",
|
|
function()
|
|
NV_Darcula_Set_Gui_Font(0)
|
|
NV_Darcula_Set_Gui_Popup(false)
|
|
end
|
|
)
|
|
|
|
utils.autocmd(group, "DirChanged", "*", NV_Darcula_Load_RC)
|
|
utils.autocmd(group, "VimEnter", "*", NV_Darcula_Load_RC)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"FileType",
|
|
"help",
|
|
function()
|
|
vim.opt_local.signcolumn = "no"
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"User",
|
|
{"FugitiveChanged", "GitSignsUpdate"},
|
|
function()
|
|
local api = require("nvim-tree.api")
|
|
if api.tree.is_visible() then
|
|
pcall(api.tree.reload)
|
|
end
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"FileType",
|
|
"*",
|
|
function(args)
|
|
pcall(vim.treesitter.start, args.buf)
|
|
end
|
|
)
|
|
|
|
if not NV_DARCULA_ENABLE_COC then
|
|
utils.autocmd(
|
|
group,
|
|
"User",
|
|
{
|
|
"MiniCompletionWindowOpen",
|
|
"MiniCompletionWindowUpdate"
|
|
},
|
|
function(args)
|
|
local data = args.data
|
|
if not data or not data.win_id then
|
|
return
|
|
end
|
|
|
|
if data.kind ~= "info" and data.kind ~= "signature" then
|
|
return
|
|
end
|
|
|
|
if vim.api.nvim_win_is_valid(data.win_id) then
|
|
vim.api.nvim_win_set_config(
|
|
data.win_id,
|
|
{
|
|
title = ""
|
|
}
|
|
)
|
|
end
|
|
end
|
|
)
|
|
end
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"BufEnter",
|
|
"*",
|
|
function()
|
|
if vim.bo.filetype == "fugitive" or vim.bo.filetype == "gitcommit" then
|
|
vim.cmd("resize 15")
|
|
end
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"BufWritePost",
|
|
"*",
|
|
function()
|
|
if NV_DARCULA_ENABLE_FORMATTING then
|
|
vim.cmd("FormatWriteLock")
|
|
end
|
|
end
|
|
)
|
|
|
|
if not NV_DARCULA_ENABLE_COC then
|
|
utils.autocmd(
|
|
group,
|
|
{"CursorHold"},
|
|
"*",
|
|
function()
|
|
vim.diagnostic.open_float(nil, {focus = false})
|
|
end
|
|
)
|
|
end
|
|
|
|
if NV_DARCULA_ENABLE_COC then
|
|
local show_signature_help = function()
|
|
if vim.bo.buftype ~= "prompt" and vim.bo.buftype ~= "nofile" then
|
|
vim.fn.CocActionAsync("showSignatureHelp")
|
|
end
|
|
end
|
|
|
|
utils.autocmd(group, "User", "CocJumpPlaceholder", show_signature_help)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
{"InsertEnter", "TextChangedI"},
|
|
"*",
|
|
show_signature_help
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"CursorHold",
|
|
"*",
|
|
function()
|
|
if vim.bo.buftype ~= "prompt" and vim.bo.buftype ~= "nofile" then
|
|
vim.fn.CocActionAsync("highlight")
|
|
end
|
|
end
|
|
)
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"User",
|
|
"CocNvimInit",
|
|
function()
|
|
vim.notify("Initialized coc.nvim for LSP support", vim.log.levels.INFO)
|
|
end
|
|
)
|
|
end
|
|
|
|
utils.autocmd(
|
|
group,
|
|
"VimResized",
|
|
"*",
|
|
function()
|
|
MiniNotify.refresh()
|
|
end
|
|
)
|