Skip to content

Commit 587af41

Browse files
author
Fredrik Holmberg
committed
clean commit that adds support for prepend option in capture templates
1 parent b1952f7 commit 587af41

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lua/orgmode/capture/init.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,14 @@ function Capture:_refile_from_capture_buffer(opts)
167167
local target_line = -1
168168
local destination_file = opts.destination_file
169169
local destination_headline = opts.destination_headline
170+
local prepend = opts.template.prepend
170171

171172
if destination_headline then
172-
target_line = destination_headline:get_range().end_line
173+
if prepend then
174+
target_line = destination_headline:get_range().start_line
175+
else
176+
target_line = destination_headline:get_range().end_line
177+
end
173178
end
174179

175180
if opts.template.datetree then

lua/orgmode/capture/template/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ local expansions = {
8484
---@field target? string
8585
---@field datetree? OrgCaptureTemplateDatetree
8686
---@field headline? string|fun():string
87+
---@field prepend? boolean
8788
---@field regexp? string
8889
---@field properties? OrgCaptureTemplateProperties
8990
---@field subtemplates? table<string, OrgCaptureTemplate>
@@ -103,6 +104,7 @@ function Template:new(opts)
103104
vim.validate('target', opts.target, 'string', true)
104105
vim.validate('regexp', opts.regexp, 'string', true)
105106
vim.validate('headline', opts.headline, { 'string', 'function' }, true)
107+
vim.validate('prepend', opts.prepend, 'boolean', true)
106108
vim.validate('properties', opts.properties, 'table', true)
107109
vim.validate('subtemplates', opts.subtemplates, 'table', true)
108110
vim.validate('datetree', opts.datetree, { 'boolean', 'table' }, true)
@@ -113,6 +115,7 @@ function Template:new(opts)
113115
this.template = opts.template or ''
114116
this.target = opts.target or ''
115117
this.headline = opts.headline
118+
this.prepend = opts.prepend
116119
this.properties = TemplateProperties:new(opts.properties)
117120
this.datetree = opts.datetree
118121
this.regexp = opts.regexp

0 commit comments

Comments
 (0)