Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/orgmode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 <https://orgmode.org/manual/Template-elements.html#FOOT84> 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
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lua/orgmode/capture/template/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, OrgCaptureTemplate>
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading