nix-community.nixvim/plugins/bufferlines/bufferline.nix

378 lines
12 KiB
Nix
Raw Normal View History

{
config,
pkgs,
lib,
...
} @ args:
with lib; let
cfg = config.plugins.bufferline;
optionWarnings = import ../../lib/option-warnings.nix args;
helpers = import ../helpers.nix args;
2021-11-23 18:14:53 +01:00
highlight = mkOption {
type = types.nullOr (types.submodule ({...}: {
2021-11-23 18:14:53 +01:00
options = {
guifg = mkOption {
type = types.nullOr types.str;
description = "foreground color";
default = null;
};
guibg = mkOption {
type = types.nullOr types.str;
description = "background color";
default = null;
};
};
}));
default = {};
2021-11-23 18:14:53 +01:00
};
in {
imports = [
(optionWarnings.mkDeprecatedOption {
option = ["plugins" "bufferline" "indicatorIcon"];
alternative = ["plugins" "bufferline" "indicator" "icon"];
})
];
2021-11-23 16:33:52 +01:00
options = {
plugins.bufferline = {
2023-01-22 03:32:08 +00:00
enable = mkEnableOption "bufferline";
package = helpers.mkPackageOption "bufferline" pkgs.vimPlugins.bufferline-nvim;
2021-11-23 16:33:52 +01:00
numbers = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "A lua function customizing the styling of numbers.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
closeCommand = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "Command or function run when closing a buffer.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
rightMouseCommand = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "Command or function run when right clicking on a buffer.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
leftMouseCommand = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "Command or function run when clicking on a buffer.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
middleMouseCommand = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "Command or function run when middle clicking on a buffer.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
# is deprecated, but might still work
2021-11-23 16:33:52 +01:00
indicatorIcon = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
description = "The Icon shown as a indicator for buffer. Changing it is NOT recommended,
2021-11-23 16:33:52 +01:00
this is intended to be an escape hatch for people who cannot bear it for whatever reason.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
bufferCloseIcon = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
2021-11-23 16:33:52 +01:00
description = "The close icon for each buffer.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
modifiedIcon = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
2021-11-23 16:33:52 +01:00
description = "The icon indicating a buffer was modified.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
closeIcon = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
2021-11-23 16:33:52 +01:00
description = "The close icon.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
leftTruncMarker = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
default = null;
2021-11-23 16:33:52 +01:00
};
rightTruncMarker = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.str;
default = null;
2021-11-23 16:33:52 +01:00
};
nameFormatter = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
2021-11-23 16:33:52 +01:00
description = "A lua function that can be used to modify the buffer's lable. The argument 'buf' containing a name, path and bufnr is supplied.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
maxNameLength = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.int;
2021-11-23 16:33:52 +01:00
description = "Max length of a buffer name.";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
maxPrefixLength = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.int;
2021-11-23 16:33:52 +01:00
description = "Max length of a buffer prefix (used when a buffer is de-duplicated)";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
tabSize = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.int;
2021-11-23 16:33:52 +01:00
description = "Size of the tabs";
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
diagnostics = mkOption {
type = types.nullOr (types.enum [false "nvim_lsp" "coc"]);
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
diagnosticsUpdateInInsert = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
diagnosticsIndicator = mkOption {
type = types.nullOr helpers.rawType;
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
customFilter = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.lines;
default = null;
2021-11-23 16:33:52 +01:00
};
showBufferIcons = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
showBufferCloseIcons = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
showCloseIcon = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
showTabIndicators = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
persistBufferSort = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
separatorStyle = mkOption {
type = types.nullOr (types.enum ["slant" "thick" "thin"]);
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 16:33:52 +01:00
};
enforceRegularTabs = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
alwaysShowBufferline = mkOption {
2021-11-24 16:29:42 +01:00
type = types.nullOr types.bool;
default = null;
2021-11-23 16:33:52 +01:00
};
sortBy = mkOption {
type = types.nullOr (types.enum ["id" "extension" "relative_directory" "directory" "tabs"]);
2021-11-24 16:29:42 +01:00
default = null;
2021-11-23 18:14:53 +01:00
};
indicator = mkOption {
default = {};
type = types.nullOr (types.submodule ({...}: {
options = {
icon = mkOption {
type = types.nullOr types.str;
default = null;
};
style = mkOption {
type = types.nullOr (types.enum ["icon" "underline" "none"]);
default = null;
};
};
}));
};
2021-11-23 18:14:53 +01:00
highlights = mkOption {
default = {};
type = types.nullOr (types.submodule ({...}: {
2021-11-23 18:14:53 +01:00
options = {
fill = highlight;
background = highlight;
tab = highlight;
tabSelected = highlight;
tabClose = highlight;
closeButton = highlight;
closeButtonVisible = highlight;
closeButtonSelected = highlight;
bufferVisible = highlight;
bufferSelected = highlight;
diagnostic = highlight;
diagnosticVisible = highlight;
diagnosticSelected = highlight;
info = highlight;
infoVisible = highlight;
infoSelected = highlight;
infoDiagnostic = highlight;
infoDiagnosticVisible = highlight;
infoDiagnosticSelected = highlight;
warning = highlight;
warningVisible = highlight;
warningSelected = highlight;
warningDiagnostic = highlight;
warningDiagnosticVisible = highlight;
warningDiagnosticSelected = highlight;
error = highlight;
errorVisible = highlight;
errorSelected = highlight;
errorDiagnostic = highlight;
errorDiagnosticVisible = highlight;
errorDiagnosticSelected = highlight;
modified = highlight;
modifiedVisible = highlight;
modifiedSelected = highlight;
duplicate = highlight;
duplicateVisible = highlight;
duplicateSelected = highlight;
separator = highlight;
separatorVisible = highlight;
separatorSelected = highlight;
indicatorSelected = highlight;
pick = highlight;
pickVisible = highlight;
pickSelected = highlight;
};
2021-11-24 16:29:42 +01:00
}));
2021-11-23 16:33:52 +01:00
};
extraOptions = mkOption {
type = types.attrs;
default = {};
description = "Extra options, will override others if defined";
};
2021-11-23 16:33:52 +01:00
};
};
config = let
setupOptions = {
options =
{
numbers = cfg.numbers;
close_command = cfg.closeCommand;
right_mouse_command = cfg.rightMouseCommand;
left_mouse_command = cfg.leftMouseCommand;
middle_mouse_command = cfg.middleMouseCommand;
# deprecated, but might still work
indicator_icon = cfg.indicatorIcon;
indicator =
if cfg.indicator != null
then
with cfg.indicator; {
icon = icon;
style = style;
}
else null;
buffer_close_icon = cfg.bufferCloseIcon;
modified_icon = cfg.modifiedIcon;
close_icon = cfg.closeIcon;
left_trunc_marker = cfg.leftTruncMarker;
right_trunc_marker = cfg.rightTruncMarker;
name_formatter = cfg.nameFormatter;
max_name_length = cfg.maxNameLength;
max_prefix_length = cfg.maxPrefixLength;
tab_size = cfg.tabSize;
diagnostics = cfg.diagnostics;
diagnostics_update_in_insert = cfg.diagnosticsUpdateInInsert;
diagnostics_indicator = cfg.diagnosticsIndicator;
custom_filter = cfg.customFilter;
show_buffer_icons = cfg.showBufferIcons;
show_buffer_close_icons = cfg.showBufferCloseIcons;
show_close_icon = cfg.showCloseIcon;
show_tab_indicators = cfg.showTabIndicators;
persist_buffer_sort = cfg.persistBufferSort;
separator_style = cfg.separatorStyle;
enforce_regular_tabs = cfg.enforceRegularTabs;
always_show_bufferline = cfg.alwaysShowBufferline;
sort_by = cfg.sortBy;
}
// cfg.extraOptions;
highlights =
if builtins.isNull cfg.highlights
then null
else
with cfg.highlights; {
fill = fill;
background = background;
tab = tab;
tab_selected = tabSelected;
tab_close = tabClose;
close_button = closeButton;
close_button_visible = closeButtonVisible;
close_button_selected = closeButtonSelected;
buffer_visible = bufferVisible;
buffer_selected = bufferSelected;
diagnostic = diagnostic;
diagnostic_visible = diagnosticVisible;
diagnostic_selected = diagnosticSelected;
info = info;
info_visible = infoVisible;
info_selected = infoSelected;
info_diagnostic = infoDiagnostic;
info_diagnostic_visible = infoDiagnosticVisible;
info_diagnostic_selected = infoDiagnosticSelected;
warning = warning;
warning_visible = warningVisible;
warning_selected = warningSelected;
warning_diagnostic = warningDiagnostic;
warning_diagnostic_visible = warningDiagnosticVisible;
warning_diagnostic_selected = warningDiagnosticSelected;
error = error;
error_visible = errorVisible;
error_selected = errorSelected;
error_diagnostic = errorDiagnostic;
error_diagnostic_visible = errorDiagnosticVisible;
error_diagnostic_selected = errorDiagnosticSelected;
modified = modified;
modified_visible = modifiedVisible;
modified_selected = modifiedSelected;
duplicate = duplicate;
duplicate_visible = duplicateVisible;
duplicate_selected = duplicateSelected;
separator = separator;
separator_visible = separatorVisible;
separator_selected = separatorSelected;
indicator_selected = indicatorSelected;
pick = pick;
pick_visible = pickVisible;
pick_selected = pickSelected;
};
};
in
mkIf cfg.enable {
2021-11-23 16:33:52 +01:00
extraPlugins = with pkgs.vimPlugins; [
cfg.package
2021-11-23 16:33:52 +01:00
nvim-web-devicons
];
options.termguicolors = true;
extraConfigLua = ''
2021-11-23 18:14:53 +01:00
require('bufferline').setup${helpers.toLuaObject setupOptions}
2021-11-23 16:33:52 +01:00
'';
};
}