-
-
Notifications
You must be signed in to change notification settings - Fork 857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
telescope tries to show preview for binary files #223
Comments
Hey thanks for the report. Just to be clear this only happens when |
Yep, it worked: https://snipboard.io/S0qDzF.jpg Although maybe you don't want that |
That is actually a thing of |
Oh, cool. TIL. |
This is happening again, now when using the tree-sitter preview. Depending on the size of the binary file, Neovim completely freezes. |
Yes i know because i haven't found the time to write a good implementation. I thought we should rely on a platform independent binary detection in lua. A way to configure this would be (because you can override the filereading): 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,
}
} I wanted to add some other things to |
Would be helpful if telescope knew not to try to preview arbitrary binary files as it leaves a bunch of garbage characters on the screen. I've seen this functionality implemented by checking XDG MIME type, but unclear how general that solution can be on all platforms.
The text was updated successfully, but these errors were encountered: