plugins/statuslines: move to by-name

This commit is contained in:
Matt Sturgeon 2024-09-05 02:42:01 +01:00
parent 82e7d153e4
commit d07a9c78cc
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
7 changed files with 0 additions and 4 deletions

View file

@ -0,0 +1,295 @@
{
lib,
helpers,
...
}:
with lib;
with helpers.vim-plugin;
mkVimPlugin {
name = "airline";
originalName = "vim-airline";
package = "vim-airline";
globalPrefix = "airline_";
maintainers = [ maintainers.GaetanLepage ];
# TODO introduced 2024-03-02: remove 2024-05-02
deprecateExtraConfig = true;
optionsRenamedToSettings = [
"sectionA"
"sectionB"
"sectionC"
"sectionX"
"sectionY"
"sectionZ"
"experimental"
"leftSep"
"rightSep"
"detectModified"
"detectPaste"
"detectCrypt"
"detectSpell"
"detectSpelllang"
"detectIminsert"
"inactiveCollapse"
"inactiveAltSep"
"theme"
"themePatchFunc"
"powerlineFonts"
"symbolsAscii"
"modeMap"
"excludeFilenames"
"excludeFiletypes"
"filetypeOverrides"
"excludePreview"
"disableStatusline"
"skipEmptySections"
"highlightingCache"
"focuslostInactive"
"statuslineOntop"
"stlPathStyle"
"sectionCOnlyFilename"
"symbols"
];
settingsOptions =
(listToAttrs (
map
(
name:
nameValuePair "section_${name}" (
helpers.mkNullOrOption (
with helpers.nixvimTypes;
oneOf [
rawLua
str
(listOf str)
(attrsOf anything)
]
) "Configuration for this section."
)
)
[
"a"
"b"
"c"
"x"
"y"
"z"
]
))
// {
experimental = helpers.defaultNullOpts.mkFlagInt 1 ''
Enable experimental features.
Currently: Enable Vim9 Script implementation.
'';
left_sep = helpers.defaultNullOpts.mkStr ">" ''
The separator used on the left side.
'';
right_sep = helpers.defaultNullOpts.mkStr "<" ''
The separator used on the right side.
'';
detect_modified = helpers.defaultNullOpts.mkFlagInt 1 ''
Enable modified detection.
'';
detect_paste = helpers.defaultNullOpts.mkFlagInt 1 ''
Enable paste detection.
'';
detect_crypt = helpers.defaultNullOpts.mkFlagInt 1 ''
Enable crypt detection.
'';
detect_spell = helpers.defaultNullOpts.mkFlagInt 1 ''
Enable spell detection.
'';
detect_spelllang =
helpers.defaultNullOpts.mkNullable
(
with helpers.nixvimTypes;
oneOf [
rawLua
intFlag
(enum [ "flag" ])
]
)
1
''
Display spelling language when spell detection is enabled (if enough space is
available).
Set to 'flag' to get a unicode icon of the relevant country flag instead of the
'spelllang' itself.
'';
detect_iminsert = helpers.defaultNullOpts.mkFlagInt 0 ''
Enable iminsert detection.
'';
inactive_collapse = helpers.defaultNullOpts.mkFlagInt 1 ''
Determine whether inactive windows should have the left section collapsed to only the
filename of that buffer.
'';
inactive_alt_sep = helpers.defaultNullOpts.mkFlagInt 1 ''
Use alternative separators for the statusline of inactive windows.
'';
theme = helpers.defaultNullOpts.mkStr "dark" ''
Themes are automatically selected based on the matching colorscheme.
This can be overridden by defining a value.
Note: Only the dark theme is distributed with vim-airline.
For more themes, checkout the vim-airline-themes repository
(https://github.com/vim-airline/vim-airline-themes)
'';
theme_patch_func = helpers.mkNullOrStr ''
If you want to patch the airline theme before it gets applied, you can supply the name of
a function where you can modify the palette.
Example: "AirlineThemePatch"
Then, define this function using `extraConfigVim`:
```nix
extraConfigVim = \'\'
function! AirlineThemePatch(palette)
if g:airline_theme == 'badwolf'
for colors in values(a:palette.inactive)
let colors[3] = 245
endfor
endif
endfunction
\'\';
```
'';
powerline_fonts = helpers.defaultNullOpts.mkFlagInt 0 ''
By default, airline will use unicode symbols if your encoding matches utf-8.
If you want the powerline symbols set this variable to `1`.
'';
symbols_ascii = helpers.defaultNullOpts.mkFlagInt 0 ''
By default, airline will use unicode symbols if your encoding matches utf-8.
If you want to use plain ascii symbols, set this variable: >
'';
mode_map = helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (attrsOf str)) ''
Define the set of text to display for each mode.
Default: see source
'';
exclude_filenames = helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (listOf str)) ''
Define the set of filename match queries which excludes a window from having its
statusline modified.
Default: see source for current list
'';
exclude_filetypes = helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (listOf str)) ''
Define the set of filetypes which are excluded from having its window statusline modified.
Default: see source for current list
'';
filetype_overrides =
helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (attrsOf (listOf str)))
''
Define the set of names to be displayed instead of a specific filetypes.
Example:
```nix
{
coc-explorer = ["CoC Explorer" ""];
defx = ["defx" "%{b:defx.paths[0]}"];
fugitive = ["fugitive" "%{airline#util#wrap(airline#extensions#branch#get_head(),80)}"];
gundo = ["Gundo" "" ];
help = ["Help" "%f"];
minibufexpl = ["MiniBufExplorer" ""];
startify = ["startify" ""];
vim-plug = ["Plugins" ""];
vimfiler = ["vimfiler" "%{vimfiler#get_status_string()}"];
vimshell = ["vimshell" "%{vimshell#get_status_string()}"];
vaffle = ["Vaffle" "%{b:vaffle.dir}"];
}
```
'';
exclude_preview = helpers.defaultNullOpts.mkFlagInt 0 ''
Defines whether the preview window should be excluded from having its window statusline
modified (may help with plugins which use the preview window heavily).
'';
disable_statusline = helpers.defaultNullOpts.mkFlagInt 0 ''
Disable the Airline statusline customization globally.
This setting disables setting the 'statusline' option.
This allows to use e.g. the tabline extension (`|airline-tabline|`) but keep the
'statusline' option totally configurable by a custom configuration.
'';
skip_empty_sections = helpers.defaultNullOpts.mkFlagInt 1 ''
Do not draw separators for empty sections (only for the active window).
'';
highlighting_cache = helpers.defaultNullOpts.mkFlagInt 0 ''
Caches the changes to the highlighting groups, should therefore be faster.
Set this to one, if you experience a sluggish Vim.
'';
focuslost_inactive = helpers.defaultNullOpts.mkFlagInt 0 ''
Disable airline on FocusLost autocommand (e.g. when Vim loses focus).
'';
statusline_ontop = helpers.defaultNullOpts.mkFlagInt 0 ''
Display the statusline in the tabline (first top line).
Setting this option, allows to use the statusline option to be used by a custom function
or another plugin, since airline won't change it.
Note: This setting is experimental and works on a best effort approach.
Updating the statusline might not always happen as fast as needed, but that is a
limitation, that comes from Vim.
airline tries to force an update if needed, but it might not always work as expected.
To force updating the tabline on mode changes, call `airline#check_mode()` in your custom
statusline setting: `:set stl=%!airline#check_mode(winnr())` will correctly update the
tabline on mode changes.
'';
stl_path_style = helpers.defaultNullOpts.mkStr "short" ''
Display a short path in statusline.
'';
section_c_only_filename = helpers.defaultNullOpts.mkFlagInt 1 ''
Display a only file name in statusline.
'';
symbols = helpers.mkNullOrOption (with types; attrsOf str) ''
Customize airline symbols.
Example:
```nix
{
branch = "";
colnr = " :";
readonly = "";
linenr = " :";
maxlinenr = " ";
dirty= "";
}
```
'';
};
settingsExample = {
powerline_fonts = 1;
theme = "base16";
skip_empty_sections = 1;
};
}

View file

@ -0,0 +1,216 @@
{
lib,
options,
...
}:
let
inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "lightline";
originalName = "lightline.vim";
package = "lightline-vim";
maintainers = [ lib.maintainers.khaneliman ];
description = ''
### Example of defining your own component_function
plugins.lightline = {
enable = true;
settings.component_function = {
readonly = "LightlineReadonly";
};
};
extraConfigLua = '''
function LightlineReadonly()
local is_readonly = vim.bo.readonly == 1
local filetype = vim.bo.filetype
if is_readonly and filetype ~= "help" then
return "RO"
else
return ""
end
end
''';
'';
# TODO: Added 2024-08-23, remove after 24.11
optionsRenamedToSettings = [
"colorscheme"
"componentFunction"
"component"
"active"
"inactive"
"modeMap"
];
settingsOptions = {
colorscheme = defaultNullOpts.mkStr "default" ''
The colorscheme to use for lightline.
Default theme is equal to `powerline`.
List of supported colorschemes can be found at
https://github.com/itchyny/lightline.vim/blob/master/colorscheme.md.
'';
component_function = defaultNullOpts.mkAttrsOf types.str { } ''
A list of function component definitions.
You can use the name of a function defined elsewhere.
'';
component =
defaultNullOpts.mkAttrsOf types.str
{
mode = ''%{lightline#mode()}'';
absolutepath = "%F";
relativepath = "%f";
filename = "%t";
modified = "%M";
bufnum = "%n";
paste = ''%{&paste?"PASTE"=""}'';
readonly = "%R";
charvalue = "%b";
charvaluehex = "%B";
fileencoding = ''%{&fenc!=#" "?&fenc=&enc}'';
fileformat = "%{&ff}";
filetype = ''%{&ft!=#""?&ft="no ft"}'';
percent = "%3p%%";
percentwin = "%P";
spell = ''%{&spell?&spelllang=" "}'';
lineinfo = "%3l=%-2c";
line = "%l";
column = "%c";
close = "%999X X ";
winnr = ''%{winnr()}'';
}
''
Lightline component definitions. Uses 'statusline' syntax.
Consult `:h 'statusline'` for a list of what's available.
'';
active =
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
{
left = [
[
"mode"
"paste"
]
[
"readonly"
"filename"
"modified"
]
];
right = [
[ "lineinfo" ]
[ "percent" ]
[
"fileformat"
"fileencoding"
"filetype"
]
];
}
''
Components placement for the active window.
'';
inactive =
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
{
left = [ "filename" ];
right = [
[ "lineinfo" ]
[ "percent" ]
];
}
''
Components placement for inactive windows.
'';
tabline =
defaultNullOpts.mkAttrsOf (with types; listOf (listOf str))
{
left = [ [ "tabs" ] ];
right = [ [ "close" ] ];
}
''
Components placement for tabline.
'';
tab = defaultNullOpts.mkAttrsOf (with types; listOf str) {
active = [
"tabnum"
"filename"
"modified"
];
inactive = [
"tabnum"
"filename"
"modified"
];
} ''A dictionary to store the tab components in each tabs.'';
mode_map =
defaultNullOpts.mkAttrsOf types.str
{
"n" = "NORMAL";
"i" = "INSERT";
"R" = "REPLACE";
"v" = "VISUAL";
"V" = "V-LINE";
"\<C-v>" = "V-BLOCK";
"c" = "COMMAND";
"s" = "SELECT";
"S" = "S-LINE";
"\<C-s>" = "S-BLOCK";
"t" = "TERMINAL";
}
''
Mode name mappings
'';
};
settingsExample = {
colorscheme = "one";
component_function = {
gitbranch = "FugitiveHead";
};
component = {
charvaluehex = "0x%B";
lineinfo = "%3l:%-2v%<";
};
active = {
right = [
[ "lineinfo" ]
[ "percent" ]
[
"fileformat"
"fileencoding"
"filetype"
"charvaluehex"
]
];
};
inactive = [ ];
mode_map = {
"n" = "N";
"i" = "I";
"v" = "V";
"<C-v>" = "VB";
"<C-s>" = "SB";
};
};
callSetup = false;
extraConfig = cfg: {
globals.lightline = lib.modules.mkAliasAndWrapDefsWithPriority lib.id options.plugins.lightline.settings;
};
}

View file

@ -0,0 +1,413 @@
{
lib,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts mkSettingsRenamedOptionModules;
inherit (lib) types;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "lualine";
originalName = "lualine.nvim";
package = "lualine-nvim";
maintainers = [ lib.maintainers.khaneliman ];
# TODO: Added 2024-09-05, remove after 24.11
optionsRenamedToSettings = [
"extensions"
"sections"
"inactiveSections"
"tabline"
"winbar"
"inactiveWinbar"
];
imports =
let
basePluginPath = [
"plugins"
"lualine"
];
settingsPath = basePluginPath ++ [ "settings" ];
optionsPath = settingsPath ++ [ "options" ];
oldOptions = [
"theme"
"globalstatus"
"refresh"
"iconsEnabled"
"sectionSeparators"
"componentSeparators"
"disabledFiletypes"
"ignoreFocus"
"alwaysDivideMiddle"
];
in
mkSettingsRenamedOptionModules basePluginPath optionsPath oldOptions;
settingsOptions =
let
mkSeparatorsOption =
{ left, right }:
defaultNullOpts.mkNullableWithRaw' {
description = ''
Filetypes in which to disable lualine.
Allows you to specify filetypes that you want to only disable on specific components.
'';
pluginDefault = {
inherit left right;
};
type =
with types;
either str (submodule {
freeformType = attrsOf anything;
options = {
left = defaultNullOpts.mkStr left "Left separator";
right = defaultNullOpts.mkStr right "Right separator";
};
});
};
# NOTE: This option is used for the shared component section definitions.
# We used to transform several options for the user to handle unkeying inside an attribute set and
# merging in undefined options into the final option. Now that we have freeformType support the user can
# manage this configuration exactly as the plugin expects without us transforming the values for them.
mkComponentOptions =
description:
lib.nixvim.mkNullOrOption' {
type =
with types;
let
# TODO: added 2024-09-05 remove after 24.11
oldAttrs = [
[ "name" ]
[
"icon"
"icon"
]
[ "extraConfig" ]
];
isOldType = x: lib.any (loc: lib.hasAttrByPath loc x) oldAttrs;
oldType = addCheck (attrsOf anything) isOldType // {
description = "attribute set containing ${lib.concatMapStringsSep ", " lib.showOption oldAttrs}";
};
coerceFn =
attrs:
lib.pipe attrs [
# Transform old `name` attr to `__unkeyed`
(
x:
if x ? name then
lib.removeAttrs x [ "name" ]
// {
__unkeyed-1 = x.name;
}
else
x
)
# Transform old `icon.icon` attr to `__unkeyed`
(
x:
if x.icon or null ? icon then
x
// {
icon = removeAttrs x.icon [ "icon" ] // {
__unkeyed-1 = x.icon.icon;
};
}
else
x
)
# Merge in old `extraConfig` attr
(x: removeAttrs x [ "extraConfig" ] // x.extraConfig or { })
];
newType = submodule {
freeformType = attrsOf anything;
options = {
icons_enabled = defaultNullOpts.mkBool true ''
Whether to display icons alongside the component.
'';
icon = lib.nixvim.mkNullOrOption' {
type = either str (attrsOf anything);
description = "The icon to be displayed in the component.";
};
separator = mkSeparatorsOption {
left = " ";
right = " ";
};
color = defaultNullOpts.mkNullable' {
type = either attrs str;
pluginDefault = lib.literalMD "The color defined by your theme, for the respective section & mode.";
description = "Defines a custom color for the component.";
};
padding = defaultNullOpts.mkNullable (oneOf [
int
(submodule {
# In case they add support for top/bottom padding
freeformType = attrsOf (maybeRaw int);
options = {
left = defaultNullOpts.mkInt null "Left padding.";
right = defaultNullOpts.mkInt null "Right padding.";
};
})
rawLua
]) 1 "Amount of padding added to components.";
fmt = lib.nixvim.mkNullOrLuaFn' {
description = ''
A lua function to format the component string.
'';
example = ''
function(text)
return text .. "!!!"
end
'';
};
};
};
in
maybeRaw (listOf (either str (lib.nixvim.transitionType oldType coerceFn (maybeRaw newType))));
inherit description;
};
mkEmptySectionOption = name: {
lualine_a = mkComponentOptions "Left section on left side.";
lualine_b = mkComponentOptions "Middle section on left side.";
lualine_c = mkComponentOptions "Right section on left side.";
lualine_x = mkComponentOptions "Left section on right side.";
lualine_y = mkComponentOptions "Middle section on right side.";
lualine_z = mkComponentOptions "Right section on right side.";
};
in
{
options = {
icons_enabled = defaultNullOpts.mkBool true ''
Whether to enable icons for all components.
This option is also available on individual components to control whether they should display icons.
'';
theme = defaultNullOpts.mkNullable (
with types; either str attrs
) "auto" "The theme to use for lualine-nvim.";
component_separators = mkSeparatorsOption {
left = "";
right = "";
};
section_separators = mkSeparatorsOption {
left = "";
right = "";
};
disabled_filetypes = defaultNullOpts.mkNullableWithRaw' {
description = ''
Filetypes in which to disable lualine.
Allows you to specify filetypes that you want to only disable on specific components.
'';
pluginDefault = { };
type =
with types;
either (listOf (maybeRaw str)) (submodule {
freeformType = attrsOf anything;
options = {
statusline = defaultNullOpts.mkListOf str [ ] ''
Hide the statusline component on specified filetypes.
'';
winbar = defaultNullOpts.mkListOf str [ ] ''
Hide the winbar component on specified filetypes.
'';
};
});
};
ignore_focus = defaultNullOpts.mkNullableWithRaw' {
type = types.listOf types.str;
pluginDefault = [ ];
description = ''
A list of filetypes that should always show an "unfocused" statusline.
If the focused window's filetype is in this list, then the most
recently focused window will be drawn as the active statusline.
'';
example = [
"neo-tree"
"nvim-tree"
"mini-files"
];
};
always_divide_middle = defaultNullOpts.mkBool true ''
Whether to prevent left sections i.e. 'a','b' and 'c' from taking over the entire statusline
even if neither of 'x', 'y' or 'z' are present.
'';
globalstatus = defaultNullOpts.mkBool false ''
Whether to enable "global" statusline.
I.e. having a single statusline at bottom of neovim, instead of one for each individual window.
'';
refresh = {
statusline = defaultNullOpts.mkInt 1000 "Refresh time for the status line (ms)";
tabline = defaultNullOpts.mkInt 1000 "Refresh time for the tabline (ms)";
winbar = defaultNullOpts.mkInt 1000 "Refresh time for the winbar (ms)";
};
};
sections = {
lualine_a = mkComponentOptions "mode";
lualine_b = mkComponentOptions "branch";
lualine_c = mkComponentOptions "filename";
lualine_x = mkComponentOptions "encoding";
lualine_y = mkComponentOptions "progress";
lualine_z = mkComponentOptions "location";
};
inactive_sections = {
lualine_a = mkComponentOptions "";
lualine_b = mkComponentOptions "";
lualine_c = mkComponentOptions "filename";
lualine_x = mkComponentOptions "location";
lualine_y = mkComponentOptions "";
lualine_z = mkComponentOptions "";
};
tabline = mkEmptySectionOption "Tabline configuration";
winbar = mkEmptySectionOption "Winbar configuration.";
inactive_winbar = mkEmptySectionOption "Winbar configuration used when inactive.";
extensions = defaultNullOpts.mkListOf (
with lib.types; either str (attrsOf anything)
) [ ] "List of enabled extensions.";
};
settingsExample = {
options = {
disabled_filetypes = {
__unkeyed-1 = "startify";
__unkeyed-2 = "neo-tree";
statusline = [
"dap-repl"
];
winbar = [
"aerial"
"dap-repl"
"neotest-summary"
];
};
globalstatus = true;
};
sections = {
lualine_a = [ "mode" ];
lualine_b = [ "branch" ];
lualine_c = [
"filename"
"diff"
];
lualine_x = [
"diagnostics"
{
__unkeyed-1.__raw = ''
function()
local msg = ""
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end
'';
icon = "";
color.fg = "#ffffff";
}
"encoding"
"fileformat"
"filetype"
];
lualine_y = [
{
__unkeyed-1 = "aerial";
cond.__raw = ''
function()
local buf_size_limit = 1024 * 1024
if vim.api.nvim_buf_get_offset(0, vim.api.nvim_buf_line_count(0)) > buf_size_limit then
return false
end
return true
end
'';
sep = " ) ";
depth.__raw = "nil";
dense = false;
dense_sep = ".";
colored = true;
}
];
lualine_z = [
{
__unkeyed-1 = "location";
}
];
};
tabline = {
lualine_a = [
{
__unkeyed-1 = "buffers";
symbols = {
alternate_file = "";
};
}
];
lualine_z = [ "tabs" ];
};
winbar = {
lualine_c = [
{
__unkeyed-1 = "navic";
}
];
lualine_x = [
{
__unkeyed-1 = "filename";
newfile_status = true;
path = 3;
shorting_target = 150;
}
];
};
};
extraOptions = {
gitPackage = lib.mkPackageOption pkgs "git" {
nullable = true;
};
};
extraConfig = cfg: {
extraPackages = [ cfg.gitPackage ];
};
}