plugins/barbar: refactoring + nix flake update (#317)

* flake: update inputs

* plugins/barbar: refactoring + fix options
This commit is contained in:
Gaétan Lepage 2023-04-06 10:28:13 +02:00 committed by GitHub
parent d40db46d7f
commit 35c570deac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 359 additions and 210 deletions

24
flake.lock generated
View file

@ -9,11 +9,11 @@
"utils": "utils" "utils": "utils"
}, },
"locked": { "locked": {
"lastModified": 1669854260, "lastModified": 1680308980,
"narHash": "sha256-Z8NAL3g4i5LAhxveNGJhrVDHxIBbUf1lVIy/Thr2RMU=", "narHash": "sha256-aUEHV0jk2qIFP3jlsWYWhBbm+w/N9gzH3e4I5DcdB5s=",
"owner": "lovesegfault", "owner": "lovesegfault",
"repo": "beautysh", "repo": "beautysh",
"rev": "d616eb8d9d05ee4fb33de9c5521d99c3f0695d52", "rev": "9845efc3ea3e86cc0d41465d720a47f521b2799c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -91,11 +91,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1679705136, "lastModified": 1680487167,
"narHash": "sha256-MDlZUR7wJ3PlPtqwwoGQr3euNOe0vdSSteVVOef7tBY=", "narHash": "sha256-9FNIqrxDZgSliGGN2XJJSvcDYmQbgOANaZA4UWnTdg4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8f40f2f90b9c9032d1b824442cfbbe0dbabd0dbd", "rev": "53dad94e874c9586e71decf82d972dfb640ef044",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -157,11 +157,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1678976941, "lastModified": 1680599552,
"narHash": "sha256-skNr08frCwN9NO+7I77MjOHHAw+L410/37JknNld+W4=", "narHash": "sha256-rQQJFGvWQ3Sr+m/r5KGIFN0iVaVKr6u9uraCz6jSKj4=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "32b1dbedfd77892a6e375737ef04d8efba634e9e", "rev": "3342d7c51119030490fdcd07351b53b10806891c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -180,11 +180,11 @@
}, },
"utils": { "utils": {
"locked": { "locked": {
"lastModified": 1667395993, "lastModified": 1678901627,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -7,6 +7,56 @@
with lib; let with lib; let
cfg = config.plugins.barbar; cfg = config.plugins.barbar;
helpers = import ../helpers.nix {inherit lib;}; helpers = import ../helpers.nix {inherit lib;};
basePluginPath = ["plugins" "barbar"];
bufferOptions = {
bufferIndex = helpers.mkNullOrOption types.bool ''
Whether to show the index of the associated buffer with respect to the ordering of the
buffers in the tabline.
'';
bufferNumber =
helpers.mkNullOrOption types.bool
"Whether to show the `bufnr` for the associated buffer.";
button =
helpers.mkNullOrOption (with types; either str (enum [false]))
"the button which is clicked to close / save a buffer, or indicate that it is pinned.";
diagnostics =
helpers.mkCompositeOption "Diagnostics icons"
(
genAttrs
["error" "warn" "info" "hint"]
(
name:
helpers.mkCompositeOption "${name} diagnostic icon" {
enable = helpers.defaultNullOpts.mkBool false "Enable the ${name} diagnostic symbol";
icon = helpers.mkNullOrOption types.str "${name} diagnostic symbol";
}
)
);
filetype = {
customColors =
helpers.defaultNullOpts.mkBool false
"Sets the icon's highlight group. If false, will use nvim-web-devicons colors";
enable = helpers.defaultNullOpts.mkBool true "Show the filetype icon.";
};
separator = {
left = helpers.defaultNullOpts.mkStr "" "Left seperator";
right = helpers.defaultNullOpts.mkStr "" "Right seperator";
};
};
stateOptions =
{
modified = bufferOptions;
pinned = bufferOptions;
}
// bufferOptions;
keymaps = { keymaps = {
previous = "Previous"; previous = "Previous";
@ -32,185 +82,296 @@ with lib; let
orderByWindowNumber = "OrderByWindowNumber"; orderByWindowNumber = "OrderByWindowNumber";
}; };
in { in {
options.plugins.barbar = { # All the following renames/removes are from 2023-04-05.
enable = mkEnableOption "barbar.nvim"; # TODO: Remove them in 1-2 months.
imports = [
(mkRemovedOptionModule (basePluginPath ++ ["closable"]) "")
(
mkRenamedOptionModule
(basePluginPath ++ ["animations"])
(basePluginPath ++ ["animation"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["diagnostics"])
(basePluginPath ++ ["icons" "diagnostics"])
)
(mkRemovedOptionModule (basePluginPath ++ ["icons" "enable"]) "")
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "customColors"])
(basePluginPath ++ ["icons" "filetype" "customColors"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "separatorActive"])
(basePluginPath ++ ["icons" "separator" "left"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "separatorInactive"])
(basePluginPath ++ ["icons" "inactive" "separator" "left"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "separatorVisible"])
(basePluginPath ++ ["icons" "visible" "separator" "left"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "closeTab"])
(basePluginPath ++ ["icons" "button"])
)
(
mkRenamedOptionModule
(basePluginPath ++ ["icons" "closeTabModified"])
(basePluginPath ++ ["icons" "modified" "button"])
)
];
package = helpers.mkPackageOption "barbar" pkgs.vimPlugins.barbar-nvim; options.plugins.barbar =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "barbar.nvim";
animations = helpers.defaultNullOpts.mkBool true "Enable animations"; package = helpers.mkPackageOption "barbar" pkgs.vimPlugins.barbar-nvim;
autoHide = helpers.defaultNullOpts.mkBool false "Auto-hide the tab bar when there is only one buffer"; animation = helpers.defaultNullOpts.mkBool true "Enable/disable animations";
tabpages = helpers.defaultNullOpts.mkBool true "current/total tabpages indicator (top right corner)"; autoHide =
helpers.defaultNullOpts.mkBool false
"Enable/disable auto-hiding the tab bar when there is a single buffer.";
closable = helpers.defaultNullOpts.mkBool true "Enable the close button"; tabpages =
helpers.defaultNullOpts.mkBool true
"Enable/disable current/total tabpages indicator (top right corner).";
clickable = helpers.defaultNullOpts.mkBool true '' clickable = helpers.defaultNullOpts.mkBool true ''
Enable clickable tabs Enable clickable tabs
- left-click: go to buffer - left-click: go to buffer
- middle-click: delete buffer - middle-click: delete buffer
''; '';
diagnostics = { excludeFileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
error = { Excludes buffers of certain filetypes from the tabline
enable = helpers.defaultNullOpts.mkBool false "Enable the error diagnostic symbol"; '';
icon = helpers.defaultNullOpts.mkStr " " "Error diagnostic symbol";
};
warn = {
enable = helpers.defaultNullOpts.mkBool false "Enable the warning diagnostic symbol";
icon = helpers.defaultNullOpts.mkStr " " "Warning diagnostic symbol";
};
info = {
enable = helpers.defaultNullOpts.mkBool false "Enable the info diagnostic symbol";
icon = helpers.defaultNullOpts.mkStr " " "Info diagnostic symbol";
};
hint = {
enable = helpers.defaultNullOpts.mkBool false "Enable the hint diagnostic symbol";
icon = helpers.defaultNullOpts.mkStr "💡" "Hint diagnostic symbol";
};
};
excludeFileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' excludeFileNames = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Excludes buffers of certain filetypes from the tabline Excludes buffers with certain filenames from the tabline
''; '';
excludeFileNames = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' focusOnClose =
Excludes buffers with certain filenames from the tabline helpers.defaultNullOpts.mkEnumFirstDefault ["left" "right"]
'';
hide = {
extensions = helpers.defaultNullOpts.mkBool false "Hide file extensions";
inactive = helpers.defaultNullOpts.mkBool false "Hide inactive buffers";
alternate = helpers.defaultNullOpts.mkBool false "Hide alternate buffers";
current = helpers.defaultNullOpts.mkBool false "Hide current buffer";
visible = helpers.defaultNullOpts.mkBool false "Hide visible buffers";
};
highlightAlternate = helpers.defaultNullOpts.mkBool false "Highlight alternate buffers";
highlightInactiveFileIcons = helpers.defaultNullOpts.mkBool false "Highlight file icons in inactive buffers";
highlightVisible = helpers.defaultNullOpts.mkBool true "Highlight visible buffers";
icons = {
enable =
helpers.defaultNullOpts.mkNullable
(with types; (either bool (enum ["numbers" "both"])))
"true"
'' ''
Enable/disable icons if set to 'numbers', will show buffer index in the tabline if set to A buffer to this direction will be focused (if it exists) when closing the current buffer.
'both', will show buffer index and icons in the tabline
''; '';
customColors = highlightAlternate = helpers.defaultNullOpts.mkBool false "Highlight alternate buffers";
helpers.defaultNullOpts.mkNullable
(types.either types.bool types.str) highlightInactiveFileIcons =
"false" helpers.defaultNullOpts.mkBool false
"Highlight file icons in inactive buffers";
highlightVisible = helpers.defaultNullOpts.mkBool true "Highlight visible buffers";
icons =
stateOptions
// (
mapAttrs (name: description:
mkOption {
type = types.submodule {
options = stateOptions;
};
default = {};
inherit description;
})
{
alternate = "The icons used for an alternate buffer.";
current = "The icons for the current buffer.";
inactive = "The icons for inactive buffers.";
visible = "The icons for visible buffers.";
}
);
hide = {
alternate = helpers.mkNullOrOption types.bool "Hide alternate buffers";
current = helpers.mkNullOrOption types.bool "Hide current buffer";
extensions = helpers.mkNullOrOption types.bool "Hide file extensions";
inactive = helpers.mkNullOrOption types.bool "Hide inactive buffers";
visible = helpers.mkNullOrOption types.bool "Hide visible buffers";
};
insertAtEnd = helpers.defaultNullOpts.mkBool false ''
If true, new buffers will be inserted at the end of the list.
Default is to insert after current buffer.
'';
insertAtStart = helpers.defaultNullOpts.mkBool false ''
If true, new buffers will be inserted at the start of the list.
Default is to insert after current buffer.
'';
maximumPadding =
helpers.defaultNullOpts.mkInt 4
"Sets the maximum padding width with which to surround each tab";
minimumPadding =
helpers.defaultNullOpts.mkInt 1
"Sets the minimum padding width with which to surround each tab";
maximumLength =
helpers.defaultNullOpts.mkInt 30
"Sets the maximum buffer name length.";
semanticLetters = helpers.defaultNullOpts.mkBool true ''
If set, the letters for each buffer in buffer-pick mode will be assigned based on their
name.
Otherwise or in case all letters are already assigned, the behavior is to assign letters in
order of usability (see `letters` option)
'';
letters =
helpers.defaultNullOpts.mkStr
"asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP"
'' ''
If set, the icon color will follow its corresponding buffer New buffer letters are assigned in this order.
highlight group. By default, the Buffer*Icon group is linked to the This order is optimal for the qwerty keyboard layout but might need adjustement for other layouts.
Buffer* group (see Highlighting below). Otherwise, it will take its
default value as defined by devicons.
''; '';
separatorActive = helpers.defaultNullOpts.mkStr "" "Icon for the active tab separator"; sidebarFiletypes =
separatorInactive = helpers.defaultNullOpts.mkStr "" "Icon for the inactive tab separator"; helpers.mkNullOrOption
separatorVisible = helpers.defaultNullOpts.mkStr "" "Icon for the visible tab separator";
closeTab = helpers.defaultNullOpts.mkStr "" "Icon for the close tab button";
closeTabModified = helpers.defaultNullOpts.mkStr "" "Icon for the close tab button of a modified buffer";
pinned = helpers.defaultNullOpts.mkStr "" "Icon for the pinned tabs";
};
insertAtEnd = helpers.defaultNullOpts.mkBool false ''
If true, new buffers will be inserted at the end of the list.
Default is to insert after current buffer.
'';
insertAtStart = helpers.defaultNullOpts.mkBool false ''
If true, new buffers will be inserted at the start of the list.
Default is to insert after current buffer.
'';
maximumPadding = helpers.defaultNullOpts.mkInt 4 "Sets the maximum padding width with which to surround each tab";
minimumPadding = helpers.defaultNullOpts.mkInt 1 "Sets the minimum padding width with which to surround each tab";
maximumLength = helpers.defaultNullOpts.mkInt 30 "Sets the maximum buffer name length.";
semanticLetters = helpers.defaultNullOpts.mkBool true ''
If set, the letters for each buffer in buffer-pick mode will be assigned based on their name.
Otherwise or in case all letters are already assigned, the behavior is to assign letters in
order of usability (see `letters` option)
'';
letters = helpers.defaultNullOpts.mkStr "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP" ''
New buffer letters are assigned in this order.
This order is optimal for the qwerty keyboard layout but might need adjustement for other layouts.
'';
noNameTitle = helpers.mkNullOrOption types.str ''
Sets the name of unnamed buffers. By default format is "[Buffer X]" where X is the buffer number.
But only a static string is accepted here.
'';
keymaps =
{
silent = mkEnableOption "silent keymaps for barbar";
}
// (
mapAttrs
( (
optionName: funcName: with types;
helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}" attrsOf (
either
(enum [true])
(types.submodule {
options = {
text = helpers.mkNullOrOption types.str "The text used for the offset";
event =
helpers.mkNullOrOption types.str
"The event which the sidebar executes when leaving.";
};
})
)
) )
keymaps "Set the filetypes which barbar will offset itself for";
);
}; noNameTitle = helpers.mkNullOrOption types.str ''
Sets the name of unnamed buffers.
By default format is "[Buffer X]" where X is the buffer number.
But only a static string is accepted here.
'';
keymaps =
{
silent = mkEnableOption "silent keymaps for barbar";
}
// (
mapAttrs
(
optionName: funcName:
helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}"
)
keymaps
);
};
config = let config = let
setupOptions = { setupOptions =
animation = cfg.animations; {
auto_hide = cfg.autoHide; inherit (cfg) animation;
clickable = cfg.clickable; auto_hide = cfg.autoHide;
closable = cfg.closable; inherit (cfg) tabpages;
inherit (cfg) clickable;
exclude_ft = cfg.excludeFileTypes;
exclude_name = cfg.excludeFileNames;
focus_on_close = cfg.focusOnClose;
highlight_alternate = cfg.highlightAlternate;
highlight_inactive_file_icons = cfg.highlightInactiveFileIcons;
highlight_visible = cfg.highlightVisible;
icons = let
handleBufferOption = bufferOption:
with bufferOption; {
buffer_index = bufferIndex;
buffer_number = bufferNumber;
inherit button;
diagnostics = helpers.ifNonNull' bufferOption.diagnostics (
/*
Because the keys of this lua table are not strings (but
`vim.diagnostic.severity.XXXX`), we have to manualy build a raw lua string here.
*/
let
setIcons = filterAttrs (n: v: v != null) cfg.icons.diagnostics;
setIconsList =
mapAttrsToList
(name: value: {
key = "vim.diagnostic.severity.${strings.toUpper name}";
value = helpers.ifNonNull' value (helpers.toLuaObject {
enabled = value.enable;
inherit (value) icon;
});
})
setIcons;
in
helpers.mkRaw (
"{"
+ concatStringsSep ","
(
map
(iconOption: "[${iconOption.key}] = ${iconOption.value}")
setIconsList
)
+ "}"
)
);
filetype = with filetype; {
custom_color = customColors;
enabled = enable;
};
inherit separator;
};
diagnostics = [ handleStateOption = stateOption:
cfg.diagnostics.error with stateOption;
cfg.diagnostics.warn {
cfg.diagnostics.info modified = handleBufferOption modified;
cfg.diagnostics.hint pinned = handleBufferOption pinned;
]; }
// (
exclude_ft = cfg.excludeFileTypes; handleBufferOption
exclude_name = cfg.excludeFileNames; (
getAttrs (attrNames stateOption)
hide = cfg.hide; stateOption
)
highlight_alternate = cfg.highlightAlternate; );
highlight_inactive_file_icons = cfg.highlightInactiveFileIcons; in
highlight_visible = cfg.highlightVisible; (
handleStateOption
icon_close_tab = cfg.icons.closeTab; (
icon_close_tab_modified = cfg.icons.closeTabModified; getAttrs
icon_pinned = cfg.icons.pinned; (attrNames stateOptions)
icon_separator_active = cfg.icons.separatorActive; cfg.icons
icon_separator_inactive = cfg.icons.separatorInactive; )
icon_separator_visible = cfg.icons.separatorVisible; )
icons = cfg.icons.enable; // (
icon_custom_colors = cfg.icons.customColors; genAttrs
["alternate" "current" "inactive" "visible"]
insert_at_start = cfg.insertAtStart; (optionName: handleStateOption cfg.icons.${optionName})
insert_at_end = cfg.insertAtEnd; );
inherit (cfg) hide;
letters = cfg.letters; insert_at_end = cfg.insertAtEnd;
insert_at_start = cfg.insertAtStart;
maximum_padding = cfg.maximumPadding; maximum_padding = cfg.maximumPadding;
minimum_padding = cfg.minimumPadding; minimum_padding = cfg.minimumPadding;
maximum_length = cfg.maximumLength; maximum_length = cfg.maximumLength;
semantic_letters = cfg.semanticLetters;
no_name_title = cfg.noNameTitle; inherit (cfg) letters;
no_name_title = cfg.noNameTitle;
semantic_letters = cfg.semanticLetters; sidebar_filetypes = cfg.sidebarFiletypes;
}
tabpages = cfg.tabpages; // cfg.extraOptions;
};
userKeymapsList = userKeymapsList =
mapAttrsToList mapAttrsToList

View file

@ -20,59 +20,47 @@
# All the upstream default options of barbar # All the upstream default options of barbar
defaults = { defaults = {
plugins.barbar = { plugins.barbar = {
animations = true; enable = true;
animation = true;
autoHide = false; autoHide = false;
tabpages = true;
closable = true;
clickable = true; clickable = true;
diagnostics = {
error = {
enable = false;
icon = " ";
};
warn = {
enable = false;
icon = " ";
};
info = {
enable = false;
icon = " ";
};
hint = {
enable = false;
icon = "💡";
};
};
excludeFileTypes = []; excludeFileTypes = [];
excludeFileNames = []; excludeFileNames = [];
hide = { focusOnClose = "left";
extensions = false; hide = {};
inactive = false;
alternate = false;
current = false;
visible = false;
};
highlightAlternate = false; highlightAlternate = false;
highlightInactiveFileIcons = false; highlightInactiveFileIcons = false;
highlightVisible = true; highlightVisible = true;
icons = { icons = {
enable = true; bufferIndex = false;
customColors = false; bufferNumber = false;
separatorActive = ""; button = "";
separatorInactive = ""; diagnostics = {};
separatorVisible = ""; filetype = {enable = true;};
closeTab = ""; inactive = {
closeTabModified = ""; separator = {
pinned = ""; left = "";
right = "";
};
};
modified = {button = "";};
pinned = {button = "";};
separator = {
left = "";
right = "";
};
}; };
insertAtEnd = false; insertAtEnd = false;
insertAtStart = false; insertAtStart = false;
letters = "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP";
maximumLength = 30;
maximumPadding = 4; maximumPadding = 4;
minimumPadding = 1; minimumPadding = 1;
maximumLength = 30;
semanticLetters = true;
letters = "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP";
noNameTitle = null; noNameTitle = null;
semanticLetters = true;
sidebarFiletypes = {};
tabpages = true;
}; };
}; };
} }