From 333ea49d45b2d5ed0c28d9eb580bec6296d8538e Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 16 Nov 2023 19:00:46 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20mise=20=C3=A0=20jour=20autocmds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/user/autocmds/groovy.lua | 96 ++++++++++++++++++++++++------------ lua/user/autocmds/python.lua | 32 +++++++----- 2 files changed, 84 insertions(+), 44 deletions(-) diff --git a/lua/user/autocmds/groovy.lua b/lua/user/autocmds/groovy.lua index f76d6fc..bddae0c 100644 --- a/lua/user/autocmds/groovy.lua +++ b/lua/user/autocmds/groovy.lua @@ -1,18 +1,33 @@ vim.api.nvim_create_autocmd( "FileType", { desc = "Customizations for groovy files", - -- 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") + -- Vim settings + + vim.opt.signcolumn = "auto" + vim.opt.foldcolumn = "auto" + + -- 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 + -- Define a new terminal dedicated to groovy + local toggleterm = require('toggleterm') local Terminal = require('toggleterm.terminal').Terminal local groovy = Terminal:new({ - name = "groovy", - size = 50, - direction = "horizontal", + name = name, + cmd = command, + direction = direction, + size = size, hidden = true, close_on_exit = true, }) @@ -20,48 +35,65 @@ vim.api.nvim_create_autocmd( -- Spawn in background so it will be ready to execute code groovy:spawn() + -- Add to toggleterm list + -- groovy:__add() -- TODO: This is not working + -- Define a function to toggle the terminal - function _groovy_terminal_toggle() - groovy:toggle(50, 'horizontal') + function _Groovy_terminal_toggle() + groovy:toggle(size, direction) end - -- 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 function to run code from current buffer in the terminal + -- function _Groovy_buffer_exec() + -- if not groovy:is_open() then groovy:open(size, direction) end + -- groovy:open(size, direction) + -- groovy:send(' clear', true) + -- groovy:send(command, true) + -- end + + -- + -- Define a function to run code from visual selection in the terminal + -- function _Groovy_visual_exec(args) + -- groovy:open(size, direction) + -- toggleterm.send_lines_to_terminal("visual_lines", true, { groovy.id }) + -- end -- Define a keymap to run the current buffer in the terminal -- corresponds to F10 on my keyboard -- corresponds to Shift + F10 on my keyboard -- corresponds to Ctrl + F10 on my keyboard vim.api.nvim_set_keymap("n", "", - "lua _groovy_terminal_toggle()", + "lua _Groovy_terminal_toggle()", { noremap = true, silent = true }) vim.api.nvim_set_keymap("i", "", - "lua _groovy_terminal_toggle()", + "lua _Groovy_terminal_toggle()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("v", "", + "lua _Groovy_terminal_toggle()", { noremap = true, silent = true }) vim.api.nvim_set_keymap("t", "", - "lua _groovy_terminal_toggle()", + "lua _Groovy_terminal_toggle()", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("n", "", - -- "TermExec name=groovy cmd='groovy %'", - 'lua _groovy_buffer_exec()', - { noremap = true, silent = true }) - vim.api.nvim_set_keymap("i", "", - -- "TermExec name=groovy cmd='groovy %'", - 'lua _groovy_buffer_exec()', - { noremap = true, silent = true }) - vim.api.nvim_set_keymap("t", "", - -- "TermExec name=groovy cmd='groovy %'", - 'lua _groovy_buffer_exec()', - { noremap = true, silent = true }) - -- vim.api.nvim_set_keymap('n', '', ':terminal groovysh', { noremap = true, silent = true }) - -- vim.opt_local.wrap = true - -- vim.opt_local.spell = true + + -- vim.api.nvim_set_keymap("n", "", + -- 'lua _Groovy_visual_exec()', + -- { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("i", "", + -- 'lua _Groovy_visual_exec()', + -- { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("v", "", + -- "lua _Groovy_visual_exec()", + -- { noremap = true, silent = true }) + + -- vim.api.nvim_set_keymap("n", "", + -- 'lua _Groovy_buffer_exec()', + -- { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("i", "", + -- 'lua _Groovy_buffer_exec()', + -- { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("t", "", + -- 'lua _Groovy_buffer_exec()', + -- { noremap = true, silent = true }) end, - -- command = "setlocal wrap spell", } ) diff --git a/lua/user/autocmds/python.lua b/lua/user/autocmds/python.lua index 3224003..533310e 100644 --- a/lua/user/autocmds/python.lua +++ b/lua/user/autocmds/python.lua @@ -6,28 +6,41 @@ vim.api.nvim_create_autocmd( local utils = require("astronvim.utils") utils.notify("Loading autocmd customizations for python files") + -- Vim settings + + vim.opt.signcolumn = "auto" + vim.opt.foldcolumn = "auto" + + + -- Terminal settings + + -- Define prefered options for the terminal + local name = "python" + local direction = "vertical" + local size = 100 + -- Define a new terminal dedicated to python local Terminal = require('toggleterm.terminal').Terminal local python = Terminal:new({ - name = "python", - size = 100, - direction = "vertical", + name = name, + size = size, + direction = direction, hidden = true, - close_on_exit = true, + -- close_on_exit = true, }) - -- Spawn in background so it will be ready to execute code + -- Spawn it 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') + python:toggle(size, direction) 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') + if not python:is_open() then python:open(size, direction) end python:send(' clear', true) python:send(command, true) end @@ -57,11 +70,6 @@ vim.api.nvim_create_autocmd( -- "TermExec name=python cmd='python %'", 'lua _Python_buffer_exec()', { noremap = true, silent = true }) - - -- Test - -- local is_available = utils.is_available - -- if is_available "notify" then - -- notify("notify is available", "info") end, } )