Skip to content

Commit

Permalink
feat(capture): Add on_pre_refile and on_post_refile
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Mar 31, 2024
1 parent 96a30ff commit 050ed17
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ local Datetree = require('orgmode.capture.template.datetree')
---@field templates OrgCaptureTemplates
---@field closing_note OrgCaptureWindow
---@field files OrgFiles
---@field on_close OrgOnCaptureClose
---@field on_pre_refile OrgOnCaptureClose
---@field on_post_refile OrgOnCaptureClose
---@field _window OrgCaptureWindow
local Capture = {}
Capture.__index = Capture

---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates, on_close?: OrgOnCaptureClose }
---@param opts { files: OrgFiles, templates?: OrgCaptureTemplates, on_pre_refile?: OrgOnCaptureClose, on_post_refile?: OrgOnCaptureClose }
function Capture:new(opts)
local this = setmetatable({}, self)
this.files = opts.files
this.on_close = opts.on_close
this.on_pre_refile = opts.on_pre_refile
this.on_post_refile = opts.on_post_refile
this.templates = opts.templates or Templates:new()
this.closing_note = this:_setup_closing_note()
return this
Expand Down Expand Up @@ -150,6 +152,9 @@ end
---@private
---@param opts OrgProcessCaptureOpts
function Capture:_refile_from_capture_buffer(opts)
if self.on_pre_refile then
self.on_pre_refile(self, opts)
end
local target_level = 0
local target_line = -1
local destination_file = opts.destination_file
Expand Down Expand Up @@ -192,8 +197,8 @@ function Capture:_refile_from_capture_buffer(opts)
end)
:wait()

if self.on_close then
self.on_close(self, opts)
if self.on_post_refile then
self.on_post_refile(self, opts)
end
utils.echo_info(('Wrote %s'):format(destination_file.filename))
self:kill()
Expand Down

0 comments on commit 050ed17

Please sign in to comment.