2424--- @param template ? table
2525--- @return string[]
2626local 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)
5252end
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 ()
6263end
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 )[]
183185local Template = {}
184186
0 commit comments