config-astronvim/lua/user/autocmds/groovy.lua

107 lines
3.9 KiB
Lua
Raw Normal View History

vim.api.nvim_create_autocmd(
"FileType", {
desc = "Customizations for groovy files",
pattern = { "groovy", "Jenkinsfile" },
callback = function()
local utils = require("astronvim.utils")
utils.notify("Loading autocmd customizations for groovy files")
2023-11-16 19:00:46 +01:00
-- Vim settings
2023-11-24 19:02:55 +01:00
vim.opt_local.signcolumn = 'auto'
vim.opt_local.foldcolumn = 'auto'
vim.opt_local.makeprg = 'groovy %'
vim.keymap.set({ 'n', 'i', 'v' }, '<F5>', ':make<CR>', { buffer = true })
-- vim.keymap.nnoremap { '<leader>²x', ':make<CR>' }
-- vim.keymap.inoremap { '<leader>²x', '<ESC>:make<CR>' }
2023-11-16 19:00:46 +01:00
-- Terminal settings
-- Define prefered options for the terminal
-- local command = string.format(" groovy %s", vim.api.nvim_buf_get_name(0))
local name = "groovy"
local command = " groovysh"
local direction = "horizontal"
local size = 25
2023-11-24 19:02:55 +01:00
local toggle_key = "<F10>"
2023-11-16 19:00:46 +01:00
-- Define a new terminal dedicated to groovy
2023-11-16 19:00:46 +01:00
local toggleterm = require('toggleterm')
local Terminal = require('toggleterm.terminal').Terminal
local groovy = Terminal:new({
2023-11-16 19:00:46 +01:00
name = name,
cmd = command,
direction = direction,
size = size,
hidden = true,
close_on_exit = true,
})
-- Spawn in background so it will be ready to execute code
groovy:spawn()
2023-11-16 19:00:46 +01:00
-- Add to toggleterm list
-- groovy:__add() -- TODO: This is not working
-- Define a function to toggle the terminal
2023-11-16 19:00:46 +01:00
function _Groovy_terminal_toggle()
groovy:toggle(size, direction)
end
2023-11-16 19:00:46 +01:00
-- -- Define a function to run code from current buffer in the terminal
-- function _Groovy_buffer_exec()
2023-11-24 19:02:55 +01:00
-- if not groovy:is_open() then groovy:open(size, direction) end
2023-11-16 19:00:46 +01:00
-- groovy:send(' clear', true)
-- groovy:send(command, true)
-- end
--
-- Define a function to run code from visual selection in the terminal
2023-11-24 19:02:55 +01:00
function _Groovy_visual_exec()
if not groovy:is_open() then groovy:open(size, direction) end
toggleterm.send_lines_to_terminal("visual_lines", true, { groovy.id })
end
-- Define a keymap to run the current buffer in the terminal
-- <F10> corresponds to F10 on my keyboard
-- <F22> corresponds to Shift + F10 on my keyboard
-- <F34> corresponds to Ctrl + F10 on my keyboard
2023-11-24 19:02:55 +01:00
vim.keymap.set({ 'n', 'i', 'v', 't' }, '<F10>', function() groovy:toggle(size, direction) end,
{ noremap = true, silent = true })
2023-11-16 19:00:46 +01:00
2023-11-24 19:02:55 +01:00
-- vim.api.nvim_set_keymap("n", toggle_key,
-- "<cmd>lua _Groovy_terminal_toggle()<cr>",
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("i", toggle_key,
-- "<cmd>lua _Groovy_terminal_toggle()<cr>",
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("v", toggle_key,
-- "<cmd>lua _Groovy_terminal_toggle()<cr>",
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("t", toggle_key,
-- "<cmd>lua _Groovy_terminal_toggle()<cr>",
-- { noremap = true, silent = true })
2023-11-16 19:00:46 +01:00
-- vim.api.nvim_set_keymap("n", "<F22>",
-- '<cmd>lua _Groovy_visual_exec()<cr>',
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("i", "<F22>",
-- '<cmd>lua _Groovy_visual_exec()<cr>',
-- { noremap = true, silent = true })
2023-11-24 19:02:55 +01:00
vim.api.nvim_set_keymap("v", "<F22>",
"<cmd>lua _Groovy_visual_exec()<cr>",
{ noremap = true, silent = true })
2023-11-16 19:00:46 +01:00
-- vim.api.nvim_set_keymap("n", "<F34>",
-- '<cmd>lua _Groovy_buffer_exec()<cr>',
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("i", "<F34>",
-- '<cmd>lua _Groovy_buffer_exec()<cr>',
-- { noremap = true, silent = true })
-- vim.api.nvim_set_keymap("t", "<F34>",
-- '<cmd>lua _Groovy_buffer_exec()<cr>',
-- { noremap = true, silent = true })
end,
}
)