diff --git a/README.md b/README.md
index 2dc822e..e9fda8f 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@

-
+
Python Tools for Neovim
-
+
https://github.com/user-attachments/assets/5a637270-3785-4929-828b-628d553b5732
## Installation
@@ -31,6 +31,42 @@ return {
---@type python.Config
opts = { ---@diagnostic disable-line: missing-fields`
}
+ -- Optional suggested keymaps
+ keys = {
+ { "pv", "Python venv pick", desc = "python.nvim: pick venv" },
+ { "pi", "Python venv install", desc = "python.nvim: python venv install" },
+ { "pd", "Python dap", desc = "python.nvim: python run debug program" },
+
+ -- Test Actions
+ { "ptt", "Python test test", desc = "python.nvim: python run test suite" },
+ { "ptm", "Python test test_method", desc = "python.nvim: python run test method" },
+ { "ptf", "Python test test_file", desc = "python.nvim: python run test file" },
+ { "ptdd", "Python test test_debug", desc = "python.nvim: run test suite in debug mode." },
+ {
+ "ptdm",
+ "Python test test_method_debug",
+ desc = "python.nvim: run test method in debug mode.",
+ },
+ { "ptdf", "Python test_file_debug", desc = "python.nvim: run test file in debug mode." },
+
+ -- VEnv Actions
+ { "ped", "Python venv delete_select", desc = "python.nvim: select and delete a known venv." },
+ { "peD", "Python venv delete", desc = "python.nvim: delete current venv set." },
+
+ -- Language Actions
+ { "ppe", "Python treesitter toggle_enumerate", desc = "python.nvim: turn list into enumerate" },
+ {
+ "pw",
+ "Python treesitter wrap_cursor",
+ desc = "python.nvim: wrap treesitter identifier with pattern",
+ },
+ {
+ "pw",
+ mode = "v",
+ ":Python treesitter wrap_cursor",
+ desc = "python.nvim: wrap treesitter identifier with pattern",
+ },
+ },
}
}
```
@@ -150,56 +186,6 @@ return {
},
},
},
- -- Load python keymaps. Everything starting with p...
- keymaps = {
- -- following nvim_set_keymap() mode, lhs, rhs, opts
- mappings = {
- ["pv"] = { "n", "Python venv pick", { desc = "python.nvim: pick venv" } },
- ["pi"] = { "n", "Python venv install", { desc = "python.nvim: python venv install" } },
- ["pd"] = { "n", "Python dap", { desc = "python.nvim: python run debug program" } },
-
- -- Test Actions
- ["ptt"] = { "n", "Python test test", { desc = "python.nvim: python run test suite" } },
- ["ptm"] = { "n", "Python test test_method", { desc = "python.nvim: python run test method" } },
- ["ptf"] = { "n", "Python test test_file", { desc = "python.nvim: python run test file" } },
- ["ptdd"] = { "n", "Python test test_debug", { desc = "python.nvim: run test suite in debug mode." } },
- ["ptdm"] = {
- "n",
- "Python test test_method_debug",
- { desc = "python.nvim: run test method in debug mode." },
- },
- ["ptdf"] = {
- "n",
- "Python test_file_debug",
- { desc = "python.nvim: run test file in debug mode." },
- },
-
- -- VEnv Actions
- ["ped"] = {
- "n",
- "Python venv delete_select",
- { desc = "python.nvim: select and delete a known venv." },
- },
- ["peD"] = { "n", "Python venv delete", { desc = "python.nvim: delete current venv set." } },
-
- -- Language Actions
- ["ppe"] = {
- "n",
- "Python treesitter toggle_enumerate",
- { desc = "python.nvim: turn list into enumerate" },
- },
- ["ppw"] = {
- "n",
- "Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- ["pw"] = {
- "v",
- ":Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- },
- },
-- Settings regarding ui handling
ui = {
-- Amount of time to pause closing of ui after a finished task
@@ -292,32 +278,32 @@ return {
## Main Commands
-| Default KeyMap | Command | Functionality |
-| ------------------------ | ------------------------------------- | ------------------------------------------------------------------------------------ |
-| `pi` | `:Python venv install` | Create a venv and install dependencies if a supported python package format is found |
-| `pd` | `:Python dap` | Create and save a new Dap configuration |
-| `ptt` | `:Python test test` | Run Suite of tests with `neotest` |
-| `ptm` | `:Python test test_method` | Run test function/method with `neotest` |
-| `ptf` | `:Python test test_file` | Run test file with `neotest` |
-| `ppe` | `:Python treesitter toggle_enumerate` | Turn a regular list into `enumerate()` list and back |
-| `ppw` | `:Python treesitter wrap_cursor` | Wrap treesitter indentifiers in a pattern for quick injection. |
-| visual mode `pw` | `:Python treesitter wrap_cursor` | Wrap treesitter indentifiers in visual mode |
+| Command | Functionality |
+| ------------------------------------- | ------------------------------------------------------------------------------------ |
+| `:Python venv install` | Create a venv and install dependencies if a supported python package format is found |
+| `:Python dap` | Create and save a new Dap configuration |
+| `:Python test test` | Run Suite of tests with `neotest` |
+| `:Python test test_method` | Run test function/method with `neotest` |
+| `:Python test test_file` | Run test file with `neotest` |
+| `:Python treesitter toggle_enumerate` | Turn a regular list into `enumerate()` list and back |
+| `:Python treesitter wrap_cursor` | Wrap treesitter indentifiers in a pattern for quick injection. |
+| `:Python treesitter wrap_cursor` | Wrap treesitter indentifiers in visual mode |
## Advanced Commands
-| Default KeyMap | Command | Functionality |
-| -------------- | ---------------------------- | -------------------------------------------------------------------------------------- |
-| `ped` | `:Python venv delete_select` | Select a venv to delete from `python.nvim` state |
-| `peD` | `:Python venv delete` | Delete current selected venv in project in `python.nvim` state |
-| `ptdd` | `:Python test test_debug` | Run Suite of tests with `neotest` in `dap` mode with `dap-python` |
-| `ptdm` | `:Python test test_method_debug` | Run test function/method with `neotest` in `dap` mode with `dap-python` |
-| `ptdf` | `:Python test test_file_debug` | Run test file with `neotest` in `dap` mode with `dap-python` |
-| `none` | `:Python hatch list` | List python interpreters installed by [hatch](https://hatch.pypa.io/latest/) |
-| `none` | `:Python hatch install` | Install a python interpreter using [hatch](https://hatch.pypa.io/latest/) |
-| `none` | `:Python hatch delete` | Delete a python interpreter from [hatch](https://hatch.pypa.io/latest/) |
-| `none` | `:Python uv install_python` | Delete a python interpreter from [uv](https://docs.astral.sh/uv/) |
-| `none` | `:Python uv delete_python` | Delete a python interpreter from [uv](https://docs.astral.sh/uv/) |
-| `none` | `:UV ` | Pass through commands to [uv](https://docs.astral.sh/uv/) with command line completion |
+| Command | Functionality |
+| ---------------------------- | -------------------------------------------------------------------------------------- |
+| `:Python venv delete_select` | Select a venv to delete from `python.nvim` state |
+| `:Python venv delete` | Delete current selected venv in project in `python.nvim` state |
+| `:Python test test_debug` | Run Suite of tests with `neotest` in `dap` mode with `dap-python` |
+| `:Python test test_method_debug` | Run test function/method with `neotest` in `dap` mode with `dap-python` |
+| `:Python test test_file_debug` | Run test file with `neotest` in `dap` mode with `dap-python` |
+| `:Python hatch list` | List python interpreters installed by [hatch](https://hatch.pypa.io/latest/) |
+| `:Python hatch install` | Install a python interpreter using [hatch](https://hatch.pypa.io/latest/) |
+| `:Python hatch delete` | Delete a python interpreter from [hatch](https://hatch.pypa.io/latest/) |
+| `:Python uv install_python` | Delete a python interpreter from [uv](https://docs.astral.sh/uv/) |
+| `:Python uv delete_python` | Delete a python interpreter from [uv](https://docs.astral.sh/uv/) |
+| `:UV ` | Pass through commands to [uv](https://docs.astral.sh/uv/) with command line completion |
## Supported python package managers
diff --git a/doc/python.txt b/doc/python.txt
index 64d786f..13c6b06 100644
--- a/doc/python.txt
+++ b/doc/python.txt
@@ -67,7 +67,7 @@ Default values:
-- Path for venvs picker
venvs_path = vim.fn.expand("~/.virtualenvs"),
-- Something to do after setting an environment
- post_set_venv = nil,
+ post_set_venv = false,
-- base path for creating new venvs
auto_create_venv_path = function(parent_dir)
return vim.fs.joinpath(parent_dir, ".venv")
@@ -77,7 +77,7 @@ Default values:
-- like .yaml, .yml for ansible
auto_venv_lsp_attach_patterns = { "*.py" },
- -- Filetypes to activate commands for python.nvim
+ -- Buffer patterns to activate commands for python.nvim
command_setup_buf_pattern = { "*.py" },
-- Load python.nvim python snippets
@@ -120,56 +120,6 @@ Default values:
},
},
},
- -- Load python keymaps. Everything starting with p...
- keymaps = {
- -- following nvim_set_keymap() mode, lhs, rhs, opts
- mappings = {
- ["pv"] = { "n", "Python venv pick", { desc = "python.nvim: pick venv" } },
- ["pi"] = { "n", "Python venv install", { desc = "python.nvim: python venv install" } },
- ["pd"] = { "n", "Python dap", { desc = "python.nvim: python run debug program" } },
-
- -- Test Actions
- ["ptt"] = { "n", "Python test", { desc = "python.nvim: python run test suite" } },
- ["ptm"] = { "n", "Python test_method", { desc = "python.nvim: python run test method" } },
- ["ptf"] = { "n", "Python test_file", { desc = "python.nvim: python run test file" } },
- ["ptdd"] = { "n", "Python test_debug", { desc = "python.nvim: run test suite in debug mode." } },
- ["ptdm"] = {
- "n",
- "Python test_method_debug",
- { desc = "python.nvim: run test method in debug mode." },
- },
- ["ptdf"] = {
- "n",
- "Python test_file_debug",
- { desc = "python.nvim: run test file in debug mode." },
- },
-
- -- VEnv Actions
- ["ped"] = {
- "n",
- "Python venv delete_select",
- { desc = "python.nvim: select and delete a known venv." },
- },
- ["peD"] = { "n", "Python venv delete", { desc = "python.nvim: delete current venv set." } },
-
- -- Language Actions
- ["ppe"] = {
- "n",
- "Python treesitter toggle_enumerate",
- { desc = "python.nvim: turn list into enumerate" },
- },
- ["ppw"] = {
- "n",
- "Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- ["pw"] = {
- "v",
- ":Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- },
- },
-- Settings regarding ui handling
ui = {
-- Amount of time to pause closing of ui after a finished task
@@ -379,6 +329,16 @@ Parameters ~
{subtitute_option} `(nil|string)` if string then use as substitute
otherwise select from config
+------------------------------------------------------------------------------
+ *checkForFStringCallParent()*
+ `checkForFStringCallParent`({node})
+
+Parameters ~
+{node} `(TSNode)` the current ts node we are checking for parents
+Return ~
+`(string)` callText check if this node has a "call" type node 3 parents up
+this is used for checking on "".format() calls for strings.
+
==============================================================================
------------------------------------------------------------------------------
diff --git a/doc/tags b/doc/tags
index 199f643..9c8d759 100644
--- a/doc/tags
+++ b/doc/tags
@@ -38,6 +38,7 @@ PythonVENVInterpreters.hatch_interpreters() python.txt /*PythonVENVInterpreters.
PythonVENVInterpreters.python_interpreters() python.txt /*PythonVENVInterpreters.python_interpreters()*
PythonVENVInterpreters.uv_interpreters() python.txt /*PythonVENVInterpreters.uv_interpreters()*
UI python.txt /*UI*
+checkForFStringCallParent() python.txt /*checkForFStringCallParent()*
create_dap_config() python.txt /*create_dap_config()*
findNodeOfParentsWithType() python.txt /*findNodeOfParentsWithType()*
getNodeAtCursor() python.txt /*getNodeAtCursor()*
diff --git a/lua/python/config.lua b/lua/python/config.lua
index a0353a8..07e37f7 100644
--- a/lua/python/config.lua
+++ b/lua/python/config.lua
@@ -70,60 +70,6 @@ PythonConfig.defaults = {
},
},
},
- -- Load python keymaps. Everything starting with p...
- keymaps = {
- -- following nvim_set_keymap() mode, lhs, rhs, opts
- mappings = {
- ["pv"] = { "n", "Python venv pick", { desc = "python.nvim: pick venv" } },
- ["pi"] = { "n", "Python venv install", { desc = "python.nvim: python venv install" } },
- ["pd"] = { "n", "Python dap", { desc = "python.nvim: python run debug program" } },
-
- -- Test Actions
- ["ptt"] = { "n", "Python test test", { desc = "python.nvim: python run test suite" } },
- ["ptm"] = { "n", "Python test test_method", { desc = "python.nvim: python run test method" } },
- ["ptf"] = { "n", "Python test test_file", { desc = "python.nvim: python run test file" } },
- ["ptdd"] = {
- "n",
- "Python test test_debug",
- { desc = "python.nvim: run test suite in debug mode." },
- },
- ["ptdm"] = {
- "n",
- "Python test test_method_debug",
- { desc = "python.nvim: run test method in debug mode." },
- },
- ["ptdf"] = {
- "n",
- "Python test_file_debug",
- { desc = "python.nvim: run test file in debug mode." },
- },
-
- -- VEnv Actions
- ["ped"] = {
- "n",
- "Python venv delete_select",
- { desc = "python.nvim: select and delete a known venv." },
- },
- ["peD"] = { "n", "Python venv delete", { desc = "python.nvim: delete current venv set." } },
-
- -- Language Actions
- ["ppe"] = {
- "n",
- "Python treesitter toggle_enumerate",
- { desc = "python.nvim: turn list into enumerate" },
- },
- ["ppw"] = {
- "n",
- "Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- ["pw"] = {
- "v",
- ":Python treesitter wrap_cursor",
- { desc = "python.nvim: wrap treesitter identifier with pattern" },
- },
- },
- },
-- Settings regarding ui handling
ui = {
-- Amount of time to pause closing of ui after a finished task
diff --git a/lua/python/init.lua b/lua/python/init.lua
index fd040b8..fcf9305 100644
--- a/lua/python/init.lua
+++ b/lua/python/init.lua
@@ -51,7 +51,6 @@ function Python.setup(opts)
local venv = require("python.venv")
local commands = require("python.commands")
local snip = require("python.snip")
- local keymap = require("python.keymap")
local uv = require("python.uv.commands")
commands.load_commands()
@@ -59,8 +58,6 @@ function Python.setup(opts)
snip.load_snippets()
- keymap.load_keymaps()
-
venv.load_existing_venv()
end,
})
diff --git a/lua/python/keymap.lua b/lua/python/keymap.lua
deleted file mode 100644
index 6fada78..0000000
--- a/lua/python/keymap.lua
+++ /dev/null
@@ -1,26 +0,0 @@
-local config = require("python.config")
-
-local M = {}
-
-local function map(mode, lhs, rhs, opts)
- local options = { noremap = true, silent = true }
- if opts then
- options = vim.tbl_extend("force", options, opts)
- end
- vim.api.nvim_set_keymap(mode, lhs, rhs, options)
-end
-
-function M.load_keymaps()
- if next(config.keymaps.mappings) == nil then
- return
- end
- for key, val in pairs(config.keymaps.mappings) do
- map(val[1], key, val[2], val[3])
- end
-end
-
-return setmetatable(M, {
- __index = function(_, k)
- return require("python.keymap")[k]
- end,
-})
diff --git a/tests/test_keymap.lua b/tests/test_keymap.lua
deleted file mode 100644
index dd6577f..0000000
--- a/tests/test_keymap.lua
+++ /dev/null
@@ -1,33 +0,0 @@
--- Define helper aliases
-local new_set = MiniTest.new_set
-local expect, eq = MiniTest.expect, MiniTest.expect.equality
-
--- Create (but not start) child Neovim object
-local child = MiniTest.new_child_neovim()
-
--- Define main test set of this file
-local T = new_set({
- -- Register hooks
- hooks = {
- -- This will be executed before every (even nested) case
- pre_case = function()
- -- Restart child process with custom 'init.lua' script
- child.restart({ "-u", "scripts/minimal_init.lua" })
- -- Load tested plugin
- child.lua([[require('python').setup()]])
- end,
- -- This will be executed one after all tests from this set are finished
- post_once = child.stop,
- },
-})
-
--- Keymaps can be loaded
-T["keymaps"] = function()
- child.cmd("cd examples/python_projects/uv")
- child.cmd("e main.py")
- local keymap = child.cmd_capture("map pi")
- assert(string.find(keymap, "python venv install", 1, true))
-end
-
--- Return test set which will be collected and execute inside `MiniTest.run()`
-return T