Skip to content

Commit 39cf680

Browse files
committed
Add ability to run function after save
This adds the ability to run a function after a capture. This is configured with the `after_save` key. The function takes in the buffer number for the capture buffer (not the target file/buffer) and the data that is passed into the autosave command for the capture.
1 parent 163cd4c commit 39cf680

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lua/neorg/modules/external/capture/module.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ module.private = {
8686
path = item.path,
8787
query = item.query,
8888
datetree = item.datetree,
89+
after_save = item.after_save,
8990
}
9091
end
9192

9293
local item_is_enabled = function(item)
9394
return item.enabled == nil or type(item.enabled) == "function" and item.enabled(bufnr) or item.enabled
9495
end
9596

96-
for _, item in ipairs(conf.templates) do
97+
for _, item in ipairs(conf.templates or {}) do
9798
if item_is_enabled(item) then
9899
if item.name and item.name ~= "" then
99100
table.insert(items, item.description)
@@ -317,6 +318,9 @@ module.on_event = function(event)
317318
calling_bufnr = calling_bufnr,
318319
on_save = function(bufnr, passed_data)
319320
module.private.on_save(bufnr, passed_data)
321+
if type(data[idx].after_save) == "function" then
322+
data[idx].after_save(bufnr, passed_data)
323+
end
320324
end,
321325
},
322326
})

0 commit comments

Comments
 (0)