Made run script function work on all alphabetic characters instead

This commit is contained in:
Ivar Fatland
2023-08-15 12:54:24 +02:00
parent c7c99b6c12
commit b1b4c8a35e
+20 -14
View File
@@ -21,7 +21,7 @@ local keymap = {
-- [ ] c++ -- [ ] c++
--TODO find good keybindings --TODO find good keybindings
test_execute_file = '<leader>e', test_execute_script = '<leader>e',
test_debug_file = '<leader>d', test_debug_file = '<leader>d',
test_toggle_breakpoint = '<leader>b', test_toggle_breakpoint = '<leader>b',
test_step_over = nil, test_step_over = nil,
@@ -305,19 +305,19 @@ vim.api.nvim_create_user_command(
{ nargs = 0 } { nargs = 0 }
) )
---@type function ---Returns function that runs the given script_name in the current working directory.
local run_file ---Only implemented for Linux. ( Uses the sh command )
do ---@param script_name string
local run_script_name = ".run.sh" ---@return fun()
local function get_run_script_function(script_name)
run_file = function() return function()
---@type "Linux" | "Darwin" | "Windows_NT" ---@type "Linux" | "Darwin" | "Windows_NT"
local os_name = vim.loop.os_uname().sysname local os_name = vim.loop.os_uname().sysname
if os_name ~= "Linux" then if os_name ~= "Linux" then
error('run_file not implemented for non-linux platforms') error('run_file not implemented for non-linux platforms')
end end
local run_script_path = vim.fn.getcwd() .. "/" .. run_script_name local run_script_path = vim.fn.getcwd() .. "/" .. script_name
if not file_exists(run_script_path) then if not file_exists(run_script_path) then
error( error(
"The run script: '" .. run_script_path .. "' does not exist.\n".. "The run script: '" .. run_script_path .. "' does not exist.\n"..
@@ -329,12 +329,18 @@ do
end end
end end
vim.keymap.set( do
'n', local alphabet = 'abcdefghijklmnopqrstuvwxyzæøåABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ'
keymap.test_execute_file, for i = 1, #alphabet do
run_file, local char = alphabet:sub(i, i)
{ silent = true } vim.keymap.set(
) 'n',
keymap.test_execute_script .. char,
get_run_script_function("." .. char .. ".sh"),
{ silent = true }
)
end
end
---Splits the line under the cursor into multiple lines. ---Splits the line under the cursor into multiple lines.
---Works on lines with properly opening and closing brackets: (),[],{} ---Works on lines with properly opening and closing brackets: (),[],{}