Merge pull request #7 from lyz-code/fix/deprecation-warnings
Fix/deprecation warnings
This commit is contained in:
commit
2e0d8e6703
22
README.md
22
README.md
@ -13,7 +13,27 @@ Refile heading from capture or current file under destination with `:Telescope o
|
|||||||
|
|
||||||
[![asciicast](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN.svg)](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN)
|
[![asciicast](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN.svg)](https://asciinema.org/a/1X4oG6s5jQZrJJI3DfEzJU3wN)
|
||||||
|
|
||||||
## Setup
|
## Installation
|
||||||
|
### With lazyvim
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"lyz-code/telescope-orgmode.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
dependencies = {
|
||||||
|
"nvim-orgmode/orgmode",
|
||||||
|
"nvim-telescope/telescope.nvim",
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
require("telescope").load_extension("orgmode")
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>r", require("telescope").extensions.orgmode.refile_heading)
|
||||||
|
vim.keymap.set("n", "<leader>fh", require("telescope").extensions.orgmode.search_headings)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Without lazyvim
|
||||||
|
|
||||||
You can setup the extension by doing:
|
You can setup the extension by doing:
|
||||||
|
|
||||||
|
@ -8,50 +8,29 @@ local state = require("telescope.state")
|
|||||||
|
|
||||||
local utils = require("telescope-orgmode.utils")
|
local utils = require("telescope-orgmode.utils")
|
||||||
|
|
||||||
local orgmode = require("orgmode")
|
local api = require("orgmode.api")
|
||||||
local Files = require("orgmode.parser.files")
|
|
||||||
local Capture = require("orgmode.capture")
|
|
||||||
local Range = require("orgmode.parser.range")
|
|
||||||
|
|
||||||
return function(opts)
|
return function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
-- TODO: this should be included in return from Files.get_current_file
|
local closest_headline = api.current():get_closest_headline()
|
||||||
local is_capture = vim.F.npcall(vim.api.nvim_buf_get_var, 0, "org_capture")
|
|
||||||
|
|
||||||
local src_file = Files.get_current_file()
|
|
||||||
-- In capture, refile top level heading even if cursor closer to a subheading
|
|
||||||
local src_item = is_capture and src_file:get_headlines()[1] or src_file:get_closest_headline()
|
|
||||||
local src_lines = src_file:get_headline_lines(src_item)
|
|
||||||
|
|
||||||
local function refile(prompt_bufnr)
|
local function refile(prompt_bufnr)
|
||||||
local entry = action_state.get_selected_entry()
|
local entry = action_state.get_selected_entry()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
local dst_file = entry.value.file
|
-- Refile to the file by default
|
||||||
local dst_headline = entry.value.headline
|
local destination = entry.value.file
|
||||||
if dst_headline then
|
|
||||||
-- NOTE: adapted from Capture:refile_to_headline
|
-- Refile to a specific heading if is set
|
||||||
local is_same_file = dst_file.filename == src_item.root.filename
|
if entry.value.headline then
|
||||||
src_lines = Capture:_adapt_headline_level(src_item, dst_headline.level, is_same_file)
|
destination = entry.value.headline
|
||||||
local refile_opts = {
|
|
||||||
file = dst_file.filename,
|
|
||||||
lines = src_lines,
|
|
||||||
item = src_item,
|
|
||||||
range = Range.from_line(dst_headline.position.end_line),
|
|
||||||
headline = dst_headline.title,
|
|
||||||
}
|
|
||||||
local refiled = Capture:_refile_to(refile_opts)
|
|
||||||
if not refiled then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Capture:_refile_to_end(dst_file.filename, src_lines, src_item)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_capture then
|
return api.refile({
|
||||||
orgmode.action("capture.kill")
|
source = closest_headline,
|
||||||
end
|
destination = destination,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gen_depth_toggle(opts, prompt_bufnr)
|
local function gen_depth_toggle(opts, prompt_bufnr)
|
||||||
|
Loading…
Reference in New Issue
Block a user