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

Opening multiple files from command-line :CommandTBuffer only sees the first #418

Closed
wincent opened this issue Jul 14, 2023 · 2 comments
Closed

Comments

@wincent
Copy link
Owner

wincent commented Jul 14, 2023

When multiple files are opened when invoking nvim from the command line, :CommandTBuffer doesn't know about all the buffers. I am not sure if that is by design or not. This makes switching buffers with command-t impossible until all the buffers are cycled through with :bnext or similar. Once that is done, :CommandTBuffer knows about all the buffers.

Originally posted by @jaapie in #394 (comment)

@wincent
Copy link
Owner Author

wincent commented Jul 14, 2023

Thanks for the report!

Definitely not by design, but it's a consequence of this logic in the buffer finder:

  • List all buffers with vim.api.nvim_list_bufs()
    • For each buffer, check it is loaded with vim.api.nvim_buf_is_loaded(); if it is:
      • Get the name with vim.api.nvim_buf_get_name(); and:
      • Turn it into a relative path with vim.fn.fnamemodify().

So, the intent of the nvim_buf_is_loaded check is to skip over "unloaded" buffers, which can cause problems. The api-buffer docs say this about unloaded buffers:

Unloaded Buffers: ~

Buffers may be unloaded by the |:bunload| command or the buffer's
|'bufhidden'| option. When a buffer is unloaded its file contents are
freed from memory and vim cannot operate on the buffer lines until it is
reloaded (usually by opening the buffer again in a new window). API
methods such as |nvim_buf_get_lines()| and |nvim_buf_line_count()| will be
affected.

I'm concerned that if I remove the nvim_buf_is_loaded check I'll wind up introducing a regression; but I didn't have this kind of thing in the Ruby version (the scanner was just parsing :ls output), so this code is pretty new (added in 0b8c9ed, "feat(lua): continue sketching out UI", July 20, 2022).

I can certainly play around with removing it, and if I can't do that, I might be able to do some special-casing to detect when Neovim has just launched and skip the check in that case...

@jaapie
Copy link

jaapie commented Jul 17, 2023

Thanks @wincent that's fixed it for me! I appreciate your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants