feat(config): add templates.cursor_marker for post-template cursor placement

Problem: after apply_template writes a file's content to the buffer,
cursor positioning was left entirely to the user's setup_code hook,
forcing everyone to reimplement the same placeholder-stripping logic.

Solution: add an optional templates.cursor_marker config key. When set,
apply_template scans the written lines for the marker, strips it, and
positions the cursor there via bufwinid so it works in both the
provisional and existing-file paths.
This commit is contained in:
Barrett Ruth 2026-03-03 00:09:57 -05:00 committed by Barrett Ruth
parent d3324aafa3
commit 6a395af98f
2 changed files with 26 additions and 0 deletions

View file

@ -9,6 +9,9 @@
---@field commands CpLangCommands
---@field template? string
---@class CpTemplatesConfig
---@field cursor_marker? string
---@class CpPlatformOverrides
---@field extension? string
---@field commands? CpLangCommands
@ -86,6 +89,7 @@
---@class cp.Config
---@field languages table<string, CpLanguage>
---@field platforms table<string, CpPlatform>
---@field templates? CpTemplatesConfig
---@field hooks Hooks
---@field debug boolean
---@field open_url boolean
@ -320,6 +324,13 @@ function M.setup(user_config)
error('[cp.nvim] At least one platform must be configured')
end
if cfg.templates ~= nil then
vim.validate({ templates = { cfg.templates, 'table' } })
if cfg.templates.cursor_marker ~= nil then
vim.validate({ cursor_marker = { cfg.templates.cursor_marker, 'string' } })
end
end
vim.validate({
hooks = { cfg.hooks, { 'table' } },
ui = { cfg.ui, { 'table' } },