summaryrefslogtreecommitdiff
path: root/lua/telescope/previewers.lua
diff options
context:
space:
mode:
authorSenghan Bright <senghan.bright@deltaprojects.com>2020-12-02 00:27:54 +0100
committerGitHub <noreply@github.com>2020-12-02 00:27:54 +0100
commit8546fdf610584c367f0f1e105aedec370d71bf54 (patch)
tree6d57d1fd4882655b64bb26b363f4667ce56458b9 /lua/telescope/previewers.lua
parentb1d436ce9247b13b83590652d905e45749a0bdd5 (diff)
new builtin - autocommands (#302)
* feat: new builtin - Autocommands finder * fix: remove decorators to avoid confusion. * make preview split same hl-group as border * use highlight instead of marker character for preview selection hl
Diffstat (limited to 'lua/telescope/previewers.lua')
-rw-r--r--lua/telescope/previewers.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index 81664ec..9c63836 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -770,6 +770,51 @@ previewers.man = defaulter(function(_)
}
end)
+previewers.autocommands = defaulter(function(_)
+return previewers.new_buffer_previewer {
+ setup = function()
+ return {}
+ end,
+
+ teardown = function(self)
+ if self.state and self.state.hl_id then
+ pcall(vim.fn.matchdelete, self.state.hl_id, self.state.hl_win)
+ self.state.hl_id = nil
+ end
+ end,
+
+ preview_fn = function(self, entry, status)
+ local results = vim.tbl_filter(
+ function (x) return x.group == entry.group end,
+ status.picker.finder.results
+ )
+ local display = {}
+ table.insert(display, string.format(" augroup: %s - [ %d entries ]", entry.group, #results))
+ -- TODO: calculate banner width/string in setup()
+ -- TODO: get column characters to be the same HL group as border
+ table.insert(display, string.rep("─", vim.fn.getwininfo(status.preview_win)[1].width))
+
+ local selected_row
+ for idx, item in ipairs(results) do
+ if item == entry then
+ selected_row = idx
+ end
+ table.insert(display,
+ string.format(" %-14sā–%-08s %s", item.event, item.ft_pattern, item.command)
+ )
+ end
+
+ with_preview_window(status, nil, function()
+ -- TODO: set filetype in setup()
+ vim.api.nvim_buf_set_option(status.preview_bufnr, "filetype", "vim")
+ vim.api.nvim_buf_set_lines(status.preview_bufnr, 0, -1, false, display)
+ vim.api.nvim_buf_add_highlight(status.preview_bufnr, 0, "TelescopeBorder", 1, 0, -1)
+ vim.api.nvim_buf_add_highlight(status.preview_bufnr, 0, "TelescopeSelection", selected_row + 1, 0, -1)
+ end)
+ end,
+}
+end, {})
+
previewers.display_content = defaulter(function(_)
return previewers.new_buffer_previewer {
preview_fn = function(self, entry, status)