fixed structure, removed backups, added compilation features for C, C++, and ASM
This commit is contained in:
1
nvim/.gitignore
vendored
1
nvim/.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
pack/
|
pack/
|
||||||
|
backups/
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
-- General
|
|
||||||
vim.o.number = true
|
|
||||||
|
|
||||||
-- gruvbox
|
|
||||||
vim.o.background = "dark"
|
|
||||||
vim.cmd([[colorscheme gruvbox]])
|
|
||||||
|
|
||||||
|
|
||||||
-- treesitter
|
|
||||||
require'nvim-treesitter.configs'.setup{
|
|
||||||
highlight = {
|
|
||||||
enable = true,
|
|
||||||
},
|
|
||||||
indent = {
|
|
||||||
enable = true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- vimwiki
|
|
||||||
vim.cmd([[
|
|
||||||
set nocompatible
|
|
||||||
filetype plugin on
|
|
||||||
syntax on
|
|
||||||
]])
|
|
||||||
vim.g.vimwiki_list = {
|
|
||||||
{
|
|
||||||
path = '~/vimwiki/',
|
|
||||||
syntax = 'markdown',
|
|
||||||
ext = '.md'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- telescope
|
|
||||||
local builtin = require('telescope.builtin')
|
|
||||||
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
|
|
||||||
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
|
|
||||||
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
|
|
||||||
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })
|
|
||||||
|
|
||||||
|
|
||||||
-- lualine
|
|
||||||
require('lualine').setup()
|
|
||||||
|
|
||||||
|
|
||||||
-- comment
|
|
||||||
require('Comment').setup()
|
|
||||||
|
|
||||||
|
|
||||||
-- autopairs
|
|
||||||
require('nvim-autopairs').setup()
|
|
||||||
|
|
||||||
|
|
||||||
-- cmp
|
|
||||||
local cmp = require'cmp'
|
|
||||||
cmp.setup({
|
|
||||||
snippet = {
|
|
||||||
expand = function(args)
|
|
||||||
require('luasnip').lsp_expand(args.body)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
})
|
|
||||||
cmp.setup.cmdline(':', {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = cmp.config.sources({
|
|
||||||
{ name = 'path' }
|
|
||||||
}, {
|
|
||||||
{ name = 'cmdline' }
|
|
||||||
}),
|
|
||||||
matching = { disallow_symbol_nonprefix_matching = false }
|
|
||||||
})
|
|
||||||
-- TODO complete https://github.com/hrsh7th/nvim-cmp
|
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
-- File: ~/.config/nvim/lua/compilation.lua
|
-- File: ~/.config/nvim/lua/compilation.lua
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
local exec_terminal_buf = nil -- Module-level variable to track the exec terminal buffer
|
||||||
|
|
||||||
|
-- Utility function for non-blocking notifications
|
||||||
|
local function notify(msg, hl)
|
||||||
|
vim.api.nvim_echo({{msg, hl}}, true, {})
|
||||||
|
end
|
||||||
|
|
||||||
-- Function to compile and run the current file
|
-- Function to compile and run the current file
|
||||||
function M.compile_and_run()
|
function M.compile_and_run()
|
||||||
@@ -9,11 +15,11 @@ function M.compile_and_run()
|
|||||||
|
|
||||||
-- Check if the current buffer is a directory
|
-- Check if the current buffer is a directory
|
||||||
if vim.fn.isdirectory(file) == 1 then
|
if vim.fn.isdirectory(file) == 1 then
|
||||||
vim.notify("Cannot compile a directory. Please open a source file.", vim.log.levels.ERROR)
|
notify("Cannot compile a directory. Please open a source file.", "ErrorMsg")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Determine the filetype (c, cpp, etc.)
|
-- Determine the filetype (c, cpp, asm, etc.)
|
||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
local compiler = ''
|
local compiler = ''
|
||||||
local flags = ''
|
local flags = ''
|
||||||
@@ -25,30 +31,34 @@ function M.compile_and_run()
|
|||||||
elseif filetype == 'cpp' then
|
elseif filetype == 'cpp' then
|
||||||
compiler = 'g++'
|
compiler = 'g++'
|
||||||
flags = '-lm -O3'
|
flags = '-lm -O3'
|
||||||
|
elseif filetype == 'asm' then
|
||||||
|
compiler = 'nasm'
|
||||||
|
flags = '-f elf64'
|
||||||
else
|
else
|
||||||
vim.notify("Unsupported file type: " .. filetype, vim.log.levels.ERROR)
|
notify("Unsupported file type: " .. filetype, "ErrorMsg")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the base name of the file without extension
|
-- Get the base name of the file without extension
|
||||||
local output_name = vim.fn.expand('%:t:r') -- %:t:r extracts the filename without extension
|
local output_name = vim.fn.expand('%:t:r') -- %:t:r extracts the filename without extension
|
||||||
|
|
||||||
-- Construct the compile command
|
if filetype == 'asm' then
|
||||||
local compile_cmd = string.format('%s %s "%s" -o "%s"', compiler, flags, file, output_name)
|
-- Assemble the asm file to object file
|
||||||
|
local assemble_cmd = string.format('%s %s "%s" -o "%s.o"', compiler, flags, file, output_name)
|
||||||
|
|
||||||
-- Notify the user about the compilation process
|
-- Notify the user about the assembly process
|
||||||
vim.notify("Compiling...", vim.log.levels.INFO)
|
notify("Assembling...", "MoreMsg")
|
||||||
|
|
||||||
-- Execute the compile command
|
-- Execute the assemble command
|
||||||
local compile_output = vim.fn.system(compile_cmd)
|
local assemble_output = vim.fn.system(assemble_cmd)
|
||||||
local compile_exit = vim.v.shell_error
|
local assemble_exit = vim.v.shell_error
|
||||||
|
|
||||||
-- Check if compilation was successful
|
-- Check if assembly was successful
|
||||||
if compile_exit ~= 0 then
|
if assemble_exit ~= 0 then
|
||||||
vim.notify("Compilation failed:\n" .. compile_output, vim.log.levels.ERROR)
|
notify("Assembly failed:\n" .. assemble_output, "ErrorMsg")
|
||||||
-- Populate quickfix list with errors
|
-- Populate quickfix list with errors and warnings
|
||||||
vim.fn.setqflist({}, ' ')
|
vim.fn.setqflist({}, ' ')
|
||||||
for line in compile_output:gmatch("[^\r\n]+") do
|
for line in assemble_output:gmatch("[^\r\n]+") do
|
||||||
if line:match("error") or line:match("warning") then
|
if line:match("error") or line:match("warning") then
|
||||||
vim.fn.setqflist({}, 'a', { lines = { line } })
|
vim.fn.setqflist({}, 'a', { lines = { line } })
|
||||||
end
|
end
|
||||||
@@ -57,38 +67,89 @@ function M.compile_and_run()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Link the object file to create executable
|
||||||
|
local link_cmd = string.format('ld "%s.o" -o "%s"', output_name, output_name)
|
||||||
|
|
||||||
|
-- Notify the user about the linking process
|
||||||
|
notify("Linking...", "MoreMsg")
|
||||||
|
|
||||||
|
-- Execute the link command
|
||||||
|
local link_output = vim.fn.system(link_cmd)
|
||||||
|
local link_exit = vim.v.shell_error
|
||||||
|
|
||||||
|
-- Check if linking was successful
|
||||||
|
if link_exit ~= 0 then
|
||||||
|
notify("Linking failed:\n" .. link_output, "ErrorMsg")
|
||||||
|
-- Populate quickfix list with errors and warnings
|
||||||
|
vim.fn.setqflist({}, ' ')
|
||||||
|
for line in link_output:gmatch("[^\r\n]+") do
|
||||||
|
if line:match("error") or line:match("warning") then
|
||||||
|
vim.fn.setqflist({}, 'a', { lines = { line } })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.cmd('copen') -- Open the quickfix list to show errors
|
||||||
|
return
|
||||||
|
else
|
||||||
|
notify("Compilation successful!", "MoreMsg")
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
-- For C and C++, compile and link in one step
|
||||||
|
local compile_cmd = string.format('%s %s "%s" -o "%s"', compiler, flags, file, output_name)
|
||||||
|
|
||||||
|
-- Notify the user about the compilation process
|
||||||
|
notify("Compiling...", "MoreMsg")
|
||||||
|
|
||||||
|
-- Execute the compile command
|
||||||
|
local compile_output = vim.fn.system(compile_cmd)
|
||||||
|
local compile_exit = vim.v.shell_error
|
||||||
|
|
||||||
|
-- Check if compilation was successful
|
||||||
|
if compile_exit ~= 0 then
|
||||||
|
notify("Compilation failed:\n" .. compile_output, "ErrorMsg")
|
||||||
|
-- Populate quickfix list with errors and warnings
|
||||||
|
vim.fn.setqflist({}, ' ')
|
||||||
|
for line in compile_output:gmatch("[^\r\n]+") do
|
||||||
|
if line:match("error") or line:match("warning") then
|
||||||
|
vim.fn.setqflist({}, 'a', { lines = { line } })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.cmd('copen') -- Open the quickfix list to show errors
|
||||||
|
return
|
||||||
|
else
|
||||||
|
notify("Compilation successful!", "MoreMsg")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Construct the run command
|
-- Construct the run command
|
||||||
local run_cmd = string.format('./%s', output_name)
|
local run_cmd = string.format('./%s', output_name)
|
||||||
|
|
||||||
-- Notify the user about the execution process
|
-- Notify the user about the execution process
|
||||||
vim.notify("Running executable...", vim.log.levels.INFO)
|
notify("Running executable...", "MoreMsg")
|
||||||
|
|
||||||
-- Function to check if a terminal is already open
|
-- Function to find an existing terminal window for execution
|
||||||
local function is_terminal_open()
|
local function find_exec_terminal()
|
||||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||||
local buf = vim.api.nvim_win_get_buf(win)
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
if vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' then
|
if vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' then
|
||||||
return true
|
return win
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run the executable in a terminal split at the bottom
|
-- Run the executable in a terminal split at the bottom
|
||||||
if not is_terminal_open() then
|
local exec_win = find_exec_terminal()
|
||||||
vim.cmd('botright split') -- Open split at the bottom
|
|
||||||
|
if not exec_win then
|
||||||
|
-- Open a new terminal split at the bottom
|
||||||
|
vim.cmd('botright split')
|
||||||
vim.cmd('resize 15') -- Optional: Adjust the size of the split
|
vim.cmd('resize 15') -- Optional: Adjust the size of the split
|
||||||
vim.cmd('terminal ' .. run_cmd) -- Run the executable
|
vim.cmd('terminal ' .. run_cmd) -- Run the executable
|
||||||
else
|
else
|
||||||
-- If a terminal is already open, send the run command to it
|
-- If a terminal is already open, send the run command to it
|
||||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
vim.api.nvim_set_current_win(exec_win)
|
||||||
local buf = vim.api.nvim_win_get_buf(win)
|
vim.api.nvim_chan_send(vim.b.terminal_job_id, run_cmd .. '\n')
|
||||||
if vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' then
|
|
||||||
vim.api.nvim_set_current_win(win)
|
|
||||||
vim.api.nvim_feedkeys(run_cmd .. '\n', 'n', true)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Submodule nvim/pack/nvim/start/cmp-bufffer deleted from 3022dbc916
Submodule nvim/pack/nvim/start/cmp-cmdline deleted from d250c63aa1
Submodule nvim/pack/nvim/start/cmp-nvim-lsp deleted from 99290b3ec1
Submodule nvim/pack/nvim/start/cmp-path deleted from 91ff86cd9c
Submodule nvim/pack/nvim/start/cmp_luasnip deleted from 98d9cb5c2c
Submodule nvim/pack/nvim/start/comment deleted from e30b7f2008
Submodule nvim/pack/nvim/start/gitsigns deleted from 3ec5fbd920
Submodule nvim/pack/nvim/start/gruvbox deleted from 68c3460a5d
Submodule nvim/pack/nvim/start/lualine deleted from 2a5bae9254
Submodule nvim/pack/nvim/start/luasnip deleted from c9b9a22904
Submodule nvim/pack/nvim/start/markdown-preview.nvim deleted from a923f5fc5b
Submodule nvim/pack/nvim/start/nvim-autopairs deleted from 3d02855468
Submodule nvim/pack/nvim/start/nvim-cmp deleted from 12509903a5
Submodule nvim/pack/nvim/start/nvim-lspconfig deleted from b4d65bce97
Submodule nvim/pack/nvim/start/nvim-treesitter deleted from 6587a58868
Submodule nvim/pack/nvim/start/nvim-web-devicons deleted from aafa5c187a
Submodule nvim/pack/nvim/start/plenary deleted from 3707cdb1e4
Submodule nvim/pack/nvim/start/telescope deleted from 415af52339
Submodule nvim/pack/nvim/start/vimwiki deleted from 72792615e7
Submodule nvim/pack/nvim/start/vimwiki-markdown deleted from 1b6007d528
Submodule nvim/pack/nvim/start/which-key deleted from 6cebd86917
Reference in New Issue
Block a user