From 587af414c4fa1b4487e7a2b449b6880669888171 Mon Sep 17 00:00:00 2001 From: Fredrik Holmberg Date: Wed, 10 Jun 2026 19:38:48 +0200 Subject: [PATCH 1/4] clean commit that adds support for prepend option in capture templates --- lua/orgmode/capture/init.lua | 7 ++++++- lua/orgmode/capture/template/init.lua | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/orgmode/capture/init.lua b/lua/orgmode/capture/init.lua index 9f89c837d..fd5681f46 100644 --- a/lua/orgmode/capture/init.lua +++ b/lua/orgmode/capture/init.lua @@ -167,9 +167,14 @@ function Capture:_refile_from_capture_buffer(opts) local target_line = -1 local destination_file = opts.destination_file local destination_headline = opts.destination_headline + local prepend = opts.template.prepend if destination_headline then - target_line = destination_headline:get_range().end_line + if prepend then + target_line = destination_headline:get_range().start_line + else + target_line = destination_headline:get_range().end_line + end end if opts.template.datetree then diff --git a/lua/orgmode/capture/template/init.lua b/lua/orgmode/capture/template/init.lua index 5bf95b3fd..52fe13255 100644 --- a/lua/orgmode/capture/template/init.lua +++ b/lua/orgmode/capture/template/init.lua @@ -84,6 +84,7 @@ local expansions = { ---@field target? string ---@field datetree? OrgCaptureTemplateDatetree ---@field headline? string|fun():string +---@field prepend? boolean ---@field regexp? string ---@field properties? OrgCaptureTemplateProperties ---@field subtemplates? table @@ -103,6 +104,7 @@ function Template:new(opts) vim.validate('target', opts.target, 'string', true) vim.validate('regexp', opts.regexp, 'string', true) vim.validate('headline', opts.headline, { 'string', 'function' }, true) + vim.validate('prepend', opts.prepend, 'boolean', true) vim.validate('properties', opts.properties, 'table', true) vim.validate('subtemplates', opts.subtemplates, 'table', true) vim.validate('datetree', opts.datetree, { 'boolean', 'table' }, true) @@ -113,6 +115,7 @@ function Template:new(opts) this.template = opts.template or '' this.target = opts.target or '' this.headline = opts.headline + this.prepend = opts.prepend this.properties = TemplateProperties:new(opts.properties) this.datetree = opts.datetree this.regexp = opts.regexp From 1aadc749cfbe17edee309b6981b69b4a6a5d5992 Mon Sep 17 00:00:00 2001 From: Fredrik Holmberg Date: Sun, 14 Jun 2026 13:56:50 +0200 Subject: [PATCH 2/4] Added description of the field in orgmode.txt section about capture templates --- doc/orgmode.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/orgmode.txt b/doc/orgmode.txt index c206fb498..0f9f3091a 100644 --- a/doc/orgmode.txt +++ b/doc/orgmode.txt @@ -979,6 +979,9 @@ Templates have the following fields: capture content will be added. If a function is provided, it will be called during refile and must return the headline title as string. If no headline is specified, the content will be appended to the end of the file +- `prepend` (`boolean`) - captured items are by default added as the last item at + the specfied target, setting this property places captured items as the first item + at the target - `datetree (boolean | { time_prompt?: boolean, reversed?: boolean, tree_type: 'day' | 'month' | 'week' | 'custom' })` Create a date tree with current day in the target file and put the capture content there. - `true` - Create ascending datetree (newer dates go to end) with the current date From 75d2470bd5edd2a65652fd3909edd0f214983fe2 Mon Sep 17 00:00:00 2001 From: Fredrik Holmberg Date: Sun, 14 Jun 2026 14:18:18 +0200 Subject: [PATCH 3/4] Made addition to org-docs template-section --- docs/configuration.org | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/configuration.org b/docs/configuration.org index 63f0f9723..982266a72 100644 --- a/docs/configuration.org +++ b/docs/configuration.org @@ -920,6 +920,9 @@ Templates have the following fields: capture content will be added. If a function is provided, it will be called during refile and must return the headline title as string. If no headline is specified, the content will be appended to the end of the file +- =prepend= (=boolean=) --- captured items are by default added as the last item at + the specfied target, setting this field places captured items as the first item + at the target - =datetree (boolean | { time_prompt?: boolean, reversed?: boolean, tree_type: 'day' | 'month' | 'week' | 'custom' })= Create a [[https://orgmode.org/manual/Template-elements.html#FOOT84][date tree]] with current day in the target file and put the capture content there. - =true= - Create ascending datetree (newer dates go to end) with the current date From ab195e7b6af5c7ef64632cf13166628dfc427062 Mon Sep 17 00:00:00 2001 From: Fredrik Holmberg Date: Sun, 14 Jun 2026 14:23:28 +0200 Subject: [PATCH 4/4] Added documentation for the feature --- doc/orgmode.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/orgmode.txt b/doc/orgmode.txt index 0f9f3091a..228b27ddc 100644 --- a/doc/orgmode.txt +++ b/doc/orgmode.txt @@ -980,7 +980,7 @@ Templates have the following fields: refile and must return the headline title as string. If no headline is specified, the content will be appended to the end of the file - `prepend` (`boolean`) - captured items are by default added as the last item at - the specfied target, setting this property places captured items as the first item + the specfied target, setting this field places captured items as the first item at the target - `datetree (boolean | { time_prompt?: boolean, reversed?: boolean, tree_type: 'day' | 'month' | 'week' | 'custom' })` Create a date tree with current day in the target file and put the capture content there.