Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 10, 2024
1 parent b7e4d47 commit f89ecda
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 77 deletions.
6 changes: 6 additions & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
38 changes: 5 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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`)|
Expand Down
10 changes: 9 additions & 1 deletion doc/fzf-lua-opts.txt
Original file line number Diff line number Diff line change
@@ -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*
Expand Down Expand Up @@ -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`
Expand Down
57 changes: 29 additions & 28 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions lua/fzf-lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions lua/fzf-lua/providers/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions lua/fzf-lua/win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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+):(.+)$")
-- line<U+00A0>text (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

Expand Down

0 comments on commit f89ecda

Please sign in to comment.