Repository navigation
Conversation
Directory buffers are hijacked from a BufAdd autocmd, plus a one-off check of the current buffer in setup(). Buffers that already exist when setup() runs never trigger that autocmd. When nvim is started with several arguments, e.g. `nvim -O file.txt dir/`, every argument buffer is created before plugins are loaded, so any directory buffer that is not the current one is left alone and opens as an empty buffer. In setup(), also hijack listed buffers that are not loaded yet. They are renamed to their oil:// url, so BufReadCmd loads them when they are first entered, just like a directory buffer added after setup. Resolves stevearc#752
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #752
Problem
Oil takes over directory buffers from its
BufAddautocmd, andsetup()does a one-off check of the current buffer. Neovim creates a buffer for every argument before it loads plugins, so those buffers never trigger the autocmd. Only the current one is handled insetup(). Withnvim -O file.txt dir/,nvim -O dir1/ dir2/, ornvim file.txt dir/followed by:next, any directory argument other than the first opens as a blank buffer whose filetype is empty.Solution
setup()now also runsmaybe_hijack_directory_buffer()on every listed buffer that isn't loaded yet. Each of those buffers is renamed to itsoil://url, so the existingBufReadCmdloads it when it is first entered. That is the same path a directory buffer added aftersetup()takes. The current-buffer logic is unchanged.Only unloaded buffers are touched. A directory buffer that is already loaded (for example, oil lazy-loaded after
VimEnterwhile a directory is open in a split) would also needload_oil_buffer()called outside its window. I left that case out to keep this change small.Testing
tests/regression_spec.lua. It adds a directory buffer withnoautocmd badd, then callssetup(), then checks that the buffer is renamed tooil://and lists the directory's contents once it is entered. The test fails onmaster(the name is not renamed) and passes with this change../run_tests.shon macOS with Neovim v0.12.6: 109 passed, 0 failed, 0 errors (masterwithout the new test: 108 passed).stylua --check lua tests(StyLua 2.6.0; CI pins v2.4.1),luacheck lua tests(0 warnings / 0 errors), andscripts/nvim-typecheck-action/typecheck.sh --workdir scripts/nvim-typecheck-action lua(lua-language-server 3.19.2, no problems) all pass.nvim -u <minimal init>runs.-O dir1/ dir2/,-O file.txt dir2/,-p file.txt dir1/ dir2/, andfile.txt dir2/ +nextnow open every directory in oil. Onmasterthe second directory was blank.scripts/main.py lint). No docs changed.