Feat: telescope ignore pdf

This commit is contained in:
Bertrand Benjamin 2021-11-03 05:46:00 +01:00
parent 829bf55d82
commit 783508bf25
3 changed files with 36 additions and 6 deletions

View File

@ -0,0 +1,35 @@
local previewers = require('telescope.previewers')
local Job = require('plenary.job')
local new_maker = function(filepath, bufnr, opts)
filepath = vim.fn.expand(filepath)
Job:new({
command = 'file',
args = { '--mime-type', '-b', filepath },
on_exit = function(j)
local mime_type = vim.split(j:result()[1], '/')[1]
if mime_type == "text" then
previewers.buffer_previewer_maker(filepath, bufnr, opts)
else
-- maybe we want to write something to the buffer here
vim.schedule(function()
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { 'BINARY' })
end)
end
end
}):sync()
end
require('telescope').setup {
defaults = {
buffer_previewer_maker = new_maker,
file_ignore_patterns = {"**/*.pdf"},
}
}
local map = vim.api.nvim_set_keymap
-- Find files using Telescope command-line sugar.
map('n', '<leader>e', '<cmd>Telescope find_files<cr>', {})
map('n', '<leader>g', '<cmd>Telescope live_grep<cr>', {})
map('n', '<leader>b', '<cmd>Telescope buffers<cr>', {})
map('n', '<leader>h', '<cmd>Telescope help_tags<cr>', {})

View File

@ -15,9 +15,3 @@ map('v', '>', '>gv', {})
-- Automatically spell check last error in insert mode -- Automatically spell check last error in insert mode
map('i', '<c-f>', '<c-g>u<Esc>[s1z=`]a<c-g>u', default_opts) map('i', '<c-f>', '<c-g>u<Esc>[s1z=`]a<c-g>u', default_opts)
-- Find files using Telescope command-line sugar.
map('n', '<leader>e', '<cmd>Telescope find_files<cr>', {})
map('n', '<leader>g', '<cmd>Telescope live_grep<cr>', {})
map('n', '<leader>b', '<cmd>Telescope buffers<cr>', {})
map('n', '<leader>h', '<cmd>Telescope help_tags<cr>', {})

View File

@ -42,6 +42,7 @@ return require('packer').startup(function()
use 'nvim-lua/popup.nvim' use 'nvim-lua/popup.nvim'
use { use {
'nvim-telescope/telescope.nvim', 'nvim-telescope/telescope.nvim',
config = [[require('config.telescope')]],
requires = { {'nvim-lua/plenary.nvim'} } requires = { {'nvim-lua/plenary.nvim'} }
} }