aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-11-02 22:48:41 +0200
committersrdusr <trevorgray@srdusr.com>2023-11-02 22:48:41 +0200
commit8516a102660ce0f5ff9f36cc3947966c7636359d (patch)
tree4ceb3ee4fbcd8271de49d9648b79af151fcfcf9f /lua
parent1a8a25a258e39b3268742ef049d71b3a0297e06d (diff)
downloaddotfiles-8516a102660ce0f5ff9f36cc3947966c7636359d.tar.gz
dotfiles-8516a102660ce0f5ff9f36cc3947966c7636359d.zip
Toggle code runner
Diffstat (limited to 'lua')
-rw-r--r--lua/user/mods.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/lua/user/mods.lua b/lua/user/mods.lua
index 29d1b1c..7c2db16 100644
--- a/lua/user/mods.lua
+++ b/lua/user/mods.lua
@@ -851,6 +851,27 @@ vim.api.nvim_create_autocmd('BufHidden', {
--------------------------------------------------
+local codeRunnerEnabled = false
+
+function M.toggleCodeRunner()
+ codeRunnerEnabled = not codeRunnerEnabled
+ if codeRunnerEnabled then
+ print('Code Runner enabled')
+ M.RunCode() -- Execute when enabled
+ else
+ print('Code Runner disabled')
+ -- Close the terminal window when disabled
+ local buffers = vim.fn.getbufinfo()
+
+ for _, buf in ipairs(buffers) do
+ local type = vim.api.nvim_buf_get_option(buf.bufnr, 'buftype')
+ if type == 'terminal' then
+ vim.api.nvim_command('silent! bdelete ' .. buf.bufnr)
+ end
+ end
+ end
+end
+
local function substitute(cmd)
cmd = cmd:gsub('%%', vim.fn.expand('%'))
cmd = cmd:gsub('$fileBase', vim.fn.expand('%:r'))
@@ -864,6 +885,10 @@ local function substitute(cmd)
end
function M.RunCode()
+ if not codeRunnerEnabled then
+ print('Code Runner is currently disabled. Toggle it on to execute code.')
+ return
+ end
local file_extension = vim.fn.expand('%:e')
local selected_cmd = ''
local term_cmd = 'bot 10 new | term '
@@ -896,6 +921,9 @@ function M.RunCode()
default = 'node %',
debug = 'node --inspect %',
},
+ lua = {
+ default = 'lua %',
+ },
ts = {
default = 'tsc % && node $fileBase',
},