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' )
@@ -289,6 +290,7 @@ function AttachCore:attach(node, file, opts)
289290 if not success then
290291 return nil
291292 end
293+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
292294 node :add_auto_tag ()
293295 local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
294296 vim .fn .setreg (vim .v .register , link )
@@ -317,6 +319,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
317319 local attach_file = vim .fs .joinpath (attach_dir , basename )
318320 local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
319321 return utils .writefile (attach_file , data , { excl = true }):next (function ()
322+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
320323 node :add_auto_tag ()
321324 -- Ignore all errors here, this is just to determine whether we can store
322325 -- a link to `bufname`.
@@ -360,6 +363,7 @@ function AttachCore:attach_many(node, files, opts)
360363 end , files )
361364 --- @param successes boolean[]
362365 :next (function (successes )
366+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
363367 node :add_auto_tag ()
364368 --- @param tally orgmode.attach.core.attach_many.result
365369 --- @param success boolean
@@ -400,6 +404,7 @@ function AttachCore:attach_new(node, name, opts)
400404 return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
401405 local path = vim .fs .joinpath (attach_dir , name )
402406 -- TODO: the emacs version doesn't run the hook here. Is this correct?
407+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
403408 node :add_auto_tag ()
404409 --- @type vim.api.keyset.cmd
405410 return Promise .new (function (resolve , reject )
445450function AttachCore :open (name , node )
446451 local attach_dir = self :get_dir (node )
447452 local path = vim .fs .joinpath (attach_dir , name )
453+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
448454 return assert (vim .ui .open (path ))
449455end
450456
456462function AttachCore :open_in_vim (name , node )
457463 local attach_dir = self :get_dir (node )
458464 local path = vim .fs .joinpath (attach_dir , name )
465+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
459466 vim .cmd .edit (path )
460467end
461468
@@ -472,6 +479,7 @@ function AttachCore:delete_one(node, name)
472479 local attach_dir = self :get_dir (node )
473480 local path = vim .fs .joinpath (attach_dir , name )
474481 return fileops .unlink (path ):next (function ()
482+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
475483 return nil
476484 end )
477485end
@@ -506,6 +514,7 @@ function AttachCore:delete_all(node, recursive)
506514 return Promise .reject (errmsg )
507515 end
508516 return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
517+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
509518 node :remove_auto_tag ()
510519 return attach_dir
511520 end )
@@ -540,6 +549,7 @@ function AttachCore:sync(node, delete_empty_dir)
540549 self :untag (node )
541550 return Promise .resolve ()
542551 end
552+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
543553 local non_empty = has_any_non_litter_files (attach_dir )
544554 if non_empty then
545555 node :add_auto_tag ()
0 commit comments