Skip to content

Commit

Permalink
fix(archive): Set correct archive category on archived headline
Browse files Browse the repository at this point in the history
Fixes #882
  • Loading branch information
kristijanhusak committed Feb 1, 2025
1 parent 4c942f7 commit 63d2cbb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ function Capture:refile_file_headline_to_archive(headline)

local destination_file = self.files:get(archive_location)
local todo_state = headline:get_todo()
local headline_category = headline:get_category()
local outline_path = headline:get_outline_path()

return self
:_refile_from_org_file({
Expand All @@ -310,11 +312,10 @@ function Capture:refile_file_headline_to_archive(headline)
local archived_headline = archive_file:get_closest_headline({ target_line, 0 })
archived_headline:set_property('ARCHIVE_TIME', Date.now():to_string())
archived_headline:set_property('ARCHIVE_FILE', file.filename)
local outline_path = headline:get_outline_path()
if outline_path ~= '' then
archived_headline:set_property('ARCHIVE_OLPATH', outline_path)
end
archived_headline:set_property('ARCHIVE_CATEGORY', headline:get_category())
archived_headline:set_property('ARCHIVE_CATEGORY', headline_category)
archived_headline:set_property('ARCHIVE_TODO', todo_state or '')
end)
end)
Expand Down
30 changes: 30 additions & 0 deletions tests/plenary/ui/mappings/archive_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,34 @@ describe('Archive', function()
' Body text baz',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
end)

it('sets the correct archive category on the archived headline', function()
local file = helpers.create_agenda_file({
'* foobar',
' :PROPERTIES:',
' :CATEGORY: custom_category',
' :END:',
'* foo',
})

local now = Date.now()
vim.cmd([[exe "norm ,o$"]])
-- Pause to finish the archiving
vim.wait(50)
assert.are.same({
'* foo',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))

vim.cmd(('edit %s'):format(file.filename .. '_archive'))
assert.are.same({
'* foobar',
' :PROPERTIES:',
' :CATEGORY: custom_category',
' :ARCHIVE_TIME: ' .. now:to_string(),
' :ARCHIVE_FILE: ' .. file.filename,
' :ARCHIVE_CATEGORY: custom_category',
' :ARCHIVE_TODO: ',
' :END:',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
end)
end)

0 comments on commit 63d2cbb

Please sign in to comment.