From 63d5dd2856799144d541651fa1e0d53a63cb84fb Mon Sep 17 00:00:00 2001 From: Juliano Barbosa Date: Fri, 23 Aug 2024 06:51:00 -0300 Subject: [PATCH] chore(plugins): added python-repl.lua --- lua/custom/plugins/python-repl.lua | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lua/custom/plugins/python-repl.lua diff --git a/lua/custom/plugins/python-repl.lua b/lua/custom/plugins/python-repl.lua new file mode 100644 index 00000000..c105c9e3 --- /dev/null +++ b/lua/custom/plugins/python-repl.lua @@ -0,0 +1,57 @@ +-- python-debugging.lua: Debugging Python code with DAP +-- + +return { + -- PYTHON REPL + -- A basic REPL that opens up as a horizontal split + -- - use `i` to toggle the REPL + -- - use `I` to restart the REPL + -- - `+` serves as the "send to REPL" operator. That means we can use `++` + -- to send the current line to the REPL, and `+j` to send the current and the + -- following line to the REPL, like we would do with other vim operators. + { + 'Vigemus/iron.nvim', + keys = { + { 'i', vim.cmd.IronRepl, desc = '󱠤 Toggle REPL' }, + { 'I', vim.cmd.IronRestart, desc = '󱠤 Restart REPL' }, + + -- these keymaps need no right-hand-side, since that is defined by the + -- plugin config further below + { '+', mode = { 'n', 'x' }, desc = '󱠤 Send-to-REPL Operator' }, + { '++', desc = '󱠤 Send Line to REPL' }, + }, + + -- since irons's setup call is `require("iron.core").setup`, instead of + -- `require("iron").setup` like other plugins would do, we need to tell + -- lazy.nvim which module to via the `main` key + main = 'iron.core', + + opts = { + keymaps = { + send_line = '++', + visual_send = '+', + send_motion = '+', + }, + config = { + -- This defines how the repl is opened. Here, we set the REPL window + -- to open in a horizontal split to the bottom, with a height of 10. + repl_open_cmd = 'horizontal bot 10 split', + + -- This defines which binary to use for the REPL. If `ipython` is + -- available, it will use `ipython`, otherwise it will use `python3`. + -- since the python repl does not play well with indents, it's + -- preferable to use `ipython` or `bypython` here. + -- (see: https://github.com/Vigemus/iron.nvim/issues/348) + repl_definition = { + python = { + command = function() + local ipythonAvailable = vim.fn.executable 'ipython' == 1 + local binary = ipythonAvailable and 'ipython' or 'python3' + return { binary } + end, + }, + }, + }, + }, + }, +}