|
111 | 111 | function Capture:refile(confirm)
|
112 | 112 | local is_modified = vim.bo.modified
|
113 | 113 | local file, lines, item, template = self:_get_refile_vars()
|
| 114 | + if not file then |
| 115 | + return |
| 116 | + end |
114 | 117 | local headline_title = template.headline
|
115 | 118 | if confirm and is_modified then
|
116 | 119 | local choice = vim.fn.confirm(string.format('Do you want to refile this to %s?', file), '&Yes\n&No')
|
|
135 | 138 | ---Triggered when refiling to destination from capture buffer
|
136 | 139 | function Capture:refile_to_destination()
|
137 | 140 | local file, lines, item = self:_get_refile_vars()
|
| 141 | + if not file then |
| 142 | + return |
| 143 | + end |
138 | 144 | self:_refile_content_with_fallback(lines, file, item)
|
139 | 145 | self:kill()
|
140 | 146 | end
|
|
143 | 149 | function Capture:_get_refile_vars()
|
144 | 150 | local template = vim.api.nvim_buf_get_var(0, 'org_template') or {}
|
145 | 151 | local file = vim.fn.resolve(vim.fn.fnamemodify(template.target or config.org_default_notes_file, ':p'))
|
| 152 | + if vim.fn.filereadable(file) == 0 then |
| 153 | + local choice = vim.fn.confirm(('Refile destination %s does not exist. Create now?'):format(file), '&Yes\n&No') |
| 154 | + if choice ~= 1 then |
| 155 | + utils.echo_error('Cannot proceed without a valid refile destination') |
| 156 | + return |
| 157 | + end |
| 158 | + vim.fn.mkdir(vim.fn.fnamemodify(file, ':h'), 'p') |
| 159 | + vim.fn.writefile({}, file) |
| 160 | + end |
146 | 161 | local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
|
147 | 162 | local org_file = File.from_content(lines, 'capture', utils.current_file_path())
|
148 | 163 | local item = nil
|
|
0 commit comments