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 />
421
421
} }
422
422
```
423
423
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
+
424
433
Nested key example:<br />
425
434
``` lua
426
435
{
Original file line number Diff line number Diff line change 135
135
--- @private
136
136
function Capture :_get_refile_vars ()
137
137
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
+
139
141
if vim .fn .filereadable (file ) == 0 then
140
142
local choice = vim .fn .confirm ((' Refile destination %s does not exist. Create now?' ):format (file ), ' &Yes\n &No' )
141
143
if choice ~= 1 then
Original file line number Diff line number Diff line change @@ -55,13 +55,16 @@ function Templates:compile(template)
55
55
if type (content ) == ' table' then
56
56
content = table.concat (content , ' \n ' )
57
57
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 )
62
59
return vim .split (content , ' \n ' , true )
63
60
end
64
61
62
+ --- @param target string
63
+ --- @return string
64
+ function Templates :compile_target (target )
65
+ return self :_compile (target )
66
+ end
67
+
65
68
function Templates :setup ()
66
69
local initial_position = vim .fn .search (' %?' )
67
70
local is_at_end_of_line = vim .fn .search (' %?$' ) > 0
@@ -76,6 +79,17 @@ function Templates:setup()
76
79
end
77
80
end
78
81
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
+
79
93
--- @param content string
80
94
--- @return string
81
95
function Templates :_compile_expansions (content , found_expansions )
You can’t perform that action at this time.
0 commit comments