-- The MIT License (MIT) -- -- Copyright © 2026 Scott E. Graves -- -- 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. -- require("darcula.utils.string") require("darcula.utils.table") local utils = require("darcula.utils") local utils_os = require("darcula.utils.os") local utils_ui = require("darcula.utils.ui") NV_Darcula_Close_Invalid = function() local buffer_numbers = vim.api.nvim_list_bufs() for _, buffer_number in pairs(buffer_numbers) do local buf_info = vim.fn.getbufinfo(buffer_number) if buf_info ~= nil then buf_info = buf_info[1] if buf_info.windows ~= nil and #buf_info.windows > 0 then local win_type = vim.fn.win_gettype(buf_info.windows[1]) if win_type ~= nil and win_type == "popup" then vim.api.nvim_buf_delete(buffer_number, {force = true}) end end end end end NV_Darcula_Close_All = function(write_all) NV_Darcula_Close_Invalid() write_all = write_all or false vim.cmd(utils.iff(write_all, "wqa!", "qa!")) end NV_Darcula_Coc_Completion_Confirm = function() if vim.fn["coc#pum#visible"]() ~= 0 then return vim.fn["coc#pum#confirm"]() end return "u=coc#on_enter()" end NV_Darcula_Coc_Float_Scroll = function(fwd) if vim.fn["coc#float#has_scroll"]() == 1 then vim.fn["coc#float#scroll"](utils.iff(fwd and fwd ~= 0, 1, 0)) return end return "" end NV_Darcula_Coc_Float_Scroll_Insert_Mode = function(fwd) if vim.fn["coc#float#has_scroll"]() == 1 then return "=coc#float#scroll(" .. utils.iff(fwd and fwd ~= 0, 1, 0) .. ")" end return "<" .. utils.iff(fwd and fwd ~= 0, "Right", "Left") .. ">" end NV_Darcula_Coc_Shift_Tab_Complete = function() if vim.fn["coc#pum#visible"]() ~= 0 then return vim.fn["coc#pum#prev"](1) end return "" end NV_Darcula_Coc_Tab_Complete = function() if vim.fn["coc#pum#visible"]() ~= 0 then return vim.fn["coc#pum#next"](1) end local check_backspace = function() local col = vim.api.nvim_win_get_cursor(0)[2] return (col == 0 or vim.api.nvim_get_current_line():sub(col, col):match("%s")) and true end if check_backspace() then return "" end return vim.fn["coc#refresh"]() end NV_Darcula_Copen = function() vim.cmd(":Copen") vim.cmd(":wincmd j") end NV_Darcula_Font_Name = function() return "JetBrainsMonoNL NFM" end NV_Darcula_Git_Root = function(cwd) cwd = cwd or vim.loop.cwd() local cmd = {"git", "-C", cwd, "rev-parse", "--show-toplevel"} local output = vim.fn.systemlist(cmd) if vim.v.shell_error == 0 and output[1] and #output[1] > 0 then return vim.fn.fnamemodify(output[1], ":p") end return cwd end NV_Darcula_Grab_Selection = function(cb) local selection = utils.get_visual_text() vim.schedule( function() cb(selection) end ) end NV_Darcula_Load_RC = function() local local_vimrc = vim.fn.getcwd() .. "/.nvimrc" if vim.loop.fs_stat(local_vimrc) then vim.cmd("source " .. local_vimrc) end end NV_Darcula_LSP_Restart = function() if NV_DARCULA_ENABLE_COC then pcall( function() if vim.fn["coc#rpc#ready"] ~= nil and vim.fn["coc#rpc#ready"]() == 1 then vim.cmd(":silent! :CocRestart") NV_Darcula_Refresh_Buffer() end end ) return end vim.cmd("LspRestart") NV_Darcula_Refresh_Buffer() end NV_Darcula_LSP_Stop = function() if NV_DARCULA_ENABLE_COC then vim.cmd(":silent! :CocStop") end end NV_Darcula_Open_Nvim_Tree = function(sync) if sync and sync ~= 0 then vim.cmd("NvimTreeFindFile") return end vim.cmd("NvimTreeFindFileToggle") end NV_Darcula_Refresh_Buffer = function() vim.cmd(":silent! :e%") end NV_Darcula_Set_Gui_Font = function(size) if utils_ui.is_gui() then if vim.env.MY_STATE_HOME ~= nil and not utils_os.is_windows then if utils.file_exists(vim.env.MY_STATE_HOME .. "/.desktop") then if size == 0 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h18") return end if size == 1 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h15") return end if size == 2 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h21") return end if size == 3 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h28") return end end if utils.file_exists(vim.env.MY_STATE_HOME .. "/.laptop2") then if size == 0 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h22") return end if size == 1 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h19") return end if size == 2 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h25") return end if size == 3 then vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h12", ":h32") return end return end if utils.file_exists(vim.env.MY_STATE_HOME .. "/.laptop") then -- vim.opt.guifont = -- NV_Darcula_Font_Name() .. utils.iff(util_os.is_mac, ":h12", ":h18") return end end vim.opt.guifont = NV_Darcula_Font_Name() .. utils.iff(utils_os.is_mac, ":h15", ":h18") end end NV_Darcula_Set_Gui_Popup = function(enable) if utils_ui.is_gui() and vim.fn.exists(":GuiPopupmenu") ~= 0 then vim.cmd("GuiPopupmenu " .. utils.iff(enable, "1", "0")) end end NV_Darcula_Show_Documentation = function() local file_type = vim.bo.filetype if table.contains({"vim", "help"}, file_type) then NV_Darcula_Show_Vim_Documentation(false) return end if NV_DARCULA_ENABLE_COC then if vim.fn.CocAction("hasProvider", "hover") then vim.api.nvim_feedkeys( vim.api.nvim_replace_termcodes("", true, false, true), "n", true ) vim.fn.CocActionAsync("doHover") return end return end local bufnr = vim.api.nvim_get_current_buf() local clients = vim.lsp.get_clients( { bufnr = bufnr, method = "textDocument/hover" } ) if #clients == 0 then return end vim.lsp.buf.hover() end NV_Darcula_Show_Man_Documentation = function(visual) local is_cpp = utils.is_c_family_file() if visual then if is_cpp then require("cppman").open(utils.get_visual_text(), true) return end vim.cmd("vertical Man " .. vim.fn.escape(utils.get_visual_text(), " ")) return end if is_cpp then require("cppman").open(utils.cword(), true) return end vim.cmd("vertical Man") end NV_Darcula_Show_Vim_Documentation = function(visual) if visual then vim.cmd("vertical help " .. utils.get_visual_text()) return end vim.cmd("vertical help " .. utils.cword()) end NV_Darcula_Write_All = function() vim.cmd("silent! wa!") end