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: close_if_last_window invalid command to swap to modified buffer #1350

Closed
3 tasks done
bwpge opened this issue Feb 11, 2024 · 2 comments
Closed
3 tasks done

BUG: close_if_last_window invalid command to swap to modified buffer #1350

bwpge opened this issue Feb 11, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bwpge
Copy link
Contributor

bwpge commented Feb 11, 2024

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

Neovim Version (nvim -v)

NVIM v0.9.2

Operating System / Version

Windows 11 22H2

Describe the Bug

When the close_if_last_window option is enabled, the "swap to modified buffer" scheduled function in init.lua causes the error E492: Not an editor command: .... This only happens for buffers of files on disk (not unnamed buffers), specifically on a Windows system. This does not occur on WSL for the same system.

Possible root cause:
Looking at the traceback, it looks like this occurs because the :b[uffer] command is concatenating with an absolute Windows path (e.g., starting with a partition letter) resulting in an "unknown" command such as :bC:/... (see line 310 below):

vim.schedule(function()
log.warn(message)
vim.cmd("rightbelow vertical split")
vim.api.nvim_win_set_width(win_id, state.window.width or 40)
vim.cmd("b" .. buf_name)
end)

Example :b test on Windows:

  • Open a file in Neovim with nvim C:/foo.txt
  • Both :b C:\foo.txt and :b C:/foo.txt work as expected
  • Both :bC:\foo.txt and :bC:/foo.txt causes the error E492: Not an editor command: bC:...

Screenshots, Traceback

Error executing vim.schedule lua callback: vim/_editor.lua:341: nvim_exec2(): Vim:E492: Not an editor command: bC:/Users/user/AppData/Local/nvim/lua/user/plugins/neo-tree.lua
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua:341: in function 'cmd'
        ...nvim-data/lazy/neo-tree.nvim/lua/neo-tree/setup/init.lua:310: in function <...nvim-data/lazy/neo-tree.nvim/lua/neo-tree/setup/init.lua:306>

Steps to Reproduce

  1. Use Neovim on a Windows system with this plugin, minimally configured with lazy per README. Minimal init.lua provided below, but the following is the relevant plugin spec for neo-tree to create the behavior:
{
    "nvim-neo-tree/neo-tree.nvim",
    branch = "v3.x",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons",
      "MunifTanjim/nui.nvim",
    },
    opts = { close_if_last_window = true },
}
  1. Open Neotree with :Neotree filesystem reveal left
  2. Modify an existing file on disk without saving (IMPORTANT: the file must exist on disk since the buffer name will use an absolute Windows path)
  3. Attempt to close the buffer with :q and observe the error

Expected Behavior

The modified buffer is focused without causing an error.

Your Configuration

-- lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

-- load neo-tree with appropriate options
require("lazy").setup({
    {
        "nvim-neo-tree/neo-tree.nvim",
        branch = "v3.x",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-tree/nvim-web-devicons",
            "MunifTanjim/nui.nvim",
        },
        opts = { close_if_last_window = true },
    },
})
@bwpge bwpge added the bug Something isn't working label Feb 11, 2024
@bwpge
Copy link
Contributor Author

bwpge commented Feb 11, 2024

I've opened #1351 to fix this issue.

@bwpge bwpge changed the title BUG: close_if_last_window incorrect command to swap to modified buffer BUG: close_if_last_window invalid command to swap to modified buffer Feb 11, 2024
@bwpge
Copy link
Contributor Author

bwpge commented Feb 11, 2024

#1351 has been merged so this issue is resolved.

@bwpge bwpge closed this as completed Feb 11, 2024
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
Development

No branches or pull requests

1 participant