Skip to content

Commit af0ec40

Browse files
committed
Refile top level heading in capture file
1 parent d65dc79 commit af0ec40

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lua/telescope/_extensions/orgmode/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-- TODO: include headline.level and headline.is_archived() as part of the
22
-- public orgmode api
33
-- TODO: add highlight groups
4-
-- TODO: add action to refile/capture
54

65
return require("telescope").register_extension {
76
exports = {

lua/telescope/_extensions/orgmode/refile_heading.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ return function(opts)
1414
opts = opts or {}
1515

1616
-- TODO: this should be included in return from Files.get_current_file
17-
local has_capture, is_capture = pcall(vim.api.nvim_buf_get_var, 0, 'org_capture')
17+
local is_capture = vim.F.npcall(vim.api.nvim_buf_get_var, 0, 'org_capture')
1818

1919
local src_file = Files.get_current_file()
20-
local src_item = src_file:get_closest_headline()
20+
-- In capture, refile top level heading even if cursor closer to a subheading
21+
local src_item = is_capture and src_file:get_headlines()[1] or src_file:get_closest_headline()
2122
local src_lines = src_file:get_headline_lines(src_item)
2223

2324
local function refile(prompt_bufnr)
@@ -39,13 +40,11 @@ return function(opts)
3940
return false
4041
end
4142
--utils.echo_info(string.format('Wrote %s', dst_file.filename))
42-
--return true
4343
else
44-
--return Capture:_refile_to_end(dst_file.filename, src_lines, src_item)
4544
Capture:_refile_to_end(dst_file.filename, src_lines, src_item)
4645
end
4746

48-
if has_capture and is_capture then
47+
if is_capture then
4948
Capture:kill()
5049
end
5150
end

0 commit comments

Comments
 (0)