Skip to content

Commit 050ed17

Browse files
feat(capture): Add on_pre_refile and on_post_refile
1 parent 96a30ff commit 050ed17

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lua/orgmode/capture/init.lua

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ local Datetree = require('orgmode.capture.template.datetree')
1414
---@field templates OrgCaptureTemplates
1515
---@field closing_note OrgCaptureWindow
1616
---@field files OrgFiles
17-
---@field on_close OrgOnCaptureClose
17+
---@field on_pre_refile OrgOnCaptureClose
18+
---@field on_post_refile OrgOnCaptureClose
1819
---@field _window OrgCaptureWindow
1920
local Capture = {}
2021
Capture.__index = Capture
2122

22-
---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates, on_close?: OrgOnCaptureClose }
23+
---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates, on_pre_refile?: OrgOnCaptureClose, on_post_refile?: OrgOnCaptureClose }
2324
function Capture:new(opts)
2425
local this = setmetatable({}, self)
2526
this.files = opts.files
26-
this.on_close = opts.on_close
27+
this.on_pre_refile = opts.on_pre_refile
28+
this.on_post_refile = opts.on_post_refile
2729
this.templates = opts.templates or Templates:new()
2830
this.closing_note = this:_setup_closing_note()
2931
return this
@@ -150,6 +152,9 @@ end
150152
---@private
151153
---@param opts OrgProcessCaptureOpts
152154
function Capture:_refile_from_capture_buffer(opts)
155+
if self.on_pre_refile then
156+
self.on_pre_refile(self, opts)
157+
end
153158
local target_level = 0
154159
local target_line = -1
155160
local destination_file = opts.destination_file
@@ -192,8 +197,8 @@ function Capture:_refile_from_capture_buffer(opts)
192197
end)
193198
:wait()
194199

195-
if self.on_close then
196-
self.on_close(self, opts)
200+
if self.on_post_refile then
201+
self.on_post_refile(self, opts)
197202
end
198203
utils.echo_info(('Wrote %s'):format(destination_file.filename))
199204
self:kill()

0 commit comments

Comments
 (0)