Skip to content

Commit 72d4462

Browse files
author
Alec Stewart
committed
refactor(capture): don't require("org") to get files.
1 parent e1aeb04 commit 72d4462

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

lua/orgmode/capture/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ end
7373
---@param template OrgCaptureTemplate
7474
---@return OrgPromise<OrgCaptureWindow>
7575
function Capture:open_template(template)
76+
template.files = self.files
7677
local window = CaptureWindow:new({
7778
template = template,
7879
on_open = function(capture_window)

lua/orgmode/capture/template/init.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ end
2424
---@param template? table
2525
---@return string[]
2626
local function get_target_tags(template)
27-
local org = require('orgmode')
28-
if not org.files or not template or template.target == '' then
27+
local files = template and template.files
28+
if not files or not template or template.target == '' then
2929
return {}
3030
end
3131

3232
local ok, file = pcall(function()
33-
return org.files:get(template:get_target())
33+
return files:get(template:get_target())
3434
end)
3535

3636
if not ok or not file then
@@ -52,13 +52,14 @@ local function get_target_tags(template)
5252
end
5353

5454
---@description For `%^G` expansion in capture templates: gets all tags in all agenda files.
55+
---@param template? table
5556
---@return string[]
56-
local function get_all_tags()
57-
local org = require('orgmode')
58-
if not org.files then
57+
local function get_all_tags(template)
58+
local files = template and template.files
59+
if not files then
5960
return {}
6061
end
61-
return org.files:get_tags()
62+
return files:get_tags()
6263
end
6364

6465
---@param single boolean
@@ -159,8 +160,8 @@ local expansions = {
159160
['%%%^g'] = function(_, template)
160161
return prompt_tags(true, get_target_tags(template))
161162
end,
162-
['%%%^G'] = function()
163-
return prompt_tags(false, get_all_tags())
163+
['%%%^G'] = function(_, template)
164+
return prompt_tags(false, get_all_tags(template))
164165
end,
165166
['%%a'] = function()
166167
return string.format('[[file:%s::%s]]', utils.current_file_path(), vim.api.nvim_win_get_cursor(0)[1])
@@ -179,6 +180,7 @@ local expansions = {
179180
---@field whole_file? boolean
180181

181182
---@class OrgCaptureTemplate:OrgCaptureTemplateOpts
183+
---@field files? OrgFiles
182184
---@field private _compile_hooks? (fun(content:string, content_type: 'target' | 'content'):string | nil)[]
183185
local Template = {}
184186

0 commit comments

Comments
 (0)