From 91dd2a1c6d1259eadd7ec505768882f8c41ea0c4 Mon Sep 17 00:00:00 2001 From: Marcelo Jacobus Date: Thu, 6 Jun 2024 16:18:51 -0300 Subject: [PATCH] Initial setup --- README.md | 8 ++++++-- lua/config/keymaps.lua | 24 ++++++++++++++++++------ lua/config/options.lua | 1 + lua/mj/alternate_file.lua | 12 ++++++------ lua/mj/globals.lua | 36 ++---------------------------------- lua/mj/mj.lua | 5 ----- lua/mj/test_runner.lua | 33 +++++++++++++++++++++++++++++++++ lua/mj/utils.lua | 18 ++++++++++++++++++ 8 files changed, 84 insertions(+), 53 deletions(-) delete mode 100644 lua/mj/mj.lua create mode 100644 lua/mj/test_runner.lua create mode 100644 lua/mj/utils.lua diff --git a/README.md b/README.md index 185280b..367f9a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# 💤 LazyVim +# My neovim config -A starter template for [LazyVim](https://github.com/LazyVim/LazyVim). +```sh +./install.sh +``` + +Forked starter template for [LazyVim](https://github.com/LazyVim/LazyVim). Refer to the [documentation](https://lazyvim.github.io/installation) to get started. diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index df6937a..00e8471 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -33,10 +33,11 @@ map("n", "on", ":e ~/.tmp/notes/notes.md", { desc = "Open notes" }) map("n", "con", ":e ~/.tmp/notes/notes.md", { desc = "Open notes" }) map("n", "j", function() - CloseTerminalBuffer(true) + require("mj.utils").close_terminal_buffer(true) end, { desc = "Close terminal buffer (true)" }) + map("n", "k", function() - CloseTerminalBuffer(false) + require("mj.utils").close_terminal_buffer(false) end, { desc = "Close terminal buffer (false)" }) -- Search mappings @@ -65,7 +66,18 @@ end, { desc = "Previous alternative file" }) vim.diagnostic.config({ virtual_text = false }) -- Running tests -map("n", "T", ":lua RunTestFile()", { desc = "Run test file" }) -map("n", "t", ":lua RunTestLineByLine()", { desc = "Run test for current line" }) -map("n", "at", ":lua RunAllTests()", { desc = "Run all tests" }) -map("n", "s.t", ":lua RunShellTest()", { desc = "Run ./shell_test" }) +map("n", "at", function() + require("mj.test_runner").run_all_tests() +end, { desc = "Run all tests" }) + +map("n", "t", function() + require("mj.test_runner").test_line() +end, { desc = "Run test for current line" }) + +map("n", "T", function() + require("mj.test_runner").run_test_file() +end, { desc = "Run test file" }) + +map("n", "st", function() + require("mj.test_runner").run_shell_test() +end, { desc = "Run ./shell_test" }) diff --git a/lua/config/options.lua b/lua/config/options.lua index 3ea1454..da28ee2 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -1,3 +1,4 @@ -- Options are automatically loaded before lazy.nvim startup -- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua -- Add any additional options here +vim.g.swap = false diff --git a/lua/mj/alternate_file.lua b/lua/mj/alternate_file.lua index 878b6b1..fb39598 100644 --- a/lua/mj/alternate_file.lua +++ b/lua/mj/alternate_file.lua @@ -1,10 +1,15 @@ local runner = require("mj.command_runner") M = {} +M._mj_alternative_file = function(file, subcommand, options) + local cmd = "mj alternative_file " .. subcommand .. " " .. file .. " " .. options + return runner.run(cmd) +end + M.open = function(subcommand, options) local file_path = vim.fn.expand("%") file_path = vim.fn.fnamemodify(file_path, ":~:.") - local files = mj_alternative_file(file_path, subcommand, options) + local files = M._mj_alternative_file(file_path, subcommand, options) files = vim.split(files, " ") local file = files[1] @@ -13,9 +18,4 @@ M.open = function(subcommand, options) end end -function mj_alternative_file(file, subcommand, options) - local cmd = "mj alternative_file " .. subcommand .. " " .. file .. " " .. options - return runner.run(cmd) -end - return M diff --git a/lua/mj/globals.lua b/lua/mj/globals.lua index bfb6c6f..552c5d7 100644 --- a/lua/mj/globals.lua +++ b/lua/mj/globals.lua @@ -6,40 +6,6 @@ function RunInTerminal(cmd, open_new_tab) runner.run_in_terminal(cmd, open_new_tab) end -function RunTestFile() - local current_path = vim.fn.expand("%") - local cmd = "run_test " .. current_path - RunInTerminal(cmd, true) -end - -function RunTestLineByLine() - local current_line, _ = unpack(vim.api.nvim_win_get_cursor(0)) - local current_path = vim.fn.expand("%") - local cmd = "run_test " .. current_path .. " --line=" .. current_line - RunInTerminal(cmd, true) -end - -function RunAllTests() - local current_path = vim.fn.expand("%") - local cmd = "run_test " .. current_path .. " --all" - RunInTerminal(cmd, true) -end - -function CloseTerminalBuffer(new_tab) - local name = vim.api.nvim_buf_get_name(0) - - if string.find(name, "term://") then - if not new_tab then - local number = vim.api.nvim_buf_get_number(0) - vim.api.nvim_exec("buffer #", true) - vim.api.nvim_buf_delete(number, { force = true }) - return - end - - vim.api.nvim_command("bdelete!") - end -end - function RunShellTest() RunInTerminal("./shell_test", true) end @@ -48,3 +14,5 @@ function RunRubocop() local file = vim.fn.expand("%") RunInTerminal("bundle exec rubocop -A " .. file, false) end + +return M diff --git a/lua/mj/mj.lua b/lua/mj/mj.lua deleted file mode 100644 index 3ad4036..0000000 --- a/lua/mj/mj.lua +++ /dev/null @@ -1,5 +0,0 @@ -local M = {} - -M.alternate_file = require("mj.alternate_file") - -return M diff --git a/lua/mj/test_runner.lua b/lua/mj/test_runner.lua new file mode 100644 index 0000000..4c9b148 --- /dev/null +++ b/lua/mj/test_runner.lua @@ -0,0 +1,33 @@ +local M = {} + +local runner = require("mj.command_runner") + +M.run_test_file = function() + local current_path = vim.fn.expand("%") + local cmd = "run_test " .. current_path + runner.run_in_terminal(cmd, true) +end + +M.test_line = function() + local current_line, _ = unpack(vim.api.nvim_win_get_cursor(0)) + local current_path = vim.fn.expand("%") + local cmd = "run_test " .. current_path .. " --line=" .. current_line + runner.run_in_terminal(cmd, true) +end + +M.run_all_tests = function() + local current_path = vim.fn.expand("%") + local cmd = "run_test " .. current_path .. " --all" + runner.run_in_terminal(cmd, true) +end + +M.run_shell_test = function() + runner.run_in_terminal("./shell_test", true) +end + +M.run_rubocop = function() + local file = vim.fn.expand("%") + runner.run_in_terminal("bundle exec rubocop -A ", false) +end + +return M diff --git a/lua/mj/utils.lua b/lua/mj/utils.lua new file mode 100644 index 0000000..844c8ac --- /dev/null +++ b/lua/mj/utils.lua @@ -0,0 +1,18 @@ +local M = {} + +M.close_terminal_buffer = function(new_tab) + local name = vim.api.nvim_buf_get_name(0) + + if string.find(name, "term://") then + if not new_tab then + local number = vim.api.nvim_buf_get_number(0) + vim.api.nvim_exec("buffer #", true) + vim.api.nvim_buf_delete(number, { force = true }) + return + end + + vim.api.nvim_command("bdelete!") + end +end + +return M