feat(buffer_previewer): pass file details in TelescopePreviewLoaded autocmd (#2429)
This commit is contained in:
23
README.md
23
README.md
@@ -400,8 +400,27 @@ to configure more filetypes, take a look at
|
||||
|
||||
If you want to configure the `vim_buffer_` previewer (e.g. you want the line to wrap), do this:
|
||||
|
||||
```vim
|
||||
autocmd User TelescopePreviewerLoaded setlocal wrap
|
||||
```lua
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "TelescopePreviewerLoaded",
|
||||
callback = function(args)
|
||||
if args.data.filetype ~= "help" then
|
||||
vim.bo.number = true
|
||||
elseif args.data.bufname:match("*.csv") then
|
||||
vim.bo.wrap = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
```
|
||||
|
||||
A data field is passed to the callback, which contains the filetype and the buffer name.
|
||||
|
||||
```lua
|
||||
{
|
||||
title: string, # preview window title
|
||||
filetype: string,
|
||||
bufname: string,
|
||||
}
|
||||
```
|
||||
|
||||
## Sorters
|
||||
|
||||
@@ -426,7 +426,14 @@ previewers.new_buffer_previewer = function(opts)
|
||||
|
||||
if vim.api.nvim_buf_is_valid(self.state.bufnr) then
|
||||
vim.api.nvim_buf_call(self.state.bufnr, function()
|
||||
vim.cmd "do User TelescopePreviewerLoaded"
|
||||
vim.api.nvim_exec_autocmds("User", {
|
||||
pattern = "TelescopePreviewerLoaded",
|
||||
data = {
|
||||
title = entry.preview_title,
|
||||
bufname = self.state.bufname,
|
||||
filetype = pfiletype.detect(self.state.bufname),
|
||||
},
|
||||
})
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user