Skip to content

Commit 71ac9d3

Browse files
feat(capture): Add on_close hook for capture instance
1 parent bb89dfc commit 71ac9d3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lua/orgmode/capture/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ local CaptureWindow = require('orgmode.capture.window')
88
local Date = require('orgmode.objects.date')
99
local Datetree = require('orgmode.capture.template.datetree')
1010

11+
---@alias OrgOnCaptureClose fun(capture:OrgCapture, opts:OrgProcessCaptureOpts)
12+
1113
---@class OrgCapture
1214
---@field templates OrgCaptureTemplates
1315
---@field closing_note OrgCaptureWindow
1416
---@field files OrgFiles
17+
---@field on_close OrgOnCaptureClose
1518
---@field _window OrgCaptureWindow
1619
local Capture = {}
1720
Capture.__index = Capture
1821

19-
---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates }
22+
---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates, on_close?: OrgOnCaptureClose }
2023
function Capture:new(opts)
2124
local this = setmetatable({}, self)
2225
this.files = opts.files
26+
this.on_close = opts.on_close
2327
this.templates = opts.templates or Templates:new()
2428
this.closing_note = this:_setup_closing_note()
2529
return this
@@ -69,6 +73,9 @@ function Capture:on_refile_close()
6973
if not opts then
7074
return
7175
end
76+
if self.on_close then
77+
self.on_close(self, opts)
78+
end
7279
if is_modified then
7380
local choice =
7481
vim.fn.confirm(string.format('Do you want to refile this to %s?', opts.destination_file.filename), '&Yes\n&No')

0 commit comments

Comments
 (0)