generated from nvimdev/nvim-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a34ae8
commit 4fcb508
Showing
8 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
drash-drash.nvim drash.txt /*drash-drash.nvim* | ||
drash-drash.nvim-development drash.txt /*drash-drash.nvim-development* | ||
drash-links drash.txt /*drash-links* | ||
drash-table-of-contents drash.txt /*drash-table-of-contents* | ||
drash.txt drash.txt /*drash.txt* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
local sefaria = require('drash.sefaria') | ||
local telescope = require('telescope') | ||
_ = sefaria | ||
local M = {} | ||
|
||
M.setup = function(spec, opts) | ||
_ = spec | ||
_ = opts | ||
|
||
vim.api.nvim_create_user_command('PostSearch', function(opt) | ||
local query = opt.args | ||
local data = sefaria.post_search(query) | ||
|
||
if data == nil then | ||
vim.notify('failed', vim.log.levels.ERROR, {}) | ||
return | ||
end | ||
|
||
vim.notify(vim.fn.string(data.hits.hits or ''), vim.log.levels.DEBUG, {}) | ||
end, { nargs = '?' }) | ||
|
||
telescope.load_extension('drash') | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local M = {} | ||
|
||
M.url_encode = function(str) | ||
str = string.gsub(str, '([^%w%.%- ])', function(c) | ||
return string.format('%%%02X', string.byte(c)) | ||
end) | ||
str = string.gsub(str, '%s+', '%%20') | ||
return str | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
local telescope = require('telescope') | ||
|
||
local pickers = require('telescope.pickers') | ||
local finders = require('telescope.finders') | ||
local actions = require('telescope.actions') | ||
local action_state = require('telescope.actions.state') | ||
local previewers = require('telescope.previewers') | ||
local make_entry = require('telescope.make_entry') | ||
local conf = require('telescope.config').values | ||
|
||
local M = {} | ||
|
||
M.search_sefaria = function(opts) | ||
opts = opts or { prompt = '' } | ||
opts.entry_maker = make_entry.gen_from_string(opts) | ||
print(opts.prompt) | ||
|
||
local searcher = function(prompt) | ||
if not prompt or prompt == '' then | ||
return {} | ||
end | ||
|
||
local search_list = require('drash.sefaria').post_search(prompt) | ||
if search_list == nil then | ||
return {} | ||
end | ||
|
||
local hits = search_list.hits.hits | ||
for i, hit in ipairs(search_list.hits.hits) do | ||
hits[i] = hit._id | ||
end | ||
|
||
return hits | ||
end | ||
|
||
pickers | ||
.new(opts, { | ||
prompt_title = 'Search Sefaria', | ||
finder = finders.new_table({ | ||
results = searcher(opts.prompt), | ||
entry_maker = opts.entry_maker, | ||
}), | ||
attach_mappings = function(prompt_bufnr) | ||
actions.select_default:replace(function() | ||
local selected = action_state.get_selected_entry() | ||
print(vim.inspect(selected)) | ||
actions.close(prompt_bufnr) | ||
if selected == nil then | ||
return | ||
end | ||
|
||
local response = require('drash.sefaria').get_text(selected[1]) | ||
local text = {} | ||
if response == nil then | ||
text = { 'Error fetching text' } | ||
else | ||
text = require('telescope.utils').flatten({ response.versions[1].text }) | ||
end | ||
local bufnr = vim.api.nvim_create_buf(true, true) | ||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, text) | ||
vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr }) | ||
vim.api.nvim_open_win(bufnr, true, { | ||
split = 'right', | ||
win = 0, | ||
}) | ||
end) | ||
return true | ||
end, | ||
previewer = previewers.new_buffer_previewer({ | ||
define_preview = function(self, entry) | ||
local response = require('drash.sefaria').get_text(entry[1]) | ||
local text = {} | ||
if response == nil then | ||
text = { 'Error fetching text' } | ||
else | ||
text = require('telescope.utils').flatten({ response.versions[1].text }) | ||
end | ||
self.state.bufnr = self.state.bufnr or vim.api.nvim_get_current_buf() | ||
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, text) | ||
end, | ||
}), | ||
sorter = conf.generic_sorter(opts), | ||
}) | ||
:find() | ||
end | ||
|
||
return telescope.register_extension({ | ||
setup = function() | ||
vim.api.nvim_create_user_command('SearchSefaria', function(opts) | ||
M.search_sefaria({ prompt = opts.args }) | ||
end, { nargs = '?' }) | ||
end, | ||
exports = { | ||
search_sefaria = M.search_sefaria, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters