From 6a414ea2cd44687c8f1f5004d24975d777a4bfc1 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 3 Mar 2024 00:07:12 +0100 Subject: [PATCH] plugins/airline: switch to settings option --- plugins/colorschemes/base16.nix | 2 +- plugins/statuslines/airline.nix | 508 ++++++++---------- .../plugins/statuslines/airline.nix | 140 ++--- 3 files changed, 291 insertions(+), 359 deletions(-) diff --git a/plugins/colorschemes/base16.nix b/plugins/colorschemes/base16.nix index 736ee86e..16614895 100644 --- a/plugins/colorschemes/base16.nix +++ b/plugins/colorschemes/base16.nix @@ -99,7 +99,7 @@ in { colorscheme = mkIf (cfg.colorscheme != null) "base16-${cfg.colorscheme}"; extraPlugins = [cfg.package]; - plugins.airline.theme = mkIf cfg.setUpBar "base16"; + plugins.airline.settings.theme = mkIf cfg.setUpBar "base16"; plugins.lualine.theme = mkIf cfg.setUpBar "base16"; plugins.lightline.colorscheme = null; diff --git a/plugins/statuslines/airline.nix b/plugins/statuslines/airline.nix index 7e1303b5..83d04233 100644 --- a/plugins/statuslines/airline.nix +++ b/plugins/statuslines/airline.nix @@ -12,242 +12,219 @@ with helpers.vim-plugin; originalName = "vim-airline"; defaultPackage = pkgs.vimPlugins.vim-airline; globalPrefix = "airline_"; - deprecateExtraConfig = true; maintainers = [maintainers.GaetanLepage]; - options = + # 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${toUpper name}" - (mkDefaultOpt { - global = "section_${name}"; - type = with types; - oneOf - [ - str - (listOf str) - (attrsOf anything) - ]; - description = "Configuration for this section."; - }) + "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 = mkDefaultOpt { - description = '' - Enable experimental features. - Currently: Enable Vim9 Script implementation. + experimental = helpers.defaultNullOpts.mkBool true '' + Enable experimental features. + Currently: Enable Vim9 Script implementation. + ''; - Default: `true` - ''; - type = types.bool; - }; + left_sep = helpers.defaultNullOpts.mkStr ">" '' + The separator used on the left side. + ''; - leftSep = mkDefaultOpt { - global = "left_sep"; - description = '' - The separator used on the left side. + right_sep = helpers.defaultNullOpts.mkStr "<" '' + The separator used on the right side. + ''; - Default: ">" - ''; - type = types.str; - }; + detect_modified = helpers.defaultNullOpts.mkBool true '' + Enable modified detection. + ''; - rightSep = mkDefaultOpt { - global = "right_sep"; - description = '' - The separator used on the right side. + detect_paste = helpers.defaultNullOpts.mkBool true '' + Enable paste detection. + ''; - Default: "<" - ''; - type = types.str; - }; + detect_crypt = helpers.defaultNullOpts.mkBool true '' + Enable crypt detection. + ''; - detectModified = mkDefaultOpt { - global = "detect_modified"; - description = '' - Enable modified detection. + detect_spell = helpers.defaultNullOpts.mkBool true '' + Enable spell detection. + ''; - Default: `true` - ''; - type = types.bool; - }; - - detectPaste = mkDefaultOpt { - global = "detect_paste"; - description = '' - Enable paste detection. - - Default: `true` - ''; - type = types.bool; - }; - - detectCrypt = mkDefaultOpt { - global = "detect_crypt"; - description = '' - Enable crypt detection. - - Default: `true` - ''; - type = types.bool; - }; - - detectSpell = mkDefaultOpt { - global = "detect_spell"; - description = '' - Enable spell detection. - - Default: `true` - ''; - type = types.bool; - }; - - detectSpelllang = mkDefaultOpt { - global = "detect_spelllang"; - description = '' - Display spelling language when spell detection is enabled (if enough space is available). + detect_spelllang = + helpers.defaultNullOpts.mkNullable + ( + with helpers.nixvimTypes; + oneOf [ + rawLua + bool + (enum ["flag"]) + ] + ) + "true" + '' + 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. - - Default: `true` ''; - type = with types; either bool (enum ["flag"]); - }; - detectIminsert = mkDefaultOpt { - global = "detect_iminsert"; - description = '' - Enable iminsert detection. + detect_iminsert = helpers.defaultNullOpts.mkBool false '' + Enable iminsert detection. + ''; - Default: `false` - ''; - type = types.bool; - }; + inactive_collapse = helpers.defaultNullOpts.mkBool true '' + Determine whether inactive windows should have the left section collapsed to only the + filename of that buffer. + ''; - inactiveCollapse = mkDefaultOpt { - global = "inactive_collapse"; - description = '' - Determine whether inactive windows should have the left section collapsed to only the - filename of that buffer. + inactive_alt_sep = helpers.defaultNullOpts.mkBool true '' + Use alternative separators for the statusline of inactive windows. + ''; - Default: `true` - ''; - type = types.bool; - }; + theme = helpers.defaultNullOpts.mkStr "dark" '' + Themes are automatically selected based on the matching colorscheme. + This can be overridden by defining a value. - inactiveAltSep = mkDefaultOpt { - global = "inactive_alt_sep"; - description = '' - Use alternative separators for the statusline of inactive windows. + 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) + ''; - Default: `true` - ''; - type = types.bool; - }; + 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. - theme = mkDefaultOpt { - description = '' - Themes are automatically selected based on the matching colorscheme. - This can be overridden by defining a value. + Example: "AirlineThemePatch" - 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) + 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 + \'\'; + ``` + ''; - Default: "dark" - ''; - type = types.str; - }; + powerline_fonts = helpers.defaultNullOpts.mkBool false '' + By default, airline will use unicode symbols if your encoding matches utf-8. + If you want the powerline symbols set this variable to `true`. + ''; - themePatchFunc = mkDefaultOpt { - global = "theme_patch_func"; - description = '' - 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. + symbols_ascii = helpers.defaultNullOpts.mkBool false '' + By default, airline will use unicode symbols if your encoding matches utf-8. + If you want to use plain ascii symbols, set this variable: > + ''; - 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 - \'\'; - ``` - ''; - type = types.str; - }; - - powerlineFonts = mkDefaultOpt { - global = "powerline_fonts"; - description = '' - By default, airline will use unicode symbols if your encoding matches utf-8. - If you want the powerline symbols set this variable to `true`. - - Default: `false` - ''; - type = types.bool; - }; - - symbolsAscii = mkDefaultOpt { - global = "symbols_ascii"; - description = '' - By default, airline will use unicode symbols if your encoding matches utf-8. - If you want to use plain ascii symbols, set this variable: > - - Default: `false` - ''; - type = types.bool; - }; - - modeMap = mkDefaultOpt { - global = "mode_map"; - description = '' + mode_map = + helpers.mkNullOrOption + ( + with helpers.nixvimTypes; + maybeRaw (attrsOf str) + ) + '' Define the set of text to display for each mode. Default: see source ''; - type = with types; attrsOf str; - }; - excludeFilenames = mkDefaultOpt { - global = "exclude_filenames"; - description = '' + 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 ''; - type = with types; listOf str; - }; - excludeFiletypes = mkDefaultOpt { - global = "exclude_filetypes"; - description = '' + 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 ''; - type = with types; listOf str; - }; - filetypeOverrides = mkDefaultOpt { - global = "filetype_overrides"; - description = '' + 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: @@ -267,123 +244,76 @@ with helpers.vim-plugin; } ``` ''; - type = with types; attrsOf (listOf str); - }; - excludePreview = mkDefaultOpt { - global = "exclude_filenames"; - description = '' - Defines whether the preview window should be excluded from having its window statusline - modified (may help with plugins which use the preview window heavily). + exclude_preview = helpers.defaultNullOpts.mkBool false '' + Defines whether the preview window should be excluded from having its window statusline + modified (may help with plugins which use the preview window heavily). + ''; - Default: `false` - ''; - type = types.bool; - }; + disable_statusline = helpers.defaultNullOpts.mkBool false '' + Disable the Airline statusline customization globally. - disableStatusline = mkDefaultOpt { - global = "disable_statusline"; - description = '' - 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. + ''; - 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.mkBool true '' + Do not draw separators for empty sections (only for the active window). + ''; - Default: `false` - ''; - type = types.bool; - }; + highlighting_cache = helpers.defaultNullOpts.mkBool false '' + Caches the changes to the highlighting groups, should therefore be faster. + Set this to one, if you experience a sluggish Vim. + ''; - skipEmptySections = mkDefaultOpt { - global = "skip_empty_sections"; - description = '' - Do not draw separators for empty sections (only for the active window). + focuslost_inactive = helpers.defaultNullOpts.mkBool false '' + Disable airline on FocusLost autocommand (e.g. when Vim loses focus). + ''; - Default: `true` - ''; - type = types.bool; - }; + statusline_ontop = helpers.defaultNullOpts.mkBool false '' + Display the statusline in the tabline (first top line). - highlightingCache = mkDefaultOpt { - global = "highlighting_cache"; - description = '' - Caches the changes to the highlighting groups, should therefore be faster. - Set this to one, if you experience a sluggish Vim. + 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. - Default: `false` - ''; - type = types.bool; - }; + 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. + ''; - focuslostInactive = mkDefaultOpt { - global = "focuslost_inactive"; - description = '' - Disable airline on FocusLost autocommand (e.g. when Vim loses focus). + stl_path_style = helpers.defaultNullOpts.mkStr "short" '' + Display a short path in statusline. + ''; - Default: `false` - ''; - type = types.bool; - }; + section_c_only_filename = helpers.defaultNullOpts.mkBool true '' + Display a only file name in statusline. + ''; - statuslineOntop = mkDefaultOpt { - global = "statusline_ontop"; - description = '' - Display the statusline in the tabline (first top line). + symbols = helpers.mkNullOrOption (with types; attrsOf str) '' + Customize airline symbols. - 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. - - Default: `false` - ''; - type = types.bool; - }; - - stlPathStyle = mkDefaultOpt { - global = "stl_path_style"; - description = '' - Display a short path in statusline. - - Default: "short" - ''; - type = types.str; - }; - - sectionCOnlyFilename = mkDefaultOpt { - global = "section_c_only_filename"; - description = '' - Display a only file name in statusline. - - Default: `true` - ''; - type = types.bool; - }; - - symbols = mkDefaultOpt { - description = '' - Customize airline symbols. - - Example: - ```nix - { - branch = ""; - colnr = " ℅:"; - readonly = ""; - linenr = " :"; - maxlinenr = "☰ "; - dirty= "⚡"; - } - ``` - ''; - type = with types; attrsOf str; - }; + Example: + ```nix + { + branch = ""; + colnr = " ℅:"; + readonly = ""; + linenr = " :"; + maxlinenr = "☰ "; + dirty= "⚡"; + } + ``` + ''; }; + + settingsExample = { + powerline_fonts = true; + theme = "base16"; + skip_empty_sections = true; + }; } diff --git a/tests/test-sources/plugins/statuslines/airline.nix b/tests/test-sources/plugins/statuslines/airline.nix index 3f89c883..943b77dd 100644 --- a/tests/test-sources/plugins/statuslines/airline.nix +++ b/tests/test-sources/plugins/statuslines/airline.nix @@ -7,75 +7,77 @@ plugins.airline = { enable = true; - sectionA = "foo"; - sectionB = "foo"; - sectionC = "foo"; - sectionX = "foo"; - sectionY = "foo"; - sectionZ = "foo"; - experimental = true; - leftSep = ">"; - rightSep = "<"; - detectModified = true; - detectPaste = true; - detectCrypt = true; - detectSpell = true; - detectSpelllang = true; - detectIminsert = false; - inactiveCollapse = true; - inactiveAltSep = true; - theme = "dark"; - themePatchFunc = null; - powerlineFonts = false; - symbolsAscii = false; - modeMap = { - __ = "-"; - c = "C"; - i = "I"; - ic = "I"; - ix = "I"; - n = "N"; - multi = "M"; - ni = "N"; - no = "N"; - R = "R"; - Rv = "R"; - s = "S"; - S = "S"; - t = "T"; - v = "V"; - V = "V"; - }; - excludeFilenames = []; - excludeFiletypes = []; - filetypeOverrides = { - 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}"]; - }; - excludePreview = false; - disableStatusline = false; - skipEmptySections = true; - highlightingCache = false; - focuslostInactive = false; - statuslineOntop = false; - stlPathStyle = "short"; - sectionCOnlyFilename = true; - symbols = { - branch = ""; - colnr = " ℅:"; - readonly = ""; - linenr = " :"; - maxlinenr = "☰ "; - dirty = "⚡"; + settings = { + section_a = "foo"; + section_b = "foo"; + section_c = "foo"; + section_x = "foo"; + section_y = "foo"; + section_z = "foo"; + experimental = true; + left_sep = ">"; + right_sep = "<"; + detect_modified = true; + detect_paste = true; + detect_crypt = true; + detect_spell = true; + detect_spelllang = true; + detect_iminsert = false; + inactive_collapse = true; + inactive_alt_sep = true; + theme = "dark"; + theme_patch_func = null; + powerline_fonts = false; + symbols_ascii = false; + mode_map = { + __ = "-"; + c = "C"; + i = "I"; + ic = "I"; + ix = "I"; + n = "N"; + multi = "M"; + ni = "N"; + no = "N"; + R = "R"; + Rv = "R"; + s = "S"; + S = "S"; + t = "T"; + v = "V"; + V = "V"; + }; + exclude_filenames = []; + exclude_filetypes = []; + filetype_overrides = { + 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 = false; + disable_statusline = false; + skip_empty_sections = true; + highlighting_cache = false; + focuslost_inactive = false; + statusline_ontop = false; + stl_path_style = "short"; + section_c_only_filename = true; + symbols = { + branch = ""; + colnr = " ℅:"; + readonly = ""; + linenr = " :"; + maxlinenr = "☰ "; + dirty = "⚡"; + }; }; }; };