11local AttachNode = require (' orgmode.attach.node' )
2+ local EventManager = require (' orgmode.events' )
23local methods = require (' orgmode.attach.methods' )
34local Promise = require (' orgmode.utils.promise' )
45local config = require (' orgmode.config' )
@@ -394,6 +395,7 @@ function AttachCore:attach(node, file, opts)
394395 if not success then
395396 return nil
396397 end
398+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
397399 node :toggle_auto_tag (true )
398400 local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
399401 vim .fn .setreg (vim .v .register , link )
@@ -421,6 +423,7 @@ function AttachCore:attach_url(node, url, opts)
421423 if not success then
422424 return nil
423425 end
426+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
424427 node :toggle_auto_tag (true )
425428 local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = url })
426429 vim .fn .setreg (vim .v .register , link )
@@ -448,6 +451,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
448451 if not success then
449452 return nil
450453 end
454+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
451455 node :toggle_auto_tag (true )
452456 -- Ignore all errors here, this is just to determine whether we can store
453457 -- a link to `bufname`.
@@ -491,6 +495,7 @@ function AttachCore:attach_many(node, files, opts)
491495 end , files )
492496 --- @param successes boolean[]
493497 :next (function (successes )
498+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
494499 node :toggle_auto_tag (true )
495500 --- @param tally orgmode.attach.core.attach_many.result
496501 --- @param success boolean
@@ -531,6 +536,7 @@ function AttachCore:attach_new(node, name, opts)
531536 return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
532537 local path = vim .fs .joinpath (attach_dir , name )
533538 -- TODO: the emacs version doesn't run the hook here. Is this correct?
539+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
534540 node :toggle_auto_tag (true )
535541 --- @type vim.api.keyset.cmd
536542 return Promise .new (function (resolve , reject )
576582function AttachCore :open (name , node )
577583 local attach_dir = self :get_dir (node )
578584 local path = vim .fs .joinpath (attach_dir , name )
585+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
579586 return assert (vim .ui .open (path ))
580587end
581588
587594function AttachCore :open_in_vim (name , node )
588595 local attach_dir = self :get_dir (node )
589596 local path = vim .fs .joinpath (attach_dir , name )
597+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
590598 vim .cmd .edit (path )
591599end
592600
@@ -603,6 +611,7 @@ function AttachCore:delete_one(node, name)
603611 local attach_dir = self :get_dir (node )
604612 local path = vim .fs .joinpath (attach_dir , name )
605613 return fileops .unlink (path ):next (function ()
614+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
606615 return nil
607616 end )
608617end
@@ -637,6 +646,7 @@ function AttachCore:delete_all(node, recursive)
637646 return Promise .reject (errmsg )
638647 end
639648 return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
649+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
640650 node :toggle_auto_tag (false )
641651 return attach_dir
642652 end )
@@ -671,6 +681,7 @@ function AttachCore:sync(node, delete_empty_dir)
671681 self :untag (node )
672682 return Promise .resolve ()
673683 end
684+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
674685 local non_empty = has_any_non_litter_files (attach_dir )
675686 node :toggle_auto_tag (non_empty )
676687 if non_empty then
0 commit comments