Skip to content

Commit 4d2b47b

Browse files
Fix org_archive_location to properly replace %s placeholder with only filename. Closes #206.
1 parent b28a976 commit 4d2b47b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lua/orgmode/config/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ function Config:parse_archive_location(file, archive_loc)
243243
local parts = vim.split(archive_loc, '::')
244244
local archive_location = vim.trim(parts[1])
245245
if archive_location:find('%%s') then
246-
return string.format(archive_location, file)
246+
local file_path = vim.fn.fnamemodify(file, ':p:h')
247+
local file_name = vim.fn.fnamemodify(file, ':t')
248+
local archive_filename = string.format(archive_location, file_name)
249+
return string.format('%s/%s', file_path, archive_filename)
247250
end
248251
return vim.fn.fnamemodify(archive_location, ':p')
249252
end

lua/orgmode/org/mappings.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ function OrgMappings:archive()
3838
file = Files.get_current_file()
3939
item = file:get_closest_headline()
4040
local archive_location = file:get_archive_file_location()
41+
local archive_directory = vim.fn.fnamemodify(archive_location, ':p:h')
42+
if vim.fn.isdirectory(archive_directory) == 0 then
43+
vim.fn.mkdir(archive_directory, 'p')
44+
end
4145
self.capture:refile_file_headline_to_archive(file, item, archive_location)
4246
Files.reload(
4347
archive_location,

0 commit comments

Comments
 (0)