@@ -228,11 +228,7 @@ function Capture:_refile_from_org_file(opts)
228
228
target_line = destination_headline :get_range ().end_line
229
229
end
230
230
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 ()
236
232
237
233
if destination_headline or source_headline :get_level () > 1 then
238
234
lines = self :_adapt_headline_level (source_headline , target_level , is_same_file )
@@ -279,41 +275,24 @@ function Capture:refile_file_headline_to_archive(headline)
279
275
if not vim .loop .fs_stat (archive_location ) then
280
276
vim .fn .writefile ({}, archive_location )
281
277
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
308
278
309
279
local destination_file = self .files :get (archive_location )
310
280
311
- return self :_refile_from_org_file ({
281
+ self :_refile_from_org_file ({
312
282
source_headline = headline ,
313
283
destination_file = destination_file ,
314
- lines = lines ,
315
284
message = (' Archived to %s' ):format (destination_file .filename ),
316
285
})
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 )
317
296
end
318
297
319
298
--- @param item OrgHeadline
0 commit comments