From e5a08226b71f9d70b665da3685538a70d5715bb2 Mon Sep 17 00:00:00 2001 From: caiowakamatsu Date: Wed, 19 Nov 2025 13:33:11 -0300 Subject: [PATCH] some nice fixes --- nvim/lua/config/cmake.lua | 17 ++++++++++++++++- nvim/lua/util/float.lua | 27 +++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/nvim/lua/config/cmake.lua b/nvim/lua/config/cmake.lua index cbb4ea3..5efbf01 100644 --- a/nvim/lua/config/cmake.lua +++ b/nvim/lua/config/cmake.lua @@ -41,8 +41,23 @@ end function M.configure_cmake(build_type) vim.fn.mkdir("build", "p") + + local cmake_module_path = vim.fn.getenv("CMAKE_MODULE_PATH") + + local module_path_arg = "" + if cmake_module_path ~= nil and cmake_module_path ~= "" then + module_path_arg = "-DCMAKE_MODULE_PATH=" .. cmake_module_path + end + + local cmake_args = { + module_path_arg, + "-DCMAKE_BUILD_TYPE=" .. build_type, + "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", + ".." + } + float_term( - { M.find_cmake(), "-DCMAKE_BUILD_TYPE=" .. build_type, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", ".." }, + { M.find_cmake(), unpack(cmake_args) }, { cwd = "build" } ) end diff --git a/nvim/lua/util/float.lua b/nvim/lua/util/float.lua index 9d34e5e..f11e1d8 100644 --- a/nvim/lua/util/float.lua +++ b/nvim/lua/util/float.lua @@ -11,15 +11,38 @@ function M.float_terminal(cmd, opts) style = "minimal", relative = "editor", width = width, height = height, row = row, col = col, border = opts.border or "rounded", + -- Set the buffer for the new window + buf = buf, }) + -- --- START MODIFICATION --- + + -- Format the command as a string for display + local cmd_display + if type(cmd) == 'table' then + cmd_display = table.concat(cmd, " ") + else + cmd_display = cmd + end + + -- Write the command string to the top of the buffer + vim.api.nvim_buf_set_lines(buf, 0, 0, false, { + "--- RUNNING COMMAND: " .. cmd_display .. " ---", + "", -- Add an empty line for separation + }) + + -- --- END MODIFICATION --- + local function scroll_bottom() local win = vim.api.nvim_get_current_win() vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0}) end + -- We need to ensure the terminal starts in the correct buffer + vim.api.nvim_set_current_buf(buf) + local job = vim.fn.termopen(cmd, { - cwd = opts.cwd, -- <= important + cwd = opts.cwd, on_stdout = function(...) scroll_bottom() end, on_stderr = function(...) scroll_bottom() end, on_exit = function(_, code, _) @@ -27,7 +50,7 @@ function M.float_terminal(cmd, opts) vim.notify(("command exited %d"):format(code), code == 0 and vim.log.levels.INFO or vim.log.levels.ERROR) end) end, - env = opts.env, -- e.g. env = { PATH = os.getenv("PATH") } + env = opts.env, }) vim.keymap.set("n", "q", "bd!", { buffer = buf, silent = true })