diff --git a/OPTIONS.md b/OPTIONS.md index b5f3ef63..34621f03 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -574,6 +574,12 @@ Type: `string`, Default: `FzfLuaBufNr` Highlight group for buffer number in buffer type pickers, i.e. `buffers`, `tabs`, `lines`. +#### globals.hls.buf_linenr + +Type: `string`, Default: `LineNr` + +Highlight group for buffer line number in `lines`, `blines` and `treesitter`. + #### globals.hls.buf_flag_cur Type: `string`, Default: `FzfLuaBufFlagCur` diff --git a/README.md b/README.md index 43f1a0dd..211b8fd1 100644 --- a/README.md +++ b/README.md @@ -1106,45 +1106,16 @@ require'fzf-lua'.setup { ["--with-nth"] = '2..', }, }, + -- `blines` has the same defaults as `lines` aside from prompt and `show_bufname` lines = { - previewer = "builtin", -- set to 'false' to disable prompt = 'Lines❯ ', + show_bufname = true, -- display buffer name show_unloaded = true, -- show unloaded buffers 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"] = "[\\]:]", - ["--nth"] = '2..', - ["--tiebreak"] = 'index', - ["--tabstop"] = "1", - }, - -- actions inherit from 'actions.files' and merge - actions = { - ["enter"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf, - ["alt-l"] = actions.buf_sel_to_ll - }, - }, - blines = { - previewer = "builtin", -- set to 'false' to disable - prompt = 'BLines❯ ', - show_unlisted = true, -- include 'help' buffers - no_term_buffers = false, -- include 'term' buffers - -- start = "cursor" -- start display from cursor? - fzf_opts = { - -- hide filename, tiebreak by line no. - ["--delimiter"] = "[:]", - ["--with-nth"] = '2..', - ["--tiebreak"] = 'index', - ["--tabstop"] = "1", - }, - -- actions inherit from 'actions.files' and merge - actions = { - ["enter"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf, - ["alt-l"] = actions.buf_sel_to_ll }, }, tags = { @@ -1418,10 +1389,11 @@ temporarily overridden by its corresponding `winopts` option: |FzfLuaHelpBorder |FzfLuaBorder |`hls.help_border` |Help win border| |FzfLuaHeaderBind |*BlanchedAlmond |`hls.header_bind` |Header keybind| |FzfLuaHeaderText |*Brown1 |`hls.header_text` |Header text| -|FzfLuaPathColNr |*CadetBlue1 |`hls.path_colnr` |Path col nr (`lines,qf,lsp,diag`)| -|FzfLuaPathLineNr |*LightGreen |`hls.path_linenr` |Path line nr (`lines,qf,lsp,diag`)| +|FzfLuaPathColNr |*CadetBlue1 |`hls.path_colnr` |Path col nr (`qf,lsp,diag`)| +|FzfLuaPathLineNr |*LightGreen |`hls.path_linenr` |Path line nr (`qf,lsp,diag`)| |FzfLuaBufName |*LightMagenta |`hls.buf_name` |Buffer name (`lines`)| |FzfLuaBufNr |*BlanchedAlmond |`hls.buf_nr` |Buffer number (all buffers)| +|FzfLuaBufLineNr |LineNr |`hls.buf_linenr` |Buffer line nr (`lines,blines`)| |FzfLuaBufFlagCur |*Brown1 |`hls.buf_flag_cur` |Buffer line (`buffers`)| |FzfLuaBufFlagAlt |*CadetBlue1 |`hls.buf_flag_alt` |Buffer line (`buffers`)| |FzfLuaTabTitle |*LightSkyBlue1 |`hls.tab_title` |Tab title (`tabs`)| diff --git a/doc/fzf-lua-opts.txt b/doc/fzf-lua-opts.txt index 4892d794..d699e53e 100644 --- a/doc/fzf-lua-opts.txt +++ b/doc/fzf-lua-opts.txt @@ -1,4 +1,4 @@ -*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 November 18 +*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 06 ============================================================================== Table of Contents *fzf-lua-opts-table-of-contents* @@ -766,6 +766,14 @@ Highlight group for buffer number in buffer type pickers, i.e. `buffers`, +globals.hls.buf_linenr *fzf-lua-opts-globals.hls.buf_linenr* + +Type: `string`, Default: `LineNr` + +Highlight group for buffer line number in `lines`, `blines` and `treesitter`. + + + globals.hls.buf_flag_cur *fzf-lua-opts-globals.hls.buf_flag_cur* Type: `string`, Default: `FzfLuaBufFlagCur` diff --git a/lua/fzf-lua/defaults.lua b/lua/fzf-lua/defaults.lua index d2e74922..36f00175 100644 --- a/lua/fzf-lua/defaults.lua +++ b/lua/fzf-lua/defaults.lua @@ -623,48 +623,48 @@ M.defaults.lines = { show_unloaded = true, show_unlisted = false, no_term_buffers = true, + winopts = { treesitter = true }, + hls = { buf_nr = "TabLine" }, fzf_opts = { ["--multi"] = true, - ["--delimiter"] = "[\\]:]", - ["--nth"] = "2..", + ["--delimiter"] = "[\t]", + ["--tabstop"] = "1", ["--tiebreak"] = "index", + ["--with-nth"] = "2..", + ["--nth"] = "3..", + }, + fzf_colors = { + ["hl"] = "-1:reverse:underline", + ["hl+"] = "-1:reverse:underline", }, line_field_index = "{3}", + _fmt = { + -- NOTE: `to` is not needed, we format at the source in `buffer_lines` + to = false, + from = function(s, _) + -- restore the format to something that `path.entry_to_file` can handle + local bufnr, lnum, text = s:match("%[(%d+)%].-(%d+) (.+)$") + if not bufnr then return "" end + return string.format("[%s]%s%s:%s:%s", + bufnr, utils.nbsp, + path.tail(vim.api.nvim_buf_get_name(tonumber(bufnr))), + lnum, text) + end + }, _actions = function() return M.globals.actions.buffers or M.globals.actions.files end, - actions = { - ["enter"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf, - ["alt-l"] = actions.buf_sel_to_ll - }, - _cached_hls = { "buf_name", "buf_nr", "path_linenr" }, + _cached_hls = { "buf_name", "buf_nr", "buf_linenr" }, } -M.defaults.blines = { - previewer = M._default_previewer_fn, +M.defaults.blines = vim.tbl_deep_extend("force", M.defaults.lines, { prompt = "BLines> ", - file_icons = false, - color_icons = false, - show_unlisted = true, - no_term_buffers = false, fzf_opts = { - ["--multi"] = true, - ["--delimiter"] = "[:]", - ["--with-nth"] = "2..", - ["--tiebreak"] = "index", + ["--with-nth"] = "3..", + ["--nth"] = "2..", }, line_field_index = "{2}", - _actions = function() - return M.globals.actions.buffers or M.globals.actions.files - end, - actions = { - ["enter"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf, - ["alt-l"] = actions.buf_sel_to_ll - }, - _cached_hls = { "buf_name", "buf_nr", "path_linenr" }, -} +}) M.defaults.treesitter = { previewer = M._default_previewer_fn, @@ -1190,6 +1190,7 @@ M.defaults.__HLS = { path_linenr = "FzfLuaPathLineNr", buf_name = "FzfLuaBufName", buf_nr = "FzfLuaBufNr", + buf_linenr = "FzfLuaBufLineNr", buf_flag_cur = "FzfLuaBufFlagCur", buf_flag_alt = "FzfLuaBufFlagAlt", tab_title = "FzfLuaTabTitle", diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 69a4dfb7..1649980e 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -92,6 +92,8 @@ function M.setup_highlights(override) { default = default, fg = is_light and "DarkOrchid3" or "LightMagenta" } }, { "FzfLuaBufNr", "buf_nr", -- buffers|tabs|lines|blines { default = default, fg = is_light and "AquaMarine3" or "BlanchedAlmond" } }, + { "FzfLuaBufLineNr", "buf_linenr", -- lines|blines|treesitter + { default = default, link = "LineNr" } }, { "FzfLuaBufFlagCur", "buf_flag_cur", -- buffers|tabs { default = default, fg = is_light and "Brown4" or "Brown1" } }, { "FzfLuaBufFlagAlt", "buf_flag_alt", -- buffers|tabs diff --git a/lua/fzf-lua/providers/buffers.lua b/lua/fzf-lua/providers/buffers.lua index e9f7d6a3..d11defd2 100644 --- a/lua/fzf-lua/providers/buffers.lua +++ b/lua/fzf-lua/providers/buffers.lua @@ -221,9 +221,6 @@ end M.buffer_lines = function(opts) if not opts then return end - -- formatter doesn't work with lines|blines as only filename is displayed - opts._fmt = false - opts.fn_pre_fzf = function() core.CTX(true) end opts.fn_pre_fzf() @@ -281,14 +278,21 @@ M.buffer_lines = function(opts) if lnum > lines then lnum = lnum % lines end - add_entry(string.format("[%s]%s%s%s%s:%s: %s", - utils.ansi_codes[opts.hls.buf_nr](tostring(bufnr)), - utils.nbsp, - buficon or "", - buficon and utils.nbsp or "", - utils.ansi_codes[opts.hls.buf_name](bufname), - utils.ansi_codes[opts.hls.path_linenr](tostring(lnum)), - data[lnum]), co) + -- NOTE: Space after `lnum` is U+00A0 (decimal: 160) + add_entry(string.format("[%s]\t%s\t%s \t%s", + tostring(bufnr), + utils.ansi_codes[opts.hls.buf_nr](string.format("%2d", bufnr)), + utils.ansi_codes[opts.hls.buf_linenr](string.format("%5d", lnum)), + data[lnum] + ), co) + -- add_entry(string.format("[%s]%s%s%s%s:%s: %s", + -- utils.ansi_codes[opts.hls.buf_nr](tostring(bufnr)), + -- utils.nbsp, + -- buficon or "", + -- buficon and utils.nbsp or "", + -- utils.ansi_codes[opts.hls.buf_name](bufname), + -- utils.ansi_codes[opts.hls.buf_linenr](tostring(lnum)), + -- data[lnum]), co) end end cb(nil) diff --git a/lua/fzf-lua/win.lua b/lua/fzf-lua/win.lua index 2842ca7d..b9487371 100644 --- a/lua/fzf-lua/win.lua +++ b/lua/fzf-lua/win.lua @@ -836,12 +836,20 @@ function FzfWin:treesitter_attach() -- file:line:col:text (grep_xxx) -- file:line:text (grep_project or missing "--column" flag) -- line:col:text (grep_curbuf) - -- line:text (blines) - local filepath, _lnum, text = line:match("(.-):?(%d+):(.+)$") + -- linetext (lines|blines) + local filepath, _lnum, text = line:match("(.-):?(%d+)[: ](.+)$") if not text or text == 0 then return end - filepath = trim(filepath) - local ft = #filepath == 0 and vim.bo[utils.CTX().bufnr].ft + + local ft_bufnr = (function() + -- NOTE: blines|lines has U+00A0 (decimal: 160) following lnum + if string.byte(text, 1) == 160 then + text = text:sub(2) + return filepath:match("^%d+") or utils.CTX().bufnr + end + end)() + + local ft = ft_bufnr and vim.bo[tonumber(ft_bufnr)].ft or vim.filetype.match({ filename = path.tail(filepath) }) if not ft then return end