neovim-flake/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix

393 lines
12 KiB
Nix
Raw Permalink Normal View History

{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) enum bool either nullOr str int listOf attrs;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
in {
options.vim.tabline.nvimBufferline = {
enable = mkEnableOption "neovim bufferline";
2023-04-12 21:13:00 +02:00
mappings = {
closeCurrent = mkMappingOption "Close buffer" null;
cycleNext = mkMappingOption "Next buffer" "<leader>bn";
cyclePrevious = mkMappingOption "Previous buffer" "<leader>bp";
pick = mkMappingOption "Pick buffer" "<leader>bc";
sortByExtension = mkMappingOption "Sort buffers by extension" "<leader>bse";
sortByDirectory = mkMappingOption "Sort buffers by directory" "<leader>bsd";
sortById = mkMappingOption "Sort buffers by ID" "<leader>bsi";
moveNext = mkMappingOption "Move next buffer" "<leader>bmn";
movePrevious = mkMappingOption "Move previous buffer" "<leader>bmp";
};
setupOpts = mkPluginSetupOption "Bufferline-nvim" {
2024-06-16 19:56:31 +02:00
highlights = mkOption {
type = either attrs luaInline;
default = {};
description = ''
2024-06-16 19:56:31 +02:00
Overrides the highlight groups of bufferline.
2024-06-16 19:56:31 +02:00
See `:help bufferline-highlights`.
'';
};
2024-06-16 19:56:31 +02:00
options = {
mode = mkOption {
type = enum ["tabs" "buffers"];
default = "buffers";
description = "Mode to use for bufferline";
};
2024-06-16 19:56:31 +02:00
style_preset = mkOption {
type = enum ["default" "minimal" "no_bold" "no_italic"];
default = "default";
apply = value: mkLuaInline "require('bufferline').style_preset.${value}";
description = "The base style of bufferline";
};
2024-06-16 19:56:31 +02:00
themable = mkOption {
type = bool;
default = true;
description = ''
2024-11-26 09:24:25 +01:00
Whether or not to allow highlight groups to be overridden.
While false, bufferline.nvim sets highlights as default.
2024-06-16 19:56:31 +02:00
'';
};
2024-06-16 19:56:31 +02:00
numbers = mkOption {
type = either (enum ["none" "ordinal" "buffer_id" "both"]) luaInline;
default = mkLuaInline ''
function(opts)
return string.format('%s·%s', opts.raise(opts.id), opts.lower(opts.ordinal))
end
'';
description = "Whether or not to show buffer numbers";
};
2024-06-16 19:56:31 +02:00
close_command = mkOption {
type = either str luaInline;
default = mkLuaInline ''
function(bufnum)
require("bufdelete").bufdelete(bufnum, false)
end
'';
2024-06-16 19:56:31 +02:00
description = "Command to run when closing a buffer";
};
2024-06-16 19:56:31 +02:00
right_mouse_command = mkOption {
type = nullOr (either str luaInline);
default = "vertical sbuffer %d";
description = "Command to run when right clicking a buffer";
};
2024-06-16 19:56:31 +02:00
left_mouse_command = mkOption {
type = nullOr (either str luaInline);
default = "buffer %d";
description = "Command to run when left clicking a buffer";
};
2024-06-16 19:56:31 +02:00
middle_mouse_command = mkOption {
type = nullOr (either str luaInline);
default = null;
description = "Command to run when middle clicking a buffer";
};
2024-06-16 19:56:31 +02:00
indicator = {
icon = mkOption {
type = nullOr str;
default = null;
description = ''
The indicatotor icon to use for the current buffer.
2024-06-16 19:56:31 +02:00
::: {.warning}
2024-11-26 08:36:39 +01:00
This **must** be omitted while style is not `icon`
2024-06-16 19:56:31 +02:00
:::
'';
};
style = mkOption {
type = enum ["icon" "underline" "none"];
default = "underline";
description = "Style for indicator";
};
};
2024-06-16 19:56:31 +02:00
buffer_close_icon = mkOption {
type = str;
default = " 󰅖 ";
description = "Icon for close button";
};
2024-06-16 19:56:31 +02:00
modified_icon = mkOption {
type = str;
default = " ";
description = "Icon for modified buffer";
};
2024-06-16 19:56:31 +02:00
close_icon = mkOption {
type = str;
default = " ";
description = "Icon for close button";
};
2024-06-16 19:56:31 +02:00
left_trunc_marker = mkOption {
type = str;
default = "";
description = "Icon for left truncation";
};
2024-06-16 19:56:31 +02:00
right_trunc_marker = mkOption {
type = str;
default = "";
description = "Icon for right truncation";
};
2024-06-16 19:56:31 +02:00
name_formatter = mkOption {
type = nullOr luaInline;
default = null;
description = ''
`name_formatter` can be used to change the buffer's label in the
bufferline.
2024-06-16 19:56:31 +02:00
::: {.note}
Some names can/will break the bufferline so use this at your
discretion knowing that it has some limitations that will
**NOT** be fixed.
:::
'';
};
2024-06-16 19:56:31 +02:00
max_name_length = mkOption {
type = int;
default = 18;
description = "Max name length";
};
2024-06-16 19:56:31 +02:00
max_prefix_length = mkOption {
type = int;
default = 15;
description = "Length of the prefix used when a buffer is de-duplicated";
2024-06-16 19:56:31 +02:00
};
2024-06-16 19:56:31 +02:00
truncate_names = mkOption {
type = bool;
default = true;
description = "Truncate names";
};
2024-06-16 19:56:31 +02:00
tab_size = mkOption {
type = int;
default = 18;
description = "The size of the tabs in bufferline";
};
2024-06-16 19:56:31 +02:00
diagnostics = mkOption {
type = enum [false "nvim_lsp" "coc"];
default = "nvim_lsp";
description = "Diagnostics provider to be used in buffer LSP indicators";
};
2024-06-16 19:56:31 +02:00
diagnostics_update_in_insert = mkOption {
type = bool;
default = false;
description = ''
Whether to update diagnostics while in insert mode.
2024-06-16 19:56:31 +02:00
Setting this to true has performance implications, but they may be
negligible depending on your setup. Set it to true if you know what
you are doing.
'';
};
diagnostics_indicator = mkOption {
type = nullOr luaInline;
default = mkLuaInline ''
function(count, level, diagnostics_dict, context)
local s = " "
for e, n in pairs(diagnostics_dict) do
local sym = e == "error" and " "
or (e == "warning" and " " or " " )
s = s .. n .. sym
end
return s
end
2024-06-16 19:56:31 +02:00
'';
description = ''
Function to get the diagnostics indicator.
The function should return a string to be used as the indicator.
Can be set to nil to keep the buffer name highlight, but delete the
highlighting.
'';
};
custom_filter = mkOption {
type = nullOr luaInline;
default = null;
example = literalExpression ''
custom_filter = function(buf_number, buf_numbers)
-- filter out filetypes you don't want to see
if vim.bo[buf_number].filetype ~= "<i-dont-want-to-see-this>" then
return true
2024-06-16 19:56:31 +02:00
end
-- filter out by buffer name
if vim.fn.bufname(buf_number) ~= "<buffer-name-I-dont-want>" then
return true
end
-- filter out based on arbitrary rules
-- e.g. filter out vim wiki buffer from tabline in your work repo
if vim.fn.getcwd() == "<work-repo>" and vim.bo[buf_number].filetype ~= "wiki" then
return true
end
-- filter out by it's index number in list (don't show first buffer)
if buf_numbers[1] ~= buf_number then
return true
end
end
2024-06-16 19:56:31 +02:00
'';
2024-06-16 19:56:31 +02:00
description = ''
Custom filter function for filtering out buffers.
2024-06-16 19:56:31 +02:00
::: {.note}
This will be called a lot, so you are encouraged to keep it as
short and lightweight as possible unless you are fully aware
of the performance implications.
:::
'';
};
2024-06-16 19:56:31 +02:00
offsets = mkOption {
type = listOf attrs;
default = [
{
filetype = "NvimTree";
text = "File Explorer";
highlight = "Directory";
separator = true;
}
];
description = "The windows to offset bufferline above, see `:help bufferline-offset`";
};
2024-06-16 19:56:31 +02:00
color_icons = mkOption {
type = bool;
default = true;
description = "Whether or not to add filetype icon highlights";
};
2024-06-16 19:56:31 +02:00
get_element_icon = mkOption {
type = nullOr luaInline;
default = null;
example = literalExpression ''
function(element)
local custom_map = {my_thing_ft: {icon = "my_thing_icon", hl = "DevIconDefault"}}
return custom_map[element.filetype]
end
'';
description = "The function bufferline uses to get the icon. Recommended to leave as default.";
};
2024-06-16 19:56:31 +02:00
show_buffer_icons = mkOption {
type = bool;
default = true;
description = "Whether or not to show buffer icons";
};
2024-06-16 19:56:31 +02:00
show_buffer_close_icons = mkOption {
type = bool;
default = true;
description = "Whether or not to show buffer close icons";
};
2024-06-16 19:56:31 +02:00
show_close_icon = mkOption {
type = bool;
default = true;
description = "Whether or not to show the close icon";
2024-06-16 19:56:31 +02:00
};
2024-06-16 19:56:31 +02:00
show_tab_indicators = mkOption {
type = bool;
default = true;
description = "Whether or not to show tab indicators";
};
2024-06-16 19:56:31 +02:00
show_duplicate_prefix = mkOption {
type = bool;
default = true;
description = "Whether or not to show duplicate buffer prefixes";
2024-06-16 19:56:31 +02:00
};
2024-06-16 19:56:31 +02:00
duplicates_across_groups = mkOption {
type = bool;
default = true;
description = "Whether to consider duplicate paths in different groups as duplicates";
};
2024-06-16 19:56:31 +02:00
persist_buffer_sort = mkOption {
type = bool;
default = true;
description = "Whether or not custom sorted buffers should persist";
};
2024-06-16 19:56:31 +02:00
move_wraps_at_ends = mkOption {
type = bool;
default = false;
description = "Whether or not the move command \"wraps\" at the first or last position";
};
2024-06-16 19:56:31 +02:00
separator_style = mkOption {
type = nullOr (either (enum ["slant" "padded_slant" "slope" "padded_slope" "thick" "thin"]) (listOf str));
2024-06-16 19:56:31 +02:00
default = "thin";
description = ''
The type of separator used to separate buffers and tabs.
2024-06-16 19:56:31 +02:00
Either one of the listed types, or a list of 2 characters for either side.
'';
};
2024-06-16 19:56:31 +02:00
enforce_regular_tabs = mkOption {
type = bool;
default = false;
description = "Whether to enforce regular tabs";
};
2024-06-16 19:56:31 +02:00
always_show_bufferline = mkOption {
type = bool;
default = true;
description = "Whether to always show bufferline";
};
2024-06-16 19:56:31 +02:00
auto_toggle_bufferline = mkOption {
type = bool;
default = true;
2024-06-16 19:56:31 +02:00
description = "Whether to auto toggle bufferline";
};
2024-06-16 19:56:31 +02:00
hover = {
enabled = mkEnableOption "hover" // {default = true;};
delay = mkOption {
type = int;
default = 200;
description = "Delay for hover, in ms";
};
reveal = mkOption {
type = listOf str;
default = ["close"];
description = "Reveal hover window";
};
};
2024-06-16 19:56:31 +02:00
sort_by = mkOption {
type = either (enum ["insert_after_current" "insert_at_end" "id" "extension" "relative_directory" "directory" "tabs"]) luaInline;
default = "extension";
description = "Method to sort buffers by. Must be one of the supported values, or an inline Lua value.";
2024-06-16 19:56:31 +02:00
};
};
};
};
}