465
465
--- @private
466
466
--- @return OrgProcessCaptureOpts | false
467
467
function Capture :_get_refile_vars ()
468
- local file = self ._window .template :get_target ()
468
+ local source_file = self .files :get_current_file ()
469
+ local source_headline = nil
470
+ if not self ._window .template .whole_file then
471
+ source_headline = source_file :get_headlines ()[1 ]
472
+ end
469
473
474
+ local opts = {
475
+ source_file = source_file ,
476
+ source_headline = source_headline ,
477
+ destination_file = nil ,
478
+ destination_headline = nil ,
479
+ template = self ._window .template ,
480
+ }
481
+
482
+ if self .on_pre_refile then
483
+ self .on_pre_refile (self , opts )
484
+ end
485
+
486
+ local file = opts .template :get_target ()
470
487
if vim .fn .filereadable (file ) == 0 then
471
488
local choice = vim .fn .confirm ((' Refile destination %s does not exist. Create now?' ):format (file ), ' &Yes\n &No' )
472
489
if choice ~= 1 then
@@ -477,28 +494,16 @@ function Capture:_get_refile_vars()
477
494
vim .fn .writefile ({}, file )
478
495
end
479
496
480
- local source_file = self .files :get_current_file ()
481
- local source_headline = nil
482
- if not self ._window .template .whole_file then
483
- source_headline = source_file :get_headlines ()[1 ]
484
- end
485
- local destination_file = self .files :get (file )
486
- local destination_headline = nil
487
- if self ._window .template .headline then
488
- destination_headline = destination_file :find_headline_by_title (self ._window .template .headline )
489
- if not destination_headline then
490
- utils .echo_error ((' Refile headline "%s" does not exist in "%s"' ):format (self ._window .template .headline , file ))
497
+ opts .destination_file = self .files :get (file )
498
+ if opts .template .headline then
499
+ opts .destination_headline = opts .destination_file :find_headline_by_title (opts .template .headline )
500
+ if not opts .destination_headline then
501
+ utils .echo_error ((' Refile headline "%s" does not exist in "%s"' ):format (opts .template .headline , file ))
491
502
return false
492
503
end
493
504
end
494
505
495
- return {
496
- source_file = source_file ,
497
- source_headline = source_headline ,
498
- destination_file = destination_file ,
499
- destination_headline = destination_headline ,
500
- template = self ._window .template ,
501
- }
506
+ return opts
502
507
end
503
508
504
509
--- @private
0 commit comments