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' )
@@ -289,6 +290,7 @@ function AttachCore:attach(node, file, opts)
289
290
if not success then
290
291
return nil
291
292
end
293
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
292
294
node :add_auto_tag ()
293
295
local link = self .links :store_link_to_attachment ({ attach_dir = attach_dir , original = file })
294
296
return Promise .new (function (resolve , reject )
@@ -325,6 +327,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
325
327
local attach_file = vim .fs .joinpath (attach_dir , basename )
326
328
local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
327
329
return utils .writefile (attach_file , data , { excl = true }):next (function ()
330
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
328
331
node :add_auto_tag ()
329
332
-- Ignore all errors here, this is just to determine whether we can store
330
333
-- a link to `bufname`.
@@ -368,6 +371,7 @@ function AttachCore:attach_many(node, files, opts)
368
371
end , files )
369
372
--- @param successes boolean[]
370
373
:next (function (successes )
374
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
371
375
node :add_auto_tag ()
372
376
--- @param tally orgmode.attach.core.attach_many.result
373
377
--- @param success boolean
@@ -408,6 +412,7 @@ function AttachCore:attach_new(node, name, opts)
408
412
return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
409
413
local path = vim .fs .joinpath (attach_dir , name )
410
414
-- TODO: the emacs version doesn't run the hook here. Is this correct?
415
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
411
416
node :add_auto_tag ()
412
417
--- @type vim.api.keyset.cmd
413
418
return Promise .new (function (resolve , reject )
453
458
function AttachCore :open (name , node )
454
459
local attach_dir = self :get_dir (node )
455
460
local path = vim .fs .joinpath (attach_dir , name )
461
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
456
462
return assert (vim .ui .open (path ))
457
463
end
458
464
464
470
function AttachCore :open_in_vim (name , node )
465
471
local attach_dir = self :get_dir (node )
466
472
local path = vim .fs .joinpath (attach_dir , name )
473
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
467
474
vim .cmd .edit (path )
468
475
end
469
476
@@ -480,6 +487,7 @@ function AttachCore:delete_one(node, name)
480
487
local attach_dir = self :get_dir (node )
481
488
local path = vim .fs .joinpath (attach_dir , name )
482
489
return fileops .unlink (path ):next (function ()
490
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
483
491
return nil
484
492
end )
485
493
end
@@ -514,6 +522,7 @@ function AttachCore:delete_all(node, recursive)
514
522
return Promise .reject (errmsg )
515
523
end
516
524
return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
525
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
517
526
node :remove_auto_tag ()
518
527
return attach_dir
519
528
end )
@@ -548,6 +557,7 @@ function AttachCore:sync(node, delete_empty_dir)
548
557
self :untag (node )
549
558
return Promise .resolve ()
550
559
end
560
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
551
561
local non_empty = has_any_non_litter_files (attach_dir )
552
562
if non_empty then
553
563
node :add_auto_tag ()
0 commit comments