Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Neovide (or other UI?) run from WezTerm leads to error in integration logic #131

Closed
1 task done
mdietrich16 opened this issue Oct 16, 2023 · 9 comments · Fixed by #132 or #142
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@mdietrich16
Copy link
Contributor

Similar Issues

  • Before filing, I have searched for similar issues.

Neovim Version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1696795921

Multiplexer Integration

Wezterm

Multiplexer Version

wezterm 20230712-072601-f4abf8fd

Steps to Reproduce

  1. Have WezTerm and Neovim set up as described in README
  2. Open WezTerm
  3. Type neovide<CR>
  4. ...
  5. Profit!

Expected Behavior

Neovide opens and smart-splits works without WezTerm integration

Actual Behavior

Neovide opens and smart-splits works without WezTerm integration but echoes error message:

Failed to source `/home/max/.local/share/nvim/lazy/smart-splits.nvim/plugin/smart-splits.vim`

vim/_editor.lua:0: /home/max/.config/nvim/init.lua..nvim_exec2() called at /home/max/.config/nvim/init.lua:0../home/max/.local/share/nvim/lazy/smart-splits.nvim/plugin/smart-splits.vim[70]..function <SNR>9_write, line 2: Vim(let):E80: Error while writing: broken pipe

# stacktrace:
  - vim/_editor.lua:0 _in_ **cmd**
  - .config/nvim/lua/plugins/windows.lua:17 _in_ **init** -- This is where I have the smart-splits spec for lazy.nvim. This line only shows when using the init function described below!
  - .config/nvim/lua/config/plugins.lua:23
  - .config/nvim/lua/config/init.lua:7
  - .config/nvim/init.lua:5

Minimal Configuration to Reproduce

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  -- do not remove the colorscheme! it makes testing nicer
  'folke/tokyonight.nvim',
  'mrjones2014/smart-splits.nvim',
  -- add any other pugins here
}

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

require('smart-splits').setup({
  -- add any options here
})

-- recommended mappings
-- resizing splits
-- these keymaps will also accept a range,
-- for example `10<A-h>` will `resize_left` by `(10 * config.default_amount)`
vim.keymap.set('n', '<A-h>', require('smart-splits').resize_left)
vim.keymap.set('n', '<A-j>', require('smart-splits').resize_down)
vim.keymap.set('n', '<A-k>', require('smart-splits').resize_up)
vim.keymap.set('n', '<A-l>', require('smart-splits').resize_right)
-- moving between splits
vim.keymap.set('n', '<C-h>', require('smart-splits').move_cursor_left)
vim.keymap.set('n', '<C-j>', require('smart-splits').move_cursor_down)
vim.keymap.set('n', '<C-k>', require('smart-splits').move_cursor_up)
vim.keymap.set('n', '<C-l>', require('smart-splits').move_cursor_right)
-- swapping buffers between windows
vim.keymap.set('n', '<leader><leader>h', require('smart-splits').swap_buf_left)
vim.keymap.set('n', '<leader><leader>j', require('smart-splits').swap_buf_down)
vim.keymap.set('n', '<leader><leader>k', require('smart-splits').swap_buf_up)
vim.keymap.set('n', '<leader><leader>l', require('smart-splits').swap_buf_right)

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme! it makes testing nicer
vim.cmd([[colorscheme tokyonight]])

Additional Details and/or Screenshots

This could be mitigated by checking for vim.g.neovide which is nil when not in Neovide and true when in Neovide, which I tried. However, this is a fairly specific addition, since other UI's exist with probably the same problem.

I would just be glad to get a pointer to where I can manually do this.
I tried through the lazy.nvim opts and init function like:

    init = function()
        if vim.g.neovide then
            print("Disabled WezTerm mux integration")
            require("smart-splits.config")["multiplexer_integration"] = false
        end
    end,

But the error then just originates from that init function, which seems to mean that plugin/smart-splits.vim gets loaded when doing any require("smart-splits"). This of course makes it impossible for me to override this behaviour.

@mdietrich16 mdietrich16 added the bug Something isn't working label Oct 16, 2023
@mrjones2014
Copy link
Owner

This could be mitigated by checking for vim.g.neovide which is nil when not in Neovide and true when in Neovide, which I tried. However, this is a fairly specific addition, since other UI's exist with probably the same problem.

Yeah, a more appropriate solution would probably be to just disable terminal mux integrations entirely if it's detected that you're using a GUI instead of nvim's TUI. We may be able to check that via vim.api.nvim_list_uis(). If term_name doesn't match one of ours, or if stdin_tty or stdout_tty are false, then it's probably a GUI.

@mrjones2014
Copy link
Owner

Please verify that #132 resolves your issue @mdietrich16 🙏

@mdietrich16
Copy link
Contributor Author

Did a review, small changes required. If those are fixed, it seems to work with Neovide at least. Nice work!

@mdietrich16
Copy link
Contributor Author

I'll close when the PR is merged.

@mrjones2014
Copy link
Owner

Thanks for the review + testing! It will auto-close the issue when I merge the PR. I'll tag a patch release after merging.

@mdietrich16
Copy link
Contributor Author

Alright, thanks for the quick and elegant fix!

@lkhphuc
Copy link

lkhphuc commented Jan 2, 2024

The latest commit 26085a6 causes the error to appear on start up again.
It's not a big problem as everything still works fine. The error message only shows on startup from launching inside wezterm, not from launching Neovide from GUI.

@mrjones2014
Copy link
Owner

@lkhphuc does #142 fix it for you?

@lkhphuc
Copy link

lkhphuc commented Jan 3, 2024

#142 worked for me. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants