Skip to content

Commit 95f9273

Browse files
authored
Enable expansions within lua expression (#419)
1 parent 77ea133 commit 95f9273

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lua/orgmode/capture/templates.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,9 @@ function Templates:compile(template)
5656
content = table.concat(content, '\n')
5757
end
5858
content = self:_compile_dates(content)
59-
content = self:_compile_prompts(content)
59+
content = self:_compile_expansions(content)
6060
content = self:_compile_expressions(content)
61-
for expansion, compiler in pairs(expansions) do
62-
if content:match(vim.pesc(expansion)) then
63-
content = content:gsub(vim.pesc(expansion), compiler())
64-
end
65-
end
61+
content = self:_compile_prompts(content)
6662
return vim.split(content, '\n', true)
6763
end
6864

@@ -80,6 +76,18 @@ function Templates:setup()
8076
end
8177
end
8278

79+
---@param content string
80+
---@return string
81+
function Templates:_compile_expansions(content, found_expansions)
82+
found_expansions = found_expansions or expansions
83+
for expansion, compiler in pairs(found_expansions) do
84+
if content:match(vim.pesc(expansion)) then
85+
content = content:gsub(vim.pesc(expansion), compiler())
86+
end
87+
end
88+
return content
89+
end
90+
8391
---@param content string
8492
---@return string
8593
function Templates:_compile_dates(content)

0 commit comments

Comments
 (0)