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
This commit is contained in:
Senghan Bright
2020-12-02 00:27:54 +01:00
committed by GitHub
parent b1d436ce92
commit 8546fdf610
4 changed files with 174 additions and 0 deletions

View File

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