feat: All buffer previewers are now async and more config options (#354)

Configure preview window with:
autocmd User TelescopePreviewerLoaded setlocal wrap
autocmd User TelescopePreviewerLoaded setlocal number

file_maker example: Use regex highlighting for certain filetype like `*min.js` because they slow
down things with treesitter highlighter. Just a snippet for tests. We will do an extension :)

local previewers = require('telescope.previewers')
local putils = require('telescope.previewers.utils')
local pfiletype = require('plenary.filetype')

local _bad = { '.*%.min%.js' }
local bad_files = function(filepath)
  for _, v in ipairs(_bad) do
    if filepath:match(v) then
      return true
    end
  end

  return false
end

local new_maker = function(filepath, bufnr, bufname, use_ft_detect, callback)
  if use_ft_detect == nil then use_ft_detect = true end

  if bad_files(filepath) then
    previewers.buffer_previewer_maker(filepath, bufnr, bufname, false, callback)
    local ft = pfiletype.detect(filepath)
    putils.regex_highlighter(bufnr, ft)
  else
    previewers.buffer_previewer_maker(filepath, bufnr, bufname, use_ft_detect, callback)
  end
end

require('telescope').setup {
  defaults = {
    buffer_previewer_maker = new_maker,
  }
}
This commit is contained in:
Simon Hauser
2020-12-29 21:05:59 +01:00
committed by GitHub
parent e555cd375f
commit 1d40ab5ccd
8 changed files with 296 additions and 148 deletions

View File

@@ -35,8 +35,10 @@ highlight default link TelescopeResultsStruct Struct
highlight default link TelescopeResultsVariable SpecialChar
highlight default link TelescopeResultsLineNr LineNr
highlight default link TelescopeResultsIdentifier Identifier
highlight default link TelescopeResultsNumber Number
highlight default link TelescopeResultsComment Comment
highlight default link TelescopeResultsSpecialComment SpecialComment
" This is like "<C-R>" in your terminal.
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)