From d65dc793552da598973c9657c3abc5d93cfc927b Mon Sep 17 00:00:00 2001 From: Joao Sa Date: Tue, 1 Nov 2022 00:31:43 +0100 Subject: [PATCH] Implement refile from org capture --- lua/telescope/_extensions/orgmode/init.lua | 7 ------- lua/telescope/_extensions/orgmode/refile_heading.lua | 12 ++++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/telescope/_extensions/orgmode/init.lua b/lua/telescope/_extensions/orgmode/init.lua index eb3c11e..6ce0f46 100644 --- a/lua/telescope/_extensions/orgmode/init.lua +++ b/lua/telescope/_extensions/orgmode/init.lua @@ -1,10 +1,3 @@ -local orgmode = require('orgmode.api') - -local pickers = require("telescope.pickers") -local finders = require("telescope.finders") -local entry_display = require("telescope.pickers.entry_display") -local conf = require("telescope.config").values - -- TODO: include headline.level and headline.is_archived() as part of the -- public orgmode api -- TODO: add highlight groups diff --git a/lua/telescope/_extensions/orgmode/refile_heading.lua b/lua/telescope/_extensions/orgmode/refile_heading.lua index c62426d..6b40c71 100644 --- a/lua/telescope/_extensions/orgmode/refile_heading.lua +++ b/lua/telescope/_extensions/orgmode/refile_heading.lua @@ -13,6 +13,9 @@ local Capture = require('orgmode.capture') return function(opts) opts = opts or {} + -- TODO: this should be included in return from Files.get_current_file + local has_capture, is_capture = pcall(vim.api.nvim_buf_get_var, 0, 'org_capture') + local src_file = Files.get_current_file() local src_item = src_file:get_closest_headline() local src_lines = src_file:get_headline_lines(src_item) @@ -36,9 +39,14 @@ return function(opts) return false end --utils.echo_info(string.format('Wrote %s', dst_file.filename)) - return true + --return true else - return Capture:_refile_to_end(dst_file.filename, src_lines, src_item) + --return Capture:_refile_to_end(dst_file.filename, src_lines, src_item) + Capture:_refile_to_end(dst_file.filename, src_lines, src_item) + end + + if has_capture and is_capture then + Capture:kill() end end