diff options
Diffstat (limited to 'lua/telescope/previewers.lua')
| -rw-r--r-- | lua/telescope/previewers.lua | 45 |
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) |
