Skip to content

Commit

Permalink
feat: provider-global defaults (closes #898)
Browse files Browse the repository at this point in the history
For exmaple, opening the quickfix list at the top:
```lua
require("fzf-lua").setup({
  defaults = { copen = "topleft copen" },
})
```
  • Loading branch information
ibhagwan committed Oct 20, 2023
1 parent 85bfacf commit a5858b3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 25 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,13 @@ require'fzf-lua'.setup {
-- ext_ft_override = { ["ksql"] = "sql", ... },
},
},
-- provider setup
-- PROVIDERS SETUP
-- use `defaults` (table or function) if you wish to set "global-provider" defaults
-- for exmaple, disabling file icons globally and open the quickfix list at the top
-- defaults = {
-- file_icons = false,
-- copen = "topleft copen",
-- },
files = {
-- previewer = "bat", -- uncomment to override previewer
-- (name from 'previewers' table)
Expand Down
8 changes: 6 additions & 2 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ local sel_to_qf = function(selected, opts, is_loclist)
items = qf_list,
title = title,
})
vim.cmd(opts.lopen or "lopen")
if opts.lopen ~= false then
vim.cmd(opts.lopen or "botright lopen")
end
else
-- Set the quickfix title to last query and
-- append a new list to end of the stack (#635)
Expand All @@ -212,7 +214,9 @@ local sel_to_qf = function(selected, opts, is_loclist)
title = title,
-- nr = nr,
})
vim.cmd(opts.copen or "copen")
if opts.copen ~= false then
vim.cmd(opts.copen or "botright copen")
end
end
end

Expand Down
10 changes: 9 additions & 1 deletion lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ function M.normalize_opts(opts, defaults)
defaults._actions())
end

-- First, merge with provider defaults
-- First merge with the users' "provider-global" defaults
if type(M.globals.defaults) == "table" then
opts = vim.tbl_deep_extend("keep", opts, utils.tbl_deep_clone(M.globals.defaults))
elseif type(M.globals.defaults) == "function" then
opts = vim.tbl_deep_extend("keep", opts, utils.tbl_deep_clone(M.globals.defaults()))
end

-- Then merge with provider defaults "keeping" provider-globals
-- we must clone the 'defaults' tbl, otherwise 'opts.actions.default'
-- overrides 'config.globals.lsp.actions.default' in neovim 6.0
-- which then prevents the default action of all other LSP providers
Expand Down Expand Up @@ -220,6 +227,7 @@ function M.normalize_opts(opts, defaults)
-- Merge global resume options
opts.global_resume = get_opt("global_resume", opts, M.globals)

-- DEPRECATED: use `defaults` (provider-defaults) table
-- global option overrides. If exists, these options will
-- be used in a "LOGICAL AND" against the local option (#188)
-- e.g.:
Expand Down
16 changes: 9 additions & 7 deletions lua/fzf-lua/profiles/borderless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ local hls = {
sel = "PmenuSel",
}
return {
desc = "borderless and minimalistic",
global_git_icons = false,
global_file_icons = false,
fzf_opts = {},
winopts = {
desc = "borderless and minimalistic",
fzf_opts = {},
winopts = {
-- border = "none",
-- border = "thicccc",
border = { " ", " ", " ", " ", " ", " ", " ", " " },
Expand All @@ -17,7 +15,7 @@ return {
title_pos = "center",
},
},
hls = {
hls = {
border = hls.bg,
preview_border = hls.bg,
preview_title = hls.sel,
Expand All @@ -26,11 +24,15 @@ return {
-- TODO: not working with `scrollbar = "border"` when `border = "none"
-- scrollborder_f = "@function",
},
fzf_colors = {
fzf_colors = {
["gutter"] = { "bg", hls.bg },
["bg"] = { "bg", hls.bg },
["bg+"] = { "bg", hls.sel },
["fg+"] = { "fg", hls.sel },
-- ["fg+"] = { "fg", "", "reverse:-1" },
},
defaults = {
git_icons = false,
file_icons = false,
},
}
2 changes: 0 additions & 2 deletions lua/fzf-lua/profiles/fzf-vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,4 @@ return {
git_icons = false,
exec_empty_query = true,
},
-- global_git_icons = false,
-- global_file_icons = false,
}
6 changes: 4 additions & 2 deletions lua/fzf-lua/profiles/max-perf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ return {
tags = { previewer = "bat" },
btags = { previewer = "bat" },
files = { fzf_opts = { ["--ansi"] = false } },
global_git_icons = false,
global_file_icons = false,
defaults = {
git_icons = false,
file_icons = false,
},
}
18 changes: 9 additions & 9 deletions lua/fzf-lua/profiles/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ local function hl_validate(hl)
end

return {
desc = "match telescope default highlights|keybinds",
fzf_opts = { ["--layout"] = "default", ["--marker"] = "+" },
winopts = {
desc = "match telescope default highlights|keybinds",
fzf_opts = { ["--layout"] = "default", ["--marker"] = "+" },
winopts = {
width = 0.8,
height = 0.9,
preview = {
Expand All @@ -19,7 +19,7 @@ return {
flip_columns = 120,
},
},
hls = {
hls = {
normal = hl_validate "TelescopeNormal",
border = hl_validate "TelescopeBorder",
title = hl_validate "TelescopeTitle",
Expand All @@ -34,7 +34,7 @@ return {
cursorlinenr = hl_validate "TelescopePreviewLine",
search = hl_validate "IncSearch",
},
fzf_colors = {
fzf_colors = {
["fg"] = { "fg", "TelescopeNormal" },
["bg"] = { "bg", "TelescopeNormal" },
["hl"] = { "fg", "TelescopeMatching" },
Expand All @@ -49,7 +49,7 @@ return {
["marker"] = { "fg", "TelescopeSelectionCaret" },
["header"] = { "fg", "TelescopeTitle" },
},
keymap = {
keymap = {
builtin = {
["<F1>"] = "toggle-help",
["<F2>"] = "toggle-fullscreen",
Expand Down Expand Up @@ -77,7 +77,7 @@ return {
["ctrl-q"] = "select-all+accept",
},
},
actions = {
actions = {
files = {
["default"] = actions.file_edit_or_qf,
["ctrl-x"] = actions.file_split,
Expand All @@ -93,9 +93,9 @@ return {
["ctrl-t"] = actions.buf_tabedit,
}
},
buffers = {
buffers = {
keymap = { builtin = { ["<C-d>"] = false } },
actions = { ["ctrl-x"] = false, ["ctrl-d"] = { actions.buf_del, actions.resume } },
},
global_git_icons = false,
defaults = { git_icons = false },
}
2 changes: 1 addition & 1 deletion scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vim.cmd("set packpath=" .. packpath)

vim.o.termguicolors = true

require "fzf-lua".setup { global_git_icons = false }
require "fzf-lua".setup { defaults = { git_icons = false } }

vim.api.nvim_set_keymap("n", "<C-\\>", [[<Cmd>lua require"fzf-lua".buffers()<CR>]], {})
vim.api.nvim_set_keymap("n", "<C-k>", [[<Cmd>lua require"fzf-lua".builtin()<CR>]], {})
Expand Down

0 comments on commit a5858b3

Please sign in to comment.