|
1 | 1 | local instance = {}
|
2 | 2 | local utils = require('orgmode.utils')
|
| 3 | +local fs = require('orgmode.utils.fs') |
3 | 4 | local defaults = require('orgmode.config.defaults')
|
4 | 5 | ---@type table<string, MapEntry>
|
5 | 6 | local mappings = require('orgmode.config.mappings')
|
|
154 | 155 | function Config:get_all_files()
|
155 | 156 | local all_filenames = {}
|
156 | 157 | if self.opts.org_default_notes_file and self.opts.org_default_notes_file ~= '' then
|
157 |
| - local default_full_path = vim.fn.resolve(vim.fn.expand(self.opts.org_default_notes_file, ':p')) |
158 |
| - table.insert(all_filenames, default_full_path) |
| 158 | + local default_full_path = vim.fn.resolve(vim.fn.fnamemodify(self.opts.org_default_notes_file, ':p')) |
| 159 | + if vim.loop.fs_stat(default_full_path) then |
| 160 | + table.insert(all_filenames, default_full_path) |
| 161 | + end |
159 | 162 | end
|
160 | 163 | local files = self.opts.org_agenda_files
|
161 | 164 | if not files or files == '' or (type(files) == 'table' and vim.tbl_isempty(files)) then
|
@@ -317,13 +320,23 @@ function Config:parse_archive_location(file, archive_loc)
|
317 | 320 | -- TODO: Support archive to headline
|
318 | 321 | local parts = vim.split(archive_loc, '::')
|
319 | 322 | local archive_location = vim.trim(parts[1])
|
320 |
| - if archive_location:find('%%s') then |
321 |
| - local file_path = vim.fn.fnamemodify(file, ':p:h') |
322 |
| - local file_name = vim.fn.fnamemodify(file, ':t') |
323 |
| - local archive_filename = string.format(archive_location, file_name) |
| 323 | + if not archive_location:find('%%s') then |
| 324 | + return vim.fn.fnamemodify(archive_location, ':p') |
| 325 | + end |
| 326 | + |
| 327 | + local file_path = vim.fn.fnamemodify(file, ':p:h') |
| 328 | + local file_name = vim.fn.fnamemodify(file, ':t') |
| 329 | + local archive_filename = string.format(archive_location, file_name) |
| 330 | + |
| 331 | + -- If org_archive_location is defined as relative path (example: "archive/%s_archive") |
| 332 | + -- then we need to prepend the file path to it |
| 333 | + local is_full_path = fs.substitute_path(archive_filename) |
| 334 | + |
| 335 | + if not is_full_path then |
324 | 336 | return string.format('%s/%s', file_path, archive_filename)
|
325 | 337 | end
|
326 |
| - return vim.fn.fnamemodify(archive_location, ':p') |
| 338 | + |
| 339 | + return vim.fn.fnamemodify(archive_filename, ':p') |
327 | 340 | end
|
328 | 341 |
|
329 | 342 | function Config:is_archive_file(file)
|
|
0 commit comments