How to explain why startinsert()
does not work?
#81
-
Hi, please look at the following local thisInitFile = debug.getinfo(1).source:match('@?(.*)')
local configDir = vim.fs.dirname(thisInitFile)
local exepath = vim.uv.exepath()
vim.env['XDG_CONFIG_HOME'] = configDir
vim.env['XDG_DATA_HOME'] = configDir .. '/.xdg/data'
vim.env['XDG_STATE_HOME'] = configDir .. '/.xdg/state'
vim.env['XDG_CACHE_HOME'] = configDir .. '/.xdg/cache'
local stdPathConfig = vim.fn.stdpath('config')
vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)
local pluginsPath = vim.fn.fnamemodify('plugins/', ':p')
for name, url in pairs{
['flatten-nvim'] = 'https://github.com/willothy/flatten.nvim',
} do
local installPath = pluginsPath .. name
if vim.fn.isdirectory(installPath) == 0 then
vim.fn.system {
'git',
'clone',
'--depth=1',
url,
installPath,
}
end
vim.opt.runtimepath:append(installPath)
end
require('flatten').setup({
callbacks = {
post_open = function (bufnr, winnr, ft, _is_blocking)
if ft == 'gitcommit' then
vim.wo[winnr].number = true
vim.cmd.startinsert()
vim.api.nvim_create_autocmd({'QuitPre'}, {
buffer = bufnr,
once = true,
callback = vim.schedule_wrap(function ()
vim.api.nvim_buf_delete(bufnr, {})
end),
})
end
end,
}
})
vim.api.nvim_create_autocmd('FileType', {
pattern = 'gitcommit',
callback = function ()
vim.cmd.startinsert()
end,
})
vim.api.nvim_create_autocmd('UIEnter', {
callback = function ()
vim.cmd.new({mods = {split = 'botright'}})
vim.fn.termopen(
vim.go.shell,
{
env = {
GIT_EDITOR = table.concat({
exepath,
'--clean',
'-u',
thisInitFile
}, ' ')
},
}
)
end,
}) It does not work both in |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I am not sure, but it is possible that because the hooks are executed in a function that is called via RPC, the API is unavailable / won't work. Have you tried wrapping the hook in Note: Other hooks should not be scheduled as they are expected to be executed synchronously, but the post_open can be non-blocking if needed. |
Beta Was this translation helpful? Give feedback.
-
require('flatten').setup({
callbacks = {
post_open = function (bufnr, winnr, ft, _is_blocking)
if ft == 'gitcommit' then
vim.wo[winnr].number = true
vim.schedule_wrap(function()
vim.cmd.startinsert()
end)
vim.api.nvim_create_autocmd({'QuitPre'}, {
buffer = bufnr,
once = true,
callback = vim.schedule_wrap(function ()
vim.api.nvim_buf_delete(bufnr, {})
end),
})
end
end,
}
})
vim.api.nvim_create_autocmd('FileType', {
pattern = 'gitcommit',
callback = vim.schedule_wrap(function ()
vim.cmd.startinsert()
end),
}) Do you mean something like above? I tried also wrapping the whole Anyway, thanks for the plugin as an interesting example of what we can do with Neovim. |
Beta Was this translation helpful? Give feedback.
-
I just tried this in my config and it does work. Just replace vim.schedule_wrap(function()
vim.cmd.startinsert()
end) with vim.schedule(vim.cmd.startinsert) in your |
Beta Was this translation helpful? Give feedback.
I just tried this in my config and it does work.
Just replace
with
in your
post_open
callback.