summaryrefslogtreecommitdiff
path: root/scratch/simple_rg.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-07-15 17:53:30 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-07-15 17:53:30 -0400
commitc6f0142fc651dcbd2431630956d034c046293e7e (patch)
treea53ee03b29753ad718ea711afbb6bd3bf479882e /scratch/simple_rg.lua
parent053417dd92066e4e03b642f663bec577c0c6e59a (diff)
Get simple rg example to work
Diffstat (limited to 'scratch/simple_rg.lua')
-rw-r--r--scratch/simple_rg.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/scratch/simple_rg.lua b/scratch/simple_rg.lua
new file mode 100644
index 0000000..c6a8481
--- /dev/null
+++ b/scratch/simple_rg.lua
@@ -0,0 +1,41 @@
+local telescope = require('telescope')
+
+-- Uhh, finder should probably just GET the results
+-- and then update some table.
+-- When updating the table, we should call filter on those items
+-- and then only display ones that pass the filter
+local rg_finder = telescope.finders.new {
+ fn_command = function(prompt)
+ return string.format('rg --vimgrep %s', prompt)
+ end,
+
+ responsive = false
+}
+
+
+local p = telescope.pickers.new {
+ previewer = telescope.previewers.new(function(preview_win, preview_bufnr, results_bufnr, row)
+ assert(preview_bufnr)
+
+ local line = vim.api.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1]
+ local file_name = vim.split(line, ":")[1]
+
+ -- print(file_name)
+ -- vim.fn.termopen(
+ -- string.format("bat --color=always --style=grid %s"),
+ -- vim.fn.fnamemodify(file_name, ":p")
+ local bufnr = vim.fn.bufadd(file_name)
+ vim.fn.bufload(bufnr)
+
+ -- TODO: We should probably call something like this because we're not always getting highlight and all that stuff.
+ -- api.nvim_command('doautocmd filetypedetect BufRead ' .. vim.fn.fnameescape(filename))
+ vim.api.nvim_win_set_buf(preview_win, bufnr)
+ vim.api.nvim_win_set_option(preview_win, 'wrap', false)
+ vim.api.nvim_win_set_option(preview_win, 'winhl', 'Normal:Normal')
+ vim.api.nvim_win_set_option(preview_win, 'winblend', 20)
+ vim.api.nvim_win_set_option(preview_win, 'signcolumn', 'no')
+ vim.api.nvim_win_set_option(preview_win, 'foldlevel', 100)
+ end)
+}
+p:find(rg_finder)
+