Skip to content

Commit 35504ab

Browse files
Merge pull request #202 from joshpetit/master
2 parents 6843e37 + 50bd98a commit 35504ab

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lua/orgmode/capture/init.lua

Lines changed: 13 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,6 +66,10 @@ 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)
6974
end, 0)
7075
vim.cmd([[autocmd! OrgCapture BufWipeout <buffer>]])
@@ -133,13 +138,19 @@ function Capture:_refile_content_with_fallback(lines, fallback_file, item)
133138
end
134139

135140
local destination_file = valid_destinations[destination[1]]
136-
137141
if not destination[2] or destination[2] == '' then
138142
return self:_refile_to_end(destination_file, lines, item)
139143
end
144+
return self:refile_to_headline(destination_file, lines, item, destination[2])
145+
end
140146

147+
function Capture:refile_to_headline(destination_file, lines, item, headline_title)
141148
local agenda_file = Files.get(destination_file)
142-
local headline = agenda_file:find_headline_by_title(destination[2])
149+
local headline
150+
if headline_title then
151+
headline = agenda_file:find_headline_by_title(headline_title)
152+
end
153+
143154
if not headline then
144155
return self._refile_to_end(destination_file, lines, item)
145156
end

0 commit comments

Comments
 (0)