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 return Promise .new (function (resolve , reject )
@@ -325,6 +327,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
325327 local attach_file = vim .fs .joinpath (attach_dir , basename )
326328 local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
327329 return utils .writefile (attach_file , data , { excl = true }):next (function ()
330+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
328331 node :add_auto_tag ()
329332 -- Ignore all errors here, this is just to determine whether we can store
330333 -- a link to `bufname`.
@@ -368,6 +371,7 @@ function AttachCore:attach_many(node, files, opts)
368371 end , files )
369372 --- @param successes boolean[]
370373 :next (function (successes )
374+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
371375 node :add_auto_tag ()
372376 --- @param tally orgmode.attach.core.attach_many.result
373377 --- @param success boolean
@@ -408,6 +412,7 @@ function AttachCore:attach_new(node, name, opts)
408412 return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
409413 local path = vim .fs .joinpath (attach_dir , name )
410414 -- TODO: the emacs version doesn't run the hook here. Is this correct?
415+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
411416 node :add_auto_tag ()
412417 --- @type vim.api.keyset.cmd
413418 return Promise .new (function (resolve , reject )
453458function AttachCore :open (name , node )
454459 local attach_dir = self :get_dir (node )
455460 local path = vim .fs .joinpath (attach_dir , name )
461+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
456462 return assert (vim .ui .open (path ))
457463end
458464
464470function AttachCore :open_in_vim (name , node )
465471 local attach_dir = self :get_dir (node )
466472 local path = vim .fs .joinpath (attach_dir , name )
473+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
467474 vim .cmd .edit (path )
468475end
469476
@@ -480,6 +487,7 @@ function AttachCore:delete_one(node, name)
480487 local attach_dir = self :get_dir (node )
481488 local path = vim .fs .joinpath (attach_dir , name )
482489 return fileops .unlink (path ):next (function ()
490+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
483491 return nil
484492 end )
485493end
@@ -514,6 +522,7 @@ function AttachCore:delete_all(node, recursive)
514522 return Promise .reject (errmsg )
515523 end
516524 return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
525+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
517526 node :remove_auto_tag ()
518527 return attach_dir
519528 end )
@@ -548,6 +557,7 @@ function AttachCore:sync(node, delete_empty_dir)
548557 self :untag (node )
549558 return Promise .resolve ()
550559 end
560+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
551561 local non_empty = has_any_non_litter_files (attach_dir )
552562 if non_empty then
553563 node :add_auto_tag ()
0 commit comments