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
vim .fn .setreg (vim .v .register , link )
@@ -317,6 +319,7 @@ function AttachCore:attach_buffer(node, bufnr, opts)
317
319
local attach_file = vim .fs .joinpath (attach_dir , basename )
318
320
local data = table.concat (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), ' \n ' )
319
321
return utils .writefile (attach_file , data , { excl = true }):next (function ()
322
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
320
323
node :add_auto_tag ()
321
324
-- Ignore all errors here, this is just to determine whether we can store
322
325
-- a link to `bufname`.
@@ -360,6 +363,7 @@ function AttachCore:attach_many(node, files, opts)
360
363
end , files )
361
364
--- @param successes boolean[]
362
365
:next (function (successes )
366
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
363
367
node :add_auto_tag ()
364
368
--- @param tally orgmode.attach.core.attach_many.result
365
369
--- @param success boolean
@@ -400,6 +404,7 @@ function AttachCore:attach_new(node, name, opts)
400
404
return self :get_dir_or_create (node , opts .set_dir_method , opts .new_dir ):next (function (attach_dir )
401
405
local path = vim .fs .joinpath (attach_dir , name )
402
406
-- TODO: the emacs version doesn't run the hook here. Is this correct?
407
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
403
408
node :add_auto_tag ()
404
409
--- @type vim.api.keyset.cmd
405
410
return Promise .new (function (resolve , reject )
445
450
function AttachCore :open (name , node )
446
451
local attach_dir = self :get_dir (node )
447
452
local path = vim .fs .joinpath (attach_dir , name )
453
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
448
454
return assert (vim .ui .open (path ))
449
455
end
450
456
456
462
function AttachCore :open_in_vim (name , node )
457
463
local attach_dir = self :get_dir (node )
458
464
local path = vim .fs .joinpath (attach_dir , name )
465
+ EventManager .dispatch (EventManager .event .AttachOpened :new (node , path ))
459
466
vim .cmd .edit (path )
460
467
end
461
468
@@ -472,6 +479,7 @@ function AttachCore:delete_one(node, name)
472
479
local attach_dir = self :get_dir (node )
473
480
local path = vim .fs .joinpath (attach_dir , name )
474
481
return fileops .unlink (path ):next (function ()
482
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
475
483
return nil
476
484
end )
477
485
end
@@ -506,6 +514,7 @@ function AttachCore:delete_all(node, recursive)
506
514
return Promise .reject (errmsg )
507
515
end
508
516
return fileops .remove_directory (attach_dir , { recursive = true }):next (function ()
517
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
509
518
node :remove_auto_tag ()
510
519
return attach_dir
511
520
end )
@@ -540,6 +549,7 @@ function AttachCore:sync(node, delete_empty_dir)
540
549
self :untag (node )
541
550
return Promise .resolve ()
542
551
end
552
+ EventManager .dispatch (EventManager .event .AttachChanged :new (node , attach_dir ))
543
553
local non_empty = has_any_non_litter_files (attach_dir )
544
554
if non_empty then
545
555
node :add_auto_tag ()
0 commit comments