Merge pull request #7 from lyz-code/fix/deprecation-warnings

Fix/deprecation warnings
This commit is contained in:
Lyz 2024-02-15 09:20:03 +00:00 committed by GitHub
commit 2e0d8e6703
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 34 deletions

View File

@ -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)
## 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:

View File

@ -8,50 +8,29 @@ local state = require("telescope.state")
local utils = require("telescope-orgmode.utils")
local orgmode = require("orgmode")
local Files = require("orgmode.parser.files")
local Capture = require("orgmode.capture")
local Range = require("orgmode.parser.range")
local api = require("orgmode.api")
return function(opts)
opts = opts or {}
-- TODO: this should be included in return from Files.get_current_file
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 closest_headline = api.current():get_closest_headline()
local function refile(prompt_bufnr)
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
local dst_file = entry.value.file
local dst_headline = entry.value.headline
if dst_headline then
-- NOTE: adapted from Capture:refile_to_headline
local is_same_file = dst_file.filename == src_item.root.filename
src_lines = Capture:_adapt_headline_level(src_item, dst_headline.level, is_same_file)
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)
-- Refile to the file by default
local destination = entry.value.file
-- Refile to a specific heading if is set
if entry.value.headline then
destination = entry.value.headline
end
if is_capture then
orgmode.action("capture.kill")
end
return api.refile({
source = closest_headline,
destination = destination,
})
end
local function gen_depth_toggle(opts, prompt_bufnr)