1
1
local AttachNode = require (' orgmode.attach.node' )
2
+ local EventManager = require (' orgmode.events' )
2
3
local methods = require (' orgmode.attach.methods' )
3
4
local Promise = require (' orgmode.utils.promise' )
4
5
local config = require (' orgmode.config' )
@@ -394,6 +395,7 @@ function AttachCore:attach(node, file, opts)
394
395
if not success then
395
396
return nil
396
397
end
398
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
397
399
node :toggle_auto_tag (true )
398
400
local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
399
401
vim .fn .setreg (vim .v .register , link )
@@ -421,6 +423,7 @@ function AttachCore:attach_url(node, url, opts)
421
423
if not success then
422
424
return nil
423
425
end
426
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
424
427
node :toggle_auto_tag (true )
425
428
local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = url })
426
429
vim .fn .setreg (vim .v .register , link )
@@ -448,6 +451,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
448
451
if not success then
449
452
return nil
450
453
end
454
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
451
455
node :toggle_auto_tag (true )
452
456
-- Ignore all errors here, this is just to determine whether we can store
453
457
-- a link to `bufname`.
@@ -491,6 +495,7 @@ function AttachCore:attach_many(node, files, opts)
491
495
end , files )
492
496
--- @param successes boolean[]
493
497
:next (function (successes )
498
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
494
499
node :toggle_auto_tag (true )
495
500
--- @param tally orgmode.attach.core.attach_many.result
496
501
--- @param success boolean
@@ -531,6 +536,7 @@ function AttachCore:attach_new(node, name, opts)
531
536
return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
532
537
local path = vim .fs .joinpath (attach_dir , name )
533
538
-- TODO: the emacs version doesn't run the hook here. Is this correct?
539
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
534
540
node :toggle_auto_tag (true )
535
541
--- @type vim.api.keyset.cmd
536
542
return Promise .new (function (resolve , reject )
576
582
function AttachCore :open (name , node )
577
583
local attach_dir = self :get_dir (node )
578
584
local path = vim .fs .joinpath (attach_dir , name )
585
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
579
586
return assert (vim .ui .open (path ))
580
587
end
581
588
587
594
function AttachCore :open_in_vim (name , node )
588
595
local attach_dir = self :get_dir (node )
589
596
local path = vim .fs .joinpath (attach_dir , name )
597
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
590
598
vim .cmd .edit (path )
591
599
end
592
600
@@ -603,6 +611,7 @@ function AttachCore:delete_one(node, name)
603
611
local attach_dir = self :get_dir (node )
604
612
local path = vim .fs .joinpath (attach_dir , name )
605
613
return fileops .unlink (path ):next (function ()
614
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
606
615
return nil
607
616
end )
608
617
end
@@ -637,6 +646,7 @@ function AttachCore:delete_all(node, recursive)
637
646
return Promise .reject (errmsg )
638
647
end
639
648
return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
649
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
640
650
node :toggle_auto_tag (false )
641
651
return attach_dir
642
652
end )
@@ -671,6 +681,7 @@ function AttachCore:sync(node, delete_empty_dir)
671
681
self :untag (node )
672
682
return Promise .resolve ()
673
683
end
684
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
674
685
local non_empty = has_any_non_litter_files (attach_dir )
675
686
node :toggle_auto_tag (non_empty )
676
687
if non_empty then
0 commit comments