Closed rikchilvers closed 1 year ago
I'm not familiar with Poetry, I almost never use Python, but I'd gladly accept a PR from anyone familiar with it
Understood.
On further thought, this feels like an issue for how Neovim interacts with Python when in a virtualenv (possibly just for how I've got things set up). I'll have a poke around and see if I can find a fix.
Things that might come to mind:
wezterm
CLI still on your $PATH
when in the Poetry shell?pane:get_foreground_process_name()
in Wezterm's Lua still report nvim
when in a Poetry shell? This is used by the is_vim
function in the recommended mappings.Thanks for the tips. The CLI is still in my $PATH
. How can I check the pane:get_foreground_process_name()
?
In your wezterm config, in the keymaps recommended in the README.md of this plugin, there is a function called is_vim
-- in there, add the line:
print(string.format('foreground process name: %s', pane:get_foreground_process_name()))
then start Wezterm via the CLI from a different terminal (i.e. open a different terminal and run the wezterm
command) which will let you see Wezterm's log output.
Thanks.
Does pane:get_foreground_process_name() in Wezterm's Lua still report nvim when in a Poetry shell? This is used by the is_vim function in the recommended mappings.
No. The foreground process changes to Poetry's python.
lua: foreground process name: /Users/rik/Library/Application Support/pypoetry/venv/bin/python
From the pane with Neovim running in it? Wonder if poetry is not updating process information or something
I'll close this since the problem isn't smart-splits'. Thanks for the help!
For anyone else that runs into this, you can edit is_vim
to something similar to:
local function is_vim(pane)
local process_name = basename(pane:get_foreground_process_name())
return process_name == 'nvim' or process_name == 'vim' or string.find(process_name, "pypoetry/venv/bin/python")
end
Won't that mess with your keymaps if you're in a poetry shell without Neovim open?
We could solve this another way with user vars: https://wezfurlong.org/wezterm/recipes/passing-data.html#user-vars
In your shell, you would add these aliases:
# This function emits an OSC 1337 sequence to set a user var
# associated with the current terminal pane.
# It requires the `base64` utility to be available in the path.
# This function is included in the wezterm shell integration script, but
# is reproduced here for clarity
__wezterm_set_user_var() {
if hash base64 2>/dev/null ; then
printf "\033]1337;SetUserVar=%s=%s\007" "$1" `echo -n "$2" | base64`
fi
}
function _run_prog() {
# set PROG to the program being run
__wezterm_set_user_var "PROG" "$1"
# arrange to clear it when it is done
trap '__wezterm_set_user_var PROG ""' EXIT
# and now run the corresponding command, taking care to avoid looping
# with the alias definition
command "$@"
}
alias nvim="_run_prog nvim"
Then you could update the is_vim
function to basically just check:
pane:get_user_vars().PROG == 'nvim'
If this works for you, I can add this setup to the README.md as an alternative setup.
Good point.
I've had a play with your suggestion but couldn't get it to work with fish shell, which I'm using. Any idea on how to set a user var in fish in the way that wezterm needs?
I'm a Fish shell user as well. I'll play around with it tomorrow.
Hmm, actually I couldn't get this working either.
@wez any ideas? Here's the shell integration code converted to Fish shell syntax. But In Wezterm, pane:get_user_vars().PROG
still returns nil
# This function emits an OSC 1337 sequence to set a user var
# associated with the current terminal pane.
# It requires the `base64` utility to be available in the path.
# This function is included in the wezterm shell integration script, but
# is reproduced here for clarity
function __wezterm_set_user_var
if hash base64 2>/dev/null
printf "\033]1337;SetUserVar=%s=%s\007" "$1" `echo -n "$2" | base64`
end
end
function _run_prog
# set PROG to the program being run
__wezterm_set_user_var PROG "$1"
# arrange to clear it when it is done
trap '__wezterm_set_user_var PROG ""' EXIT
# and now run the corresponding command, taking care to avoid looping
# with the alias definition
command "$argv"
end
alias nvim="_run_prog nvim"
If poetry isn't correctly managing the foreground process / or otherwise managing unix job control correctly, then the foreground process name will be incorrect.
https://wezfurlong.org/wezterm/config/lua/window-events/user-var-changed.html may be helpful to debug user vars being set.
Similar Issues
Neovim Version
Multiplexer Integration
Wezterm
Multiplexer Version
Steps to Reproduce
Activate a poetry shell (with pynvim installed) Open neovim Create a neovim split Try to move between splits using
<C-{h|j|k|l}>
Expected Behavior
Moving between splits works using default keybindings
Actual Behavior
Moving between splits only works by calling
:SmartCursorMove{Direction}
directlyMinimal Configuration to Reproduce
Additional Details and/or Screenshots
No response