Add autocommand to run just on :make when justfile is present and add ccls

This commit is contained in:
2025-02-05 16:00:57 +01:00
parent 92a6cfc071
commit 14edeb2713
2 changed files with 22 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]]
vim.cmd 'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!'
-- Array of file names indicating root directory. Modify to your liking.
local root_names = { '.git', 'Makefile' }
local root_names = { '.git', 'Makefile', 'justfile' }
-- Cache to use for speed up (at cost of possibly outdated results)
local root_cache = {}
@@ -35,3 +35,16 @@ end
local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {})
vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root })
local function set_makeprg()
local cwd = vim.fn.getcwd()
if vim.fn.filereadable(cwd .. '/justfile') == 1 then
vim.o.makeprg = 'just'
elseif vim.fn.filereadable(cwd .. '/Makefile') == 1 then
vim.o.makeprg = 'make'
end
end
local makeprg_augroup = vim.api.nvim_create_augroup('MyMakeprg', {})
vim.api.nvim_create_autocmd('BufEnter', { pattern = '*', group = makeprg_augroup, callback = set_makeprg, })