@@ -228,11 +228,7 @@ function Capture:_refile_from_org_file(opts)
228228 target_line = destination_headline :get_range ().end_line
229229 end
230230
231- local lines = opts .lines
232-
233- if not lines then
234- lines = source_headline :get_lines ()
235- end
231+ local lines = source_headline :get_lines ()
236232
237233 if destination_headline or source_headline :get_level () > 1 then
238234 lines = self :_adapt_headline_level (source_headline , target_level , is_same_file )
@@ -279,41 +275,24 @@ function Capture:refile_file_headline_to_archive(headline)
279275 if not vim .loop .fs_stat (archive_location ) then
280276 vim .fn .writefile ({}, archive_location )
281277 end
282- local start_line = headline :get_range ().start_line
283- local lines = headline :get_lines ()
284- local properties_node = headline :get_properties ()
285- local append_line = headline :get_append_line () - start_line
286- local indent = headline :get_indent ()
287-
288- local archive_props = {
289- (' %s:ARCHIVE_TIME: %s' ):format (indent , Date .now ():to_string ()),
290- (' %s:ARCHIVE_FILE: %s' ):format (indent , file .filename ),
291- (' %s:ARCHIVE_CATEGORY: %s' ):format (indent , headline :get_category ()),
292- (' %s:ARCHIVE_TODO: %s' ):format (indent , headline :get_todo () or ' ' ),
293- }
294-
295- if properties_node then
296- local front_lines = { unpack (lines , 1 , append_line ) }
297- local back_lines = { unpack (lines , append_line + 1 , # lines ) }
298- lines = vim .list_extend (front_lines , archive_props )
299- lines = vim .list_extend (lines , back_lines )
300- else
301- local front_lines = { unpack (lines , 1 , append_line + 1 ) }
302- local back_lines = { unpack (lines , append_line + 2 , # lines ) }
303- table.insert (front_lines , (' %s:PROPERTIES:' ):format (indent ))
304- lines = vim .list_extend (front_lines , archive_props )
305- table.insert (lines , (' %s:END:' ):format (indent ))
306- lines = vim .list_extend (lines , back_lines )
307- end
308278
309279 local destination_file = self .files :get (archive_location )
310280
311- return self :_refile_from_org_file ({
281+ self :_refile_from_org_file ({
312282 source_headline = headline ,
313283 destination_file = destination_file ,
314- lines = lines ,
315284 message = (' Archived to %s' ):format (destination_file .filename ),
316285 })
286+
287+ destination_file = self .files :get (archive_location )
288+ self .files :update_file (destination_file .filename , function (archive_file )
289+ local headlines = archive_file :get_headlines_including_archived ()
290+ local last_headline = headlines [# headlines ]
291+ last_headline :set_property (' ARCHIVE_TIME' , Date .now ():to_string ())
292+ last_headline :set_property (' ARCHIVE_FILE' , file .filename )
293+ last_headline :set_property (' ARCHIVE_CATEGORY' , headline :get_category ())
294+ last_headline :set_property (' ARCHIVE_TODO' , headline :get_todo () or ' ' )
295+ end )
317296end
318297
319298--- @param item OrgHeadline
0 commit comments