Skip to content

Commit 2e0d8e6

Browse files
authored
Merge pull request #7 from lyz-code/fix/deprecation-warnings
Fix/deprecation warnings
2 parents c66faa0 + d6d4a48 commit 2e0d8e6

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,27 @@ Refile heading from capture or current file under destination with `:Telescope o
1313

1414
[![asciicast](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN.svg)](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN)
1515

16-
## Setup
16+
## Installation
17+
### With lazyvim
18+
19+
```lua
20+
{
21+
"lyz-code/telescope-orgmode.nvim",
22+
event = "VeryLazy",
23+
dependencies = {
24+
"nvim-orgmode/orgmode",
25+
"nvim-telescope/telescope.nvim",
26+
},
27+
config = function()
28+
require("telescope").load_extension("orgmode")
29+
30+
vim.keymap.set("n", "<leader>r", require("telescope").extensions.orgmode.refile_heading)
31+
vim.keymap.set("n", "<leader>fh", require("telescope").extensions.orgmode.search_headings)
32+
end,
33+
}
34+
```
35+
36+
### Without lazyvim
1737

1838
You can setup the extension by doing:
1939

lua/telescope/_extensions/orgmode/refile_heading.lua

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,29 @@ local state = require("telescope.state")
88

99
local utils = require("telescope-orgmode.utils")
1010

11-
local orgmode = require("orgmode")
12-
local Files = require("orgmode.parser.files")
13-
local Capture = require("orgmode.capture")
14-
local Range = require("orgmode.parser.range")
11+
local api = require("orgmode.api")
1512

1613
return function(opts)
1714
opts = opts or {}
1815

19-
-- TODO: this should be included in return from Files.get_current_file
20-
local is_capture = vim.F.npcall(vim.api.nvim_buf_get_var, 0, "org_capture")
21-
22-
local src_file = Files.get_current_file()
23-
-- In capture, refile top level heading even if cursor closer to a subheading
24-
local src_item = is_capture and src_file:get_headlines()[1] or src_file:get_closest_headline()
25-
local src_lines = src_file:get_headline_lines(src_item)
16+
local closest_headline = api.current():get_closest_headline()
2617

2718
local function refile(prompt_bufnr)
2819
local entry = action_state.get_selected_entry()
2920
actions.close(prompt_bufnr)
3021

31-
local dst_file = entry.value.file
32-
local dst_headline = entry.value.headline
33-
if dst_headline then
34-
-- NOTE: adapted from Capture:refile_to_headline
35-
local is_same_file = dst_file.filename == src_item.root.filename
36-
src_lines = Capture:_adapt_headline_level(src_item, dst_headline.level, is_same_file)
37-
local refile_opts = {
38-
file = dst_file.filename,
39-
lines = src_lines,
40-
item = src_item,
41-
range = Range.from_line(dst_headline.position.end_line),
42-
headline = dst_headline.title,
43-
}
44-
local refiled = Capture:_refile_to(refile_opts)
45-
if not refiled then
46-
return false
47-
end
48-
else
49-
Capture:_refile_to_end(dst_file.filename, src_lines, src_item)
50-
end
22+
-- Refile to the file by default
23+
local destination = entry.value.file
5124

52-
if is_capture then
53-
orgmode.action("capture.kill")
25+
-- Refile to a specific heading if is set
26+
if entry.value.headline then
27+
destination = entry.value.headline
5428
end
29+
30+
return api.refile({
31+
source = closest_headline,
32+
destination = destination,
33+
})
5534
end
5635

5736
local function gen_depth_toggle(opts, prompt_bufnr)

0 commit comments

Comments
 (0)