feat: Ajout autocmd pour les fichiers groovy et python

This commit is contained in:
Xavier Logerais
2023-11-09 20:24:20 +01:00
parent 095d08c050
commit 420f84f1a3
8 changed files with 163 additions and 23 deletions

View File

@ -4,21 +4,60 @@ vim.api.nvim_create_autocmd(
-- group = vim.api.nvim_create_augroup("groovy", { clear = true }),
pattern = { "groovy", "Jenkinsfile" },
callback = function()
local utils = require("astronvim.utils")
utils.notify("Loading autocmd customizations for groovy files")
-- Define a new terminal dedicated to groovy
local Terminal = require('toggleterm.terminal').Terminal
local groovysh = Terminal:new({
name = "groovysh",
cmd = "groovysh",
local groovy = Terminal:new({
name = "groovy",
size = 50,
direction = "horizontal",
hidden = true,
close_on_exit = true,
})
function _groovysh_toggle()
groovysh:toggle()
-- Spawn in background so it will be ready to execute code
groovy:spawn()
-- Define a function to toggle the terminal
function _groovy_terminal_toggle()
groovy:toggle(50, 'horizontal')
end
vim.api.nvim_set_keymap("n", "<F5>", "<cmd>lua _groovysh_toggle()<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F5>", "<cmd>lua _groovysh_toggle()<CR>", { noremap = true, silent = true })
-- Define a function to run code from current buffer in the terminal
function _groovy_buffer_exec()
local command = string.format(" groovy %s", vim.api.nvim_buf_get_name(0))
groovy:open(50, 'horizontal')
groovy:send(' clear', true)
groovy:send(command, true)
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
vim.api.nvim_set_keymap("n", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<F5>', ':terminal groovysh<CR>', { noremap = true, silent = true })
-- vim.opt_local.wrap = true
-- vim.opt_local.spell = true

View File

@ -0,0 +1,67 @@
vim.api.nvim_create_autocmd(
"FileType", {
pattern = { "python" },
desc = "Customizations for python files",
callback = function()
local utils = require("astronvim.utils")
utils.notify("Loading autocmd customizations for python files")
-- Define a new terminal dedicated to python
local Terminal = require('toggleterm.terminal').Terminal
local python = Terminal:new({
name = "python",
size = 100,
direction = "vertical",
hidden = true,
close_on_exit = true,
})
-- Spawn in background so it will be ready to execute code
python:spawn()
-- Define a function to toggle the terminal
function _Python_terminal_toggle()
python:toggle(100, 'vertical')
end
-- Define a function to run code from current buffer in the terminal
function _Python_buffer_exec()
local command = string.format(" python %s", vim.api.nvim_buf_get_name(0))
python:open(100, 'vertical')
python:send(' clear', true)
python:send(command, true)
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
vim.api.nvim_set_keymap("n", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
-- Test
-- local is_available = utils.is_available
-- if is_available "notify" then
-- notify("notify is available", "info")
end,
}
)