11local AttachNode = require (' orgmode.attach.node' )
2+ local EventManager = require (' orgmode.events' )
23local Promise = require (' orgmode.utils.promise' )
34local config = require (' orgmode.config' )
45local fileops = require (' orgmode.attach.fileops' )
@@ -428,6 +429,7 @@ function AttachCore:attach(node, file, opts)
428429 if not success then
429430 return nil
430431 end
432+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
431433 node :add_auto_tag ()
432434 local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
433435 vim .fn .setreg (vim .v .register , link )
@@ -456,6 +458,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
456458 local attach_file = vim .fs .joinpath (attach_dir , basename )
457459 local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
458460 return utils .writefile (attach_file , data , { excl = true }):next (function ()
461+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
459462 node :add_auto_tag ()
460463 -- Ignore all errors here, this is just to determine whether we can store
461464 -- a link to `bufname`.
@@ -499,6 +502,7 @@ function AttachCore:attach_many(node, files, opts)
499502 end , files )
500503 --- @param successes boolean[]
501504 :next (function (successes )
505+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
502506 node :add_auto_tag ()
503507 --- @param tally orgmode.attach.core.attach_many.result
504508 --- @param success boolean
@@ -539,6 +543,7 @@ function AttachCore:attach_new(node, name, opts)
539543 return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
540544 local path = vim .fs .joinpath (attach_dir , name )
541545 -- TODO: the emacs version doesn't run the hook here. Is this correct?
546+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
542547 node :add_auto_tag ()
543548 --- @type vim.api.keyset.cmd
544549 return Promise .new (function (resolve , reject )
584589function AttachCore :open (name , node )
585590 local attach_dir = self :get_dir (node )
586591 local path = vim .fs .joinpath (attach_dir , name )
592+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
587593 return assert (vim .ui .open (path ))
588594end
589595
595601function AttachCore :open_in_vim (name , node )
596602 local attach_dir = self :get_dir (node )
597603 local path = vim .fs .joinpath (attach_dir , name )
604+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
598605 vim .cmd .edit (path )
599606end
600607
@@ -611,6 +618,7 @@ function AttachCore:delete_one(node, name)
611618 local attach_dir = self :get_dir (node )
612619 local path = vim .fs .joinpath (attach_dir , name )
613620 return fileops .unlink (path ):next (function ()
621+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
614622 return nil
615623 end )
616624end
@@ -645,6 +653,7 @@ function AttachCore:delete_all(node, recursive)
645653 return Promise .reject (errmsg )
646654 end
647655 return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
656+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
648657 node :remove_auto_tag ()
649658 return attach_dir
650659 end )
@@ -679,6 +688,7 @@ function AttachCore:sync(node, delete_empty_dir)
679688 self :untag (node )
680689 return Promise .resolve ()
681690 end
691+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
682692 local non_empty = has_any_non_litter_files (attach_dir )
683693 if non_empty then
684694 node :add_auto_tag ()
0 commit comments