jpalardy / vim-slime

A vim plugin to give you some slime. (Emacs)
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
MIT License
1.89k stars 227 forks source link

vim-slime with neovim, tmux causes "divide by zero" issue in wezterm after `plt.show()` was send #448

Open ucl98 opened 17 hours ago

ucl98 commented 17 hours ago

I am using Neovim, WezTerm, and Tmux. My setup involves sending lines from Neovim to a Tmux window where an IPython session is running. This setup works well and allows for plot display in WezTerm without issues.

However, I encounter a problem when sending the command plt.show() via vim-slime; it causes WezTerm to panic. In contrast, when I manually type plt.show() in the same IPython instance, the plot displays correctly with no issues. Notably, lines 18-21 are sent via vim-slime, and lines 22-25 are typed manually.

Versions

System

Additional Informations

In [15]: import matplotlib

In [16]: matplotlib.use('module://matplotlib-backend-wezterm')

In [17]: import matplotlib.pyplot as plt

In [18]: x = [1, 2, 3]

In [19]: y = [2, 3, 4]

In [20]: plt.plot(x, y)
Out[20]: [<matplotlib.lines.Line2D at 0x7f553c7b96f0>]

In [21]: plt.show()
14:40:47.133  ERROR  env_bootstrap > panic at wezterm/src/main.rs:383:10 - attempt to divide by zero
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: __libc_start_main
  16: <unknown>

thread 'main' panicked at wezterm/src/main.rs:383:10:
attempt to divide by zero
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In [22]: x = [1, 2, 3]

In [23]: y = [2, 3, 4]

In [24]: plt.plot(x, y)
Out[24]: [<matplotlib.lines.Line2D at 0x7f553c63f460>]

In [25]: plt.show()

Sections from my neovim config:

    {
        "jpalardy/vim-slime",
        lazy = false,
        config = function()
            vim.g.slime_target = "tmux"
            vim.g.slime_default_config = { socket_name = "default", target_pane = "{last}" }
            vim.g.slime_dont_ask_default = 1
            vim.api.nvim_set_keymap("n", "<C-v><C-v>", "<Plug>SlimeLineSend", { noremap = false, silent = true })
            vim.api.nvim_set_keymap("n", "<C-c><C-c>", "<Plug>SlimeParagraphSend", { noremap = false, silent = true })
        end,
    },
-- 
map_keys(
    "n",
    "<leader>ip",
    [[<cmd>execute 'split | terminal tmux split-window -h ipython -i '.expand('%:p').' && tmux select-pane -L' | close<CR>]],
    { noremap = true, silent = true }
)
jpalardy commented 4 hours ago

hi @ucl98

interesting! (especially wezterm being the one that complains)

let me do a few tests and get back to you

jpalardy commented 3 hours ago

I don't run matplotlib myself, but I use nvim, tmux, and wezterm (on macos, but linux too if I needed to check) — and it doesn't seem to reproduce for me

some questions to try to corner this

looking at the wezterm code (from your error message)

image

this seems to happen on a width = 0 in the ImgCatCommand : compute_image_cell_dimensions function (which seems … weird?)


another line of inquiry:

you could try adding echom debug messages around this code and see what EXACTLY gets passed in


let me know what you find ^