Skip to content

Commit 63d2cbb

Browse files
fix(archive): Set correct archive category on archived headline
Fixes #882
1 parent 4c942f7 commit 63d2cbb

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lua/orgmode/capture/init.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ function Capture:refile_file_headline_to_archive(headline)
297297

298298
local destination_file = self.files:get(archive_location)
299299
local todo_state = headline:get_todo()
300+
local headline_category = headline:get_category()
301+
local outline_path = headline:get_outline_path()
300302

301303
return self
302304
:_refile_from_org_file({
@@ -310,11 +312,10 @@ function Capture:refile_file_headline_to_archive(headline)
310312
local archived_headline = archive_file:get_closest_headline({ target_line, 0 })
311313
archived_headline:set_property('ARCHIVE_TIME', Date.now():to_string())
312314
archived_headline:set_property('ARCHIVE_FILE', file.filename)
313-
local outline_path = headline:get_outline_path()
314315
if outline_path ~= '' then
315316
archived_headline:set_property('ARCHIVE_OLPATH', outline_path)
316317
end
317-
archived_headline:set_property('ARCHIVE_CATEGORY', headline:get_category())
318+
archived_headline:set_property('ARCHIVE_CATEGORY', headline_category)
318319
archived_headline:set_property('ARCHIVE_TODO', todo_state or '')
319320
end)
320321
end)

tests/plenary/ui/mappings/archive_spec.lua

+30
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,34 @@ describe('Archive', function()
9393
' Body text baz',
9494
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
9595
end)
96+
97+
it('sets the correct archive category on the archived headline', function()
98+
local file = helpers.create_agenda_file({
99+
'* foobar',
100+
' :PROPERTIES:',
101+
' :CATEGORY: custom_category',
102+
' :END:',
103+
'* foo',
104+
})
105+
106+
local now = Date.now()
107+
vim.cmd([[exe "norm ,o$"]])
108+
-- Pause to finish the archiving
109+
vim.wait(50)
110+
assert.are.same({
111+
'* foo',
112+
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
113+
114+
vim.cmd(('edit %s'):format(file.filename .. '_archive'))
115+
assert.are.same({
116+
'* foobar',
117+
' :PROPERTIES:',
118+
' :CATEGORY: custom_category',
119+
' :ARCHIVE_TIME: ' .. now:to_string(),
120+
' :ARCHIVE_FILE: ' .. file.filename,
121+
' :ARCHIVE_CATEGORY: custom_category',
122+
' :ARCHIVE_TODO: ',
123+
' :END:',
124+
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
125+
end)
96126
end)

0 commit comments

Comments
 (0)