Skip to content

Commit f1f3ae0

Browse files
committed
Add refile_to_headline
1 parent 2fdc13e commit f1f3ae0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lua/orgmode/capture/init.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function Capture:refile(confirm)
5656
local template = vim.api.nvim_buf_get_var(0, 'org_template') or {}
5757
local file = vim.fn.fnamemodify(template.target or config.org_default_notes_file, ':p')
5858
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
59+
local headline_title = template.headline
5960
if confirm and is_modified then
6061
local choice = vim.fn.confirm(string.format('Do you want to refile this to %s?', file), '&Yes\n&No')
6162
vim.cmd([[redraw!]])
@@ -65,7 +66,12 @@ function Capture:refile(confirm)
6566
end
6667
vim.defer_fn(function()
6768
-- TODO: Parse refile content as org file and update refile destination to point to headline or root
69+
if headline_title then
70+
self:refile_to_headline(file, lines, nil, headline_title)
71+
return
72+
end
6873
self:_refile_to_end(file, lines)
74+
6975
end, 0)
7076
vim.cmd([[autocmd! OrgCapture BufWipeout <buffer>]])
7177
vim.cmd([[silent! wq]])
@@ -133,13 +139,19 @@ function Capture:_refile_content_with_fallback(lines, fallback_file, item)
133139
end
134140

135141
local destination_file = valid_destinations[destination[1]]
136-
137142
if not destination[2] or destination[2] == '' then
138143
return self:_refile_to_end(destination_file, lines, item)
139144
end
145+
return self:refile_to_headline(destination_file, lines, item, destination[2]);
146+
end
140147

148+
function Capture:refile_to_headline(destination_file, lines, item, headline_title)
141149
local agenda_file = Files.get(destination_file)
142-
local headline = agenda_file:find_headline_by_title(destination[2])
150+
local headline
151+
if headline_title then
152+
headline = agenda_file:find_headline_by_title(headline_title)
153+
end
154+
143155
if not headline then
144156
return self._refile_to_end(destination_file, lines, item)
145157
end

0 commit comments

Comments
 (0)