File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -421,6 +421,15 @@ Journal example:<br />
421421 } }
422422 ```
423423
424+ Journal example with dynamic target, i.e. a separate file per month:<br />
425+ ``` lua
426+ { J = {
427+ description = ' Journal' ,
428+ template = ' \n *** %<%Y-%m-%d> %<%A>\n **** %U\n\n %?' ,
429+ target = ' ~/sync/org/journal/%<%Y-%m>.org'
430+ } }
431+ ```
432+
424433Nested key example:<br />
425434 ``` lua
426435 {
Original file line number Diff line number Diff line change 135135--- @private
136136function Capture :_get_refile_vars ()
137137 local template = vim .api .nvim_buf_get_var (0 , ' org_template' ) or {}
138- local file = vim .fn .resolve (vim .fn .fnamemodify (template .target or config .org_default_notes_file , ' :p' ))
138+ local target = self .templates :compile_target (template .target or config .org_default_notes_file )
139+ local file = vim .fn .resolve (vim .fn .fnamemodify (target , ' :p' ))
140+
139141 if vim .fn .filereadable (file ) == 0 then
140142 local choice = vim .fn .confirm ((' Refile destination %s does not exist. Create now?' ):format (file ), ' &Yes\n &No' )
141143 if choice ~= 1 then
Original file line number Diff line number Diff line change @@ -55,13 +55,16 @@ function Templates:compile(template)
5555 if type (content ) == ' table' then
5656 content = table.concat (content , ' \n ' )
5757 end
58- content = self :_compile_dates (content )
59- content = self :_compile_expansions (content )
60- content = self :_compile_expressions (content )
61- content = self :_compile_prompts (content )
58+ content = self :_compile (content )
6259 return vim .split (content , ' \n ' , true )
6360end
6461
62+ --- @param target string
63+ --- @return string
64+ function Templates :compile_target (target )
65+ return self :_compile (target )
66+ end
67+
6568function Templates :setup ()
6669 local initial_position = vim .fn .search (' %?' )
6770 local is_at_end_of_line = vim .fn .search (' %?$' ) > 0
@@ -76,6 +79,17 @@ function Templates:setup()
7679 end
7780end
7881
82+ --- @private
83+ --- @param content string
84+ --- @return string
85+ function Templates :_compile (content )
86+ content = self :_compile_dates (content )
87+ content = self :_compile_expansions (content )
88+ content = self :_compile_expressions (content )
89+ content = self :_compile_prompts (content )
90+ return content
91+ end
92+
7993--- @param content string
8094--- @return string
8195function Templates :_compile_expansions (content , found_expansions )
You can’t perform that action at this time.
0 commit comments