Skip to content

Commit 4874e72

Browse files
feat(capture): Compile template target when retrieving
1 parent 8cf9e67 commit 4874e72

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lua/orgmode/capture/template/init.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local expansions = {
4646
---@field whole_file? boolean
4747

4848
---@class OrgCaptureTemplate:OrgCaptureTemplateOpts
49-
---@field private _compile_hooks (fun(content:string):string)[]
49+
---@field private _compile_hooks (fun(content:string, type: 'target' | 'content'):string)[]
5050
local Template = {}
5151

5252
---@param opts OrgCaptureTemplateOpts
@@ -69,7 +69,7 @@ function Template:new(opts)
6969
local this = {}
7070
this.description = opts.description or ''
7171
this.template = opts.template or ''
72-
this.target = self:_compile(opts.target or '')
72+
this.target = opts.target or ''
7373
this.headline = opts.headline
7474
this.properties = TemplateProperties:new(opts.properties)
7575
this.datetree = opts.datetree
@@ -156,7 +156,7 @@ function Template:compile()
156156
if type(content) == 'table' then
157157
content = table.concat(content, '\n')
158158
end
159-
content = self:_compile(content or '')
159+
content = self:_compile(content or '', 'content')
160160
return vim.split(content, '\n', { plain = true })
161161
end
162162

@@ -189,7 +189,7 @@ end
189189

190190
---@return string
191191
function Template:get_target()
192-
return vim.fn.resolve(vim.fn.fnamemodify(self.target, ':p'))
192+
return vim.fn.resolve(vim.fn.fnamemodify(self:_compile(self.target, 'target'), ':p'))
193193
end
194194

195195
---@param lines string[]
@@ -210,15 +210,16 @@ end
210210

211211
---@private
212212
---@param content string
213+
---@param type 'target' | 'content'
213214
---@return string
214-
function Template:_compile(content)
215+
function Template:_compile(content, type)
215216
content = self:_compile_dates(content)
216217
content = self:_compile_expansions(content)
217218
content = self:_compile_expressions(content)
218219
content = self:_compile_prompts(content)
219220
if self._compile_hooks then
220221
for _, hook in ipairs(self._compile_hooks) do
221-
content = hook(content)
222+
content = hook(content, type)
222223
end
223224
end
224225
return content

0 commit comments

Comments
 (0)