Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: teach buffer finder to see all buffers passed on command-line
As noted in the comment on the issue, the Ruby version used to just grab buffer names with `:ls`. The Lua version instead uses `nvim_list_bufs()`, which the help claims is more like `:ls!` because it includes unlisted (unloaded/deleted) buffers: Includes unlisted (unloaded/deleted) buffers, like `:ls!`. Use |nvim_buf_is_loaded()| to check if a buffer is loaded. Unfortunately, what "unlisted" means is a bit ambiguous, because the help for `:ls` says this: When the [!] is included the list will show unlisted buffers (the term "unlisted" is a bit confusing then...). So, I think I just added the `nvim_buf_is_loaded()` check (in 0b8c9ed, "feat(lua): continue sketching out UI", July 20, 2022) because the help said I should use that to avoid unloaded buffers. The docs for `nvim_buf_is_loaded()` say: Checks if a buffer is valid and loaded. See |api-buffer| for more info about unloaded buffers. So, it's checking for loaded _and_ "valid", whatever that means. It turns out there is a `nvim_buf_is_valid()` function, so perhaps we should just use that! Checks if a buffer is valid. Note: Even if a buffer is valid it may have been unloaded. See |api-buffer| for more info about unloaded buffers. Parameters: ~ • {buffer} Buffer handle, or 0 for current buffer Return: ~ true if the buffer is valid, false otherwise. The risk here is that we let somebody try switching to an unloaded buffer, which presumably might not work. In my experimenting at least, when I run `:bunload` on a buffer and then try switching to it with Command-T, it seems to work fine. Presumably it is loading it again. Closes: #418
- Loading branch information