feat: emit \CanolaFileCreated\ autocmd on file creation
Problem: no way to hook into individual file creation to populate initial contents, without a plugin-specific config callback. Solution: fire \`User CanolaFileCreated\` with \`data.path\` after each successful \`fs.touch\` in the files adapter. Users listen with \`nvim_create_autocmd\` and write to the path however they like.
This commit is contained in:
parent
c7a55fd787
commit
75eaf3994d
3 changed files with 1260 additions and 1 deletions
|
|
@ -1135,6 +1135,22 @@ CanolaMutationComplete *CanolaMutationComp
|
||||||
additional data fields. Use this event for post-mutation side effects such
|
additional data fields. Use this event for post-mutation side effects such
|
||||||
as refreshing external status indicators.
|
as refreshing external status indicators.
|
||||||
|
|
||||||
|
CanolaFileCreated *CanolaFileCreated*
|
||||||
|
Fired after a new file is successfully created on the local filesystem.
|
||||||
|
The `args.data.path` field contains the absolute path of the created file.
|
||||||
|
Use this event to populate initial file contents, run formatters, or
|
||||||
|
perform any other setup on newly created files. >lua
|
||||||
|
vim.api.nvim_create_autocmd("User", {
|
||||||
|
pattern = "CanolaFileCreated",
|
||||||
|
callback = function(args)
|
||||||
|
local path = args.data.path
|
||||||
|
if path:match("%.sh$") then
|
||||||
|
vim.fn.writefile({ "#!/usr/bin/env bash" }, path)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
<
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
TRASH *canola-trash*
|
TRASH *canola-trash*
|
||||||
|
|
||||||
|
|
|
||||||
1231
doc/upstream.html
Normal file
1231
doc/upstream.html
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -600,7 +600,19 @@ M.perform_action = function(action, cb)
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
uv.fs_symlink(target, path, flags, cb)
|
uv.fs_symlink(target, path, flags, cb)
|
||||||
else
|
else
|
||||||
fs.touch(path, config.new_file_mode, cb)
|
fs.touch(
|
||||||
|
path,
|
||||||
|
config.new_file_mode,
|
||||||
|
vim.schedule_wrap(function(err)
|
||||||
|
if not err then
|
||||||
|
vim.api.nvim_exec_autocmds(
|
||||||
|
'User',
|
||||||
|
{ pattern = 'CanolaFileCreated', modeline = false, data = { path = path } }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
cb(err)
|
||||||
|
end)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
elseif action.type == 'delete' then
|
elseif action.type == 'delete' then
|
||||||
local _, path = util.parse_url(action.url)
|
local _, path = util.parse_url(action.url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue