lines|blines|grep_curbuf|lgrep_curbuf: hide filename by default

fix help buffer syntax highlighting in blines|buffer preview
main
bhagwan 3 years ago
parent 253b9413eb
commit 1d6ea8d381

@ -504,11 +504,36 @@ require'fzf-lua'.setup {
["ctrl-x"] = actions.buf_del, ["ctrl-x"] = actions.buf_del,
} }
}, },
lines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'Lines ',
show_unlisted = false, -- exclude 'help' buffers
no_term_buffers = true, -- exclude 'term' buffers
fzf_opts = {
-- do not include bufnr in fuzzy matching
-- tiebreak by line no.
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,
["ctrl-v"] = actions.buf_vsplit,
["ctrl-t"] = actions.buf_tabedit,
}
},
blines = { blines = {
previewer = "builtin", -- set to 'false' to disable previewer = "builtin", -- set to 'false' to disable
prompt = 'BLines ', prompt = 'BLines ',
show_unlisted = true, -- include 'help' buffers show_unlisted = true, -- include 'help' buffers
no_term_buffers = false, -- include 'term' buffers no_term_buffers = false, -- include 'term' buffers
fzf_opts = {
-- hide filename, tiebreak by line no.
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = { actions = {
["default"] = actions.buf_edit, ["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split, ["ctrl-s"] = actions.buf_split,

@ -538,11 +538,36 @@ Consult the list below for available settings:
["ctrl-x"] = actions.buf_del, ["ctrl-x"] = actions.buf_del,
} }
}, },
lines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'Lines ',
show_unlisted = false, -- exclude 'help' buffers
no_term_buffers = true, -- exclude 'term' buffers
fzf_opts = {
-- do not include bufnr in fuzzy matching
-- tiebreak by line no.
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,
["ctrl-v"] = actions.buf_vsplit,
["ctrl-t"] = actions.buf_tabedit,
}
},
blines = { blines = {
previewer = "builtin", -- set to 'false' to disable previewer = "builtin", -- set to 'false' to disable
prompt = 'BLines ', prompt = 'BLines ',
show_unlisted = true, -- include 'help' buffers show_unlisted = true, -- include 'help' buffers
no_term_buffers = false, -- include 'term' buffers no_term_buffers = false, -- include 'term' buffers
fzf_opts = {
-- hide filename, tiebreak by line no.
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = { actions = {
["default"] = actions.buf_edit, ["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split, ["ctrl-s"] = actions.buf_split,

@ -324,6 +324,13 @@ M.globals.lines = {
prompt = 'Lines> ', prompt = 'Lines> ',
file_icons = true and M._has_devicons, file_icons = true and M._has_devicons,
color_icons = true, color_icons = true,
show_unlisted = false,
no_term_buffers = true,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = { actions = {
["default"] = actions.buf_edit, ["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split, ["ctrl-s"] = actions.buf_split,
@ -338,6 +345,11 @@ M.globals.blines = {
color_icons = true, color_icons = true,
show_unlisted = true, show_unlisted = true,
no_term_buffers = false, no_term_buffers = false,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = { actions = {
["default"] = actions.buf_edit, ["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split, ["ctrl-s"] = actions.buf_split,

@ -170,7 +170,7 @@ function M.entry_to_file(entry, cwd)
if bufnr then if bufnr then
terminal = utils.is_term_buffer(bufnr) terminal = utils.is_term_buffer(bufnr)
if terminal then if terminal then
file, line = stripped:match("(.*):(%d+)$") file, line = stripped:match("([^:]+):(%d+)")
end end
end end
return { return {

@ -252,6 +252,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
else --]] else --]]
-- mark the buffer for unloading the next call -- mark the buffer for unloading the next call
self.preview_bufloaded = true self.preview_bufloaded = true
entry.filetype = vim.api.nvim_buf_get_option(entry.bufnr, 'filetype')
local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, lines) vim.api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, lines)
-- end -- end
@ -335,11 +336,19 @@ function Previewer.buffer_or_file:do_syntax(entry)
)) ))
end end
if syntax_limit_reached == 0 then if syntax_limit_reached == 0 then
-- prepend the buffer number to the path and if entry.filetype and #entry.filetype>0 then
-- set as buffer name, this makes sure 'filetype detect' -- filetype was saved from a loaded buffer
-- gets the right filetype which enables the syntax -- this helps avoid losing highlights for help buffers
local tempname = path.join({tostring(bufnr), entry.path}) -- which are '.txt' files with 'ft=help'
pcall(api.nvim_buf_set_name, bufnr, tempname) -- api.nvim_buf_set_option(bufnr, 'filetype', entry.filetype)
pcall(api.nvim_buf_set_option, bufnr, 'filetype', entry.filetype)
else
-- prepend the buffer number to the path and
-- set as buffer name, this makes sure 'filetype detect'
-- gets the right filetype which enables the syntax
local tempname = path.join({tostring(bufnr), entry.path})
pcall(api.nvim_buf_set_name, bufnr, tempname)
end
-- nvim_buf_call has less side-effects than window switch -- nvim_buf_call has less side-effects than window switch
api.nvim_buf_call(bufnr, function() api.nvim_buf_call(bufnr, function()
vim.cmd('filetype detect') vim.cmd('filetype detect')

@ -205,9 +205,6 @@ end
M.buffer_lines = function(opts) M.buffer_lines = function(opts)
if not opts then return end if not opts then return end
if opts.no_term_buffers == nil then
opts.no_term_buffers = true
end
local buffers = filter_buffers(opts, local buffers = filter_buffers(opts,
opts.current_buffer_only and { vim.api.nvim_get_current_buf() } or opts.current_buffer_only and { vim.api.nvim_get_current_buf() } or
vim.api.nvim_list_bufs()) vim.api.nvim_list_bufs())
@ -249,9 +246,6 @@ M.buffer_lines = function(opts)
-- disable multi-select -- disable multi-select
opts.fzf_opts["--no-multi"] = '' opts.fzf_opts["--no-multi"] = ''
opts.fzf_opts["--preview-window"] = 'hidden:right:0' opts.fzf_opts["--preview-window"] = 'hidden:right:0'
opts.fzf_opts["--delimiter"] = vim.fn.shellescape(']')
opts.fzf_opts["--nth"] = '2,-1'
opts.fzf_opts["--tiebreak"] = 'index'
if opts.search and #opts.search>0 then if opts.search and #opts.search>0 then
opts.fzf_opts['--query'] = vim.fn.shellescape(opts.search) opts.fzf_opts['--query'] = vim.fn.shellescape(opts.search)

@ -349,8 +349,10 @@ M.grep_curbuf = function(opts)
if opts.exec_empty_query == nil then if opts.exec_empty_query == nil then
opts.exec_empty_query = true opts.exec_empty_query = true
end end
opts.fzf_opts = vim.tbl_extend("keep",
opts.fzf_opts or {}, config.globals.blines.fzf_opts)
opts.filename = vim.api.nvim_buf_get_name(0) opts.filename = vim.api.nvim_buf_get_name(0)
if #opts.filename > 0 then if #opts.filename > 0 and vim.loop.fs_stat(opts.filename) then
opts.filename = path.relative(opts.filename, vim.loop.cwd()) opts.filename = path.relative(opts.filename, vim.loop.cwd())
if opts.lgrep then if opts.lgrep then
return M.live_grep(opts) return M.live_grep(opts)
@ -359,7 +361,7 @@ M.grep_curbuf = function(opts)
return M.grep(opts) return M.grep(opts)
end end
else else
utils.info("Rg current buffer requires actual file on disk") utils.info("Rg current buffer requires file on disk")
return return
end end
end end

Loading…
Cancel
Save