From 783508bf2578220a465abbff21a3d9012ede5050 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 3 Nov 2021 05:46:00 +0100 Subject: [PATCH] Feat: telescope ignore pdf --- nvim/.config/nvim/lua/config/telescope.lua | 35 ++++++++++++++++++++++ nvim/.config/nvim/lua/mappings.lua | 6 ---- nvim/.config/nvim/lua/plugins.lua | 1 + 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 nvim/.config/nvim/lua/config/telescope.lua diff --git a/nvim/.config/nvim/lua/config/telescope.lua b/nvim/.config/nvim/lua/config/telescope.lua new file mode 100644 index 0000000..3bd1b11 --- /dev/null +++ b/nvim/.config/nvim/lua/config/telescope.lua @@ -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', 'e', 'Telescope find_files', {}) +map('n', 'g', 'Telescope live_grep', {}) +map('n', 'b', 'Telescope buffers', {}) +map('n', 'h', 'Telescope help_tags', {}) + diff --git a/nvim/.config/nvim/lua/mappings.lua b/nvim/.config/nvim/lua/mappings.lua index a482944..474a0ea 100644 --- a/nvim/.config/nvim/lua/mappings.lua +++ b/nvim/.config/nvim/lua/mappings.lua @@ -15,9 +15,3 @@ map('v', '>', '>gv', {}) -- Automatically spell check last error in insert mode map('i', '', 'u[s1z=`]au', default_opts) --- Find files using Telescope command-line sugar. -map('n', 'e', 'Telescope find_files', {}) -map('n', 'g', 'Telescope live_grep', {}) -map('n', 'b', 'Telescope buffers', {}) -map('n', 'h', 'Telescope help_tags', {}) - diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index dfcf2be..4a4a732 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -42,6 +42,7 @@ return require('packer').startup(function() use 'nvim-lua/popup.nvim' use { 'nvim-telescope/telescope.nvim', + config = [[require('config.telescope')]], requires = { {'nvim-lua/plenary.nvim'} } }