docs(upstream): triage stevearc/oil.nvim#280 and consolidate #325 (#166)

* docs(upstream): consolidate stevearc/oil.nvim#325 into #164

Problem: upstream #325 (spurious "could not find parent window" warning
on startup) was still marked open in the tracker.

Solution: created canola.nvim#164 to track the `WinNew`/`BufEnter`
race condition and updated the tracker status.

* docs(upstream): triage stevearc/oil.nvim#280 as not actionable

Problem: upstream #280 (vim-projectionist support) was still marked
open. `BufNewFile` does not fire for oil-created files because the
file already exists on disk by the time it is opened.

Solution: the `OilFileCreated` user event is the correct hook point.
Added an `oil-recipe-file-templates` recipe documenting both a simple
template approach and a precise vim-projectionist shim via
`OilFileCreated`. Updated the tracker status.

* docs(upstream): close PR #721 as not actionable

`OilFileCreated` already covers the use case addressed by the
`create_hook` draft PR.
This commit is contained in:
Barrett Ruth 2026-03-17 21:09:21 -04:00 committed by GitHub
parent ff1c443cc8
commit d67195b637
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 2 deletions

View file

@ -1321,6 +1321,50 @@ path in the clipboard.
end, { desc = "Paste file from clipboard path into oil directory" })
<
*oil-recipe-file-templates*
Apply initial content to newly created files using the |OilFileCreated| event.
This is the recommended alternative to relying on |BufNewFile|, which does not
fire for files created through oil (the file already exists on disk by the
time it is opened). >lua
vim.api.nvim_create_autocmd("User", {
pattern = "OilFileCreated",
callback = function(args)
local path = args.data.path
local ext = vim.fn.fnamemodify(path, ":e")
local templates = {
sh = { "#!/usr/bin/env bash", "" },
py = { "#!/usr/bin/env python3", "" },
}
if templates[ext] then
vim.fn.writefile(templates[ext], path)
end
end,
})
<
For integration with vim-projectionist or any plugin that hooks |BufNewFile|,
use |OilFileCreated| to track oil-created files, then fire |BufNewFile| the
first time each file is opened. This is more precise than checking for empty
buffers on |BufRead|: >lua
local oil_created = {}
vim.api.nvim_create_autocmd("User", {
pattern = "OilFileCreated",
callback = function(args)
oil_created[args.data.path] = true
end,
})
vim.api.nvim_create_autocmd("BufRead", {
callback = function(args)
local path = vim.api.nvim_buf_get_name(args.buf)
if oil_created[path] then
oil_created[path] = nil
vim.api.nvim_exec_autocmds("BufNewFile", { buffer = args.buf })
end
end,
})
<
--------------------------------------------------------------------------------
EVENTS *oil-events*