From 420f84f1a36caaeee49408a5a16655eb093ac199 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 9 Nov 2023 20:24:20 +0100 Subject: [PATCH] feat: Ajout autocmd pour les fichiers groovy et python --- lua/user/autocmds/groovy.lua | 53 ++++++++++++++++++++---- lua/user/autocmds/python.lua | 67 +++++++++++++++++++++++++++++++ lua/user/colorscheme.lua | 2 +- lua/user/init.lua | 1 + lua/user/mappings.lua | 36 +++++++++++------ lua/user/plugins/colorschemes.lua | 3 +- lua/user/plugins/neotree.lua | 22 +++++++++- lua/user/plugins/telescope.lua | 2 + 8 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 lua/user/autocmds/python.lua diff --git a/lua/user/autocmds/groovy.lua b/lua/user/autocmds/groovy.lua index 1bd5eff..f76d6fc 100644 --- a/lua/user/autocmds/groovy.lua +++ b/lua/user/autocmds/groovy.lua @@ -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", "", "lua _groovysh_toggle()", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("i", "", "lua _groovysh_toggle()", { 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 + -- 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()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("i", "", + "lua _groovy_terminal_toggle()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("t", "", + "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 diff --git a/lua/user/autocmds/python.lua b/lua/user/autocmds/python.lua new file mode 100644 index 0000000..3224003 --- /dev/null +++ b/lua/user/autocmds/python.lua @@ -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 + -- 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 _Python_terminal_toggle()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("i", "", + "lua _Python_terminal_toggle()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("t", "", + "lua _Python_terminal_toggle()", + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("n", "", + -- "TermExec name=python cmd='python %'", + 'lua _Python_buffer_exec()', + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("i", "", + -- "TermExec name=python cmd='python %'", + 'lua _Python_buffer_exec()', + { noremap = true, silent = true }) + vim.api.nvim_set_keymap("t", "", + -- "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, + } +) diff --git a/lua/user/colorscheme.lua b/lua/user/colorscheme.lua index a781f3d..5c1ed01 100644 --- a/lua/user/colorscheme.lua +++ b/lua/user/colorscheme.lua @@ -1 +1 @@ -return "astrodark" +return "onenord" diff --git a/lua/user/init.lua b/lua/user/init.lua index c8536a8..2c38f15 100644 --- a/lua/user/init.lua +++ b/lua/user/init.lua @@ -17,6 +17,7 @@ return { require "user.autocmds.text" require "user.autocmds.terminal" require "user.autocmds.groovy" + require "user.autocmds.python" -- Set up custom filetypes -- vim.filetype.add { diff --git a/lua/user/mappings.lua b/lua/user/mappings.lua index 372aa34..62142b6 100644 --- a/lua/user/mappings.lua +++ b/lua/user/mappings.lua @@ -13,35 +13,47 @@ return { -- quick save -- [""] = { ":w!", desc = "Save File" }, -- change description but the same command - -- My personal keybindings - ["x"] = { name = "Personal" }, - - ["xn"] = { name = "Neotree" }, - ["xnb"] = { "Neotree toggle buffers left", desc = "Open Neotree Buffers" }, - ["xng"] = { "Neotree toggle git_status left", desc = "Open Neotree Git status" }, - - ["xt"] = { "terminal tig", desc = "Open tig in a new tab" }, - -- My telescope keybindings ["fq"] = { "Telescope quickfix", desc = "Find quickfixes with Telescope" }, ["fs"] = { "Telescope spell_suggest", desc = "Find spell suggestions with Telescope" }, + ["fp"] = { "Telescope projects", desc = "Find projetcs with Telescope" }, + + -- My personal keybindings + ["²"] = { name = "Personal" }, + ["²t"] = { name = "Terminals" }, + ["²tt"] = { "TermSelect", desc = "Select a terminal" }, + ["²tg"] = { "terminal tig", desc = "Open tig in a new tab" }, + + ["²n"] = { name = "Neotree" }, + ["²nb"] = { "Neotree toggle buffers left", desc = "Open Neotree Buffers" }, + ["²ng"] = { "Neotree toggle git_status left", desc = "Open Neotree Git status" }, + + [""] = { 'Neotree toggle', desc = "File Explorer" }, -- F26 corresponds to on my keyboard + [""] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to on my keyboard + [""] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to on my keyboard }, -- Insert mode - i = {}, + i = { + [""] = { 'Neotree toggle', desc = "File Explorer" }, -- F26 corresponds to on my keyboard + [""] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to on my keyboard + [""] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to on my keyboard + }, -- Terminal mode t = { -- setting a mapping to false will disable it -- [""] = false, + -- Switch to normal mode in terminal mode + [""] = { "" }, -- Clear Ctrl+l so that we can use it to clear the terminal [""] = false, [""] = false, -- Clear Ctrl-J and Ctrl-K so that we can use them to navigate the terminal (for lazygit) [""] = false, [""] = false, - -- Switch to normal mode in terminal mode - [""] = { "" } + [""] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to on my keyboard + [""] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to on my keyboard }, } diff --git a/lua/user/plugins/colorschemes.lua b/lua/user/plugins/colorschemes.lua index 0aa08a6..4d1ad17 100644 --- a/lua/user/plugins/colorschemes.lua +++ b/lua/user/plugins/colorschemes.lua @@ -2,6 +2,7 @@ return { { 'jacoborus/tender.vim', lazy = false }, { 'altercation/vim-colors-solarized', lazy = false }, { 'bluz71/vim-moonfly-colors', lazy = false }, - { 'joshdick/onedark.vim', lazy = false }, { 'ray-x/aurora', lazy = false }, + { 'rmehri01/onenord.nvim' }, + { 'joshdick/onedark.vim' }, } diff --git a/lua/user/plugins/neotree.lua b/lua/user/plugins/neotree.lua index d5e6a76..cd6c89a 100644 --- a/lua/user/plugins/neotree.lua +++ b/lua/user/plugins/neotree.lua @@ -2,8 +2,26 @@ return { { "nvim-neo-tree/neo-tree.nvim", opts = { + window = { + width = 50, + mappings = { + [""] = false, -- disable space until we figure out which-key disabling + [">"] = "next_source", + ["<"] = "prev_source", + }, + }, + event_handlers = { + { + event = "file_opened", + handler = function(file_path) + -- auto close + -- vimc.cmd("Neotree close") + -- OR + require("neo-tree.command").execute({ action = "close" }) + end + }, + }, close_if_last_window = true, - window = { width = 50 }, - } + }, } } diff --git a/lua/user/plugins/telescope.lua b/lua/user/plugins/telescope.lua index bbcde2c..fabfb7c 100644 --- a/lua/user/plugins/telescope.lua +++ b/lua/user/plugins/telescope.lua @@ -2,10 +2,12 @@ return { "nvim-telescope/telescope.nvim", dependencies = { "nvim-telescope/telescope-file-browser.nvim", + "da-moon/telescope-toggleterm.nvim", }, config = function(...) require "plugins.configs.telescope" (...) local telescope = require "telescope" telescope.load_extension "file_browser" + telescope.load_extension "toggleterm" end, }