1
1
local AttachNode = require (' orgmode.attach.node' )
2
+ local EventManager = require (' orgmode.events' )
2
3
local Promise = require (' orgmode.utils.promise' )
3
4
local config = require (' orgmode.config' )
4
5
local fileops = require (' orgmode.attach.fileops' )
@@ -428,6 +429,7 @@ function AttachCore:attach(node, file, opts)
428
429
if not success then
429
430
return nil
430
431
end
432
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
431
433
node :add_auto_tag ()
432
434
local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
433
435
vim .fn .setreg (vim .v .register , link )
@@ -456,6 +458,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
456
458
local attach_file = vim .fs .joinpath (attach_dir , basename )
457
459
local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
458
460
return utils .writefile (attach_file , data , { excl = true }):next (function ()
461
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
459
462
node :add_auto_tag ()
460
463
-- Ignore all errors here, this is just to determine whether we can store
461
464
-- a link to `bufname`.
@@ -499,6 +502,7 @@ function AttachCore:attach_many(node, files, opts)
499
502
end , files )
500
503
--- @param successes boolean[]
501
504
:next (function (successes )
505
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
502
506
node :add_auto_tag ()
503
507
--- @param tally orgmode.attach.core.attach_many.result
504
508
--- @param success boolean
@@ -539,6 +543,7 @@ function AttachCore:attach_new(node, name, opts)
539
543
return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
540
544
local path = vim .fs .joinpath (attach_dir , name )
541
545
-- TODO: the emacs version doesn't run the hook here. Is this correct?
546
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
542
547
node :add_auto_tag ()
543
548
--- @type vim.api.keyset.cmd
544
549
return Promise .new (function (resolve , reject )
584
589
function AttachCore :open (name , node )
585
590
local attach_dir = self :get_dir (node )
586
591
local path = vim .fs .joinpath (attach_dir , name )
592
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
587
593
return assert (vim .ui .open (path ))
588
594
end
589
595
595
601
function AttachCore :open_in_vim (name , node )
596
602
local attach_dir = self :get_dir (node )
597
603
local path = vim .fs .joinpath (attach_dir , name )
604
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
598
605
vim .cmd .edit (path )
599
606
end
600
607
@@ -611,6 +618,7 @@ function AttachCore:delete_one(node, name)
611
618
local attach_dir = self :get_dir (node )
612
619
local path = vim .fs .joinpath (attach_dir , name )
613
620
return fileops .unlink (path ):next (function ()
621
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
614
622
return nil
615
623
end )
616
624
end
@@ -645,6 +653,7 @@ function AttachCore:delete_all(node, recursive)
645
653
return Promise .reject (errmsg )
646
654
end
647
655
return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
656
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
648
657
node :remove_auto_tag ()
649
658
return attach_dir
650
659
end )
@@ -679,6 +688,7 @@ function AttachCore:sync(node, delete_empty_dir)
679
688
self :untag (node )
680
689
return Promise .resolve ()
681
690
end
691
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
682
692
local non_empty = has_any_non_litter_files (attach_dir )
683
693
if non_empty then
684
694
node :add_auto_tag ()
0 commit comments