From 954470581e9e10118cec9ea7a6759b5792e1a988 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 27 Apr 2024 02:25:55 +0300 Subject: [PATCH 01/12] tabline/bufferline: convert to setupOpts this is pretty much WIP and contains a bunch of bugs that I haven't tackled yet. --- .../tabline/nvim-bufferline/config.nix | 107 +----- .../nvim-bufferline/nvim-bufferline.nix | 318 +++++++++++++++++- 2 files changed, 335 insertions(+), 90 deletions(-) diff --git a/modules/plugins/tabline/nvim-bufferline/config.nix b/modules/plugins/tabline/nvim-bufferline/config.nix index 93b0f58..c52fb49 100644 --- a/modules/plugins/tabline/nvim-bufferline/config.nix +++ b/modules/plugins/tabline/nvim-bufferline/config.nix @@ -6,101 +6,30 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.binds) mkLuaBinding mkBinding pushDownDefault; inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.tabline.nvimBufferline; self = import ./nvim-bufferline.nix {inherit lib;}; inherit (self.options.vim.tabline.nvimBufferline) mappings; in { - config = mkIf cfg.enable ( - let - mouse = { - right = "'vertical sbuffer %d'"; - close = '' - function(bufnum) - require("bufdelete").bufdelete(bufnum, false) - end - ''; + config = mkIf cfg.enable { + vim = { + startPlugins = [ + (assert config.vim.visuals.nvimWebDevicons.enable; "nvim-bufferline-lua") + "bufdelete-nvim" + ]; + + binds.whichKey.register = pushDownDefault { + "b" = "+Buffer"; + "bm" = "BufferLineMove"; + "bs" = "BufferLineSort"; + "bsi" = "BufferLineSortById"; }; - in { - vim = { - startPlugins = [ - (assert config.vim.visuals.nvimWebDevicons.enable; "nvim-bufferline-lua") - "bufdelete-nvim" - ]; - maps.normal = mkMerge [ - (mkLuaBinding cfg.mappings.closeCurrent "require(\"bufdelete\").bufdelete" mappings.closeCurrent.description) - (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) - (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) - (mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev" mappings.cyclePrevious.description) - (mkBinding cfg.mappings.pick ":BufferLinePick" mappings.pick.description) - (mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension" mappings.sortByExtension.description) - (mkBinding cfg.mappings.sortByDirectory ":BufferLineSortByDirectory" mappings.sortByDirectory.description) - (mkLuaBinding cfg.mappings.sortById "function() require(\"bufferline\").sort_buffers_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end) end" mappings.sortById.description) - (mkBinding cfg.mappings.moveNext ":BufferLineMoveNext" mappings.moveNext.description) - (mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev" mappings.movePrevious.description) - ]; - - binds.whichKey.register = pushDownDefault { - "b" = "+Buffer"; - "bm" = "BufferLineMove"; - "bs" = "BufferLineSort"; - "bsi" = "BufferLineSortById"; - }; - - luaConfigRC.nvimBufferline = entryAnywhere '' - require("bufferline").setup{ - options = { - mode = "buffers", - numbers = "both", - close_command = ${mouse.close}, - right_mouse_command = ${mouse.right}, - indicator = { - style = 'icon', - indicator_icon = '▎', - }, - buffer_close_icon = '󰅖', - modified_icon = '●', - close_icon = '', - left_trunc_marker = '', - right_trunc_marker = '', - max_name_length = 18, - max_prefix_length = 15, - tab_size = 18, - show_buffer_icons = true, - show_buffer_close_icons = true, - show_close_icon = true, - show_tab_indicators = true, - persist_buffer_sort = true, - --separator_style = "thin", - separator_style = { " ", " " }, - enforce_regular_tabs = true, - always_show_bufferline = true, - offsets = { - {filetype = "NvimTree", text = "File Explorer", text_align = "center"} - }, - sort_by = 'extension', - diagnostics = "nvim_lsp", -- TODO: use coc if it's enabled - diagnostics_update_in_insert = true, - diagnostics_indicator = 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 "" ) - if(sym ~= "") then - s = s .. " " .. n .. sym - end - end - return s - end, - numbers = function(opts) - return string.format('%s·%s', opts.raise(opts.id), opts.lower(opts.ordinal)) - end, - } - } - ''; - }; - } - ); + luaConfigRC.nvimBufferline = entryAnywhere '' + require("bufferline").setup({options = ${toLuaObject cfg.setupOpts}}) + ''; + }; + }; } diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 6e2b87e..cc3f90f 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,6 +1,8 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption; + inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.types) enum bool either nullOr str int listOf; inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; in { options.vim.tabline.nvimBufferline = { enable = mkEnableOption "neovim bufferline"; @@ -16,5 +18,319 @@ in { moveNext = mkMappingOption "Move next buffer" "bmn"; movePrevious = mkMappingOption "Move previous buffer" "bmp"; }; + + setupOpts = mkPluginSetupOption "Bufferline-nvim" { + mode = mkOption { + type = enum ["tabs" "buffers"]; + default = "tabs"; + description = "Mode to use for bufferline"; + }; + + themable = mkOption { + type = bool; + default = true; + description = '' + Whether or not highlight groups to be overriden. + + While false, bufferline.nvim sets highlights as default + ''; + }; + + numbers = mkOption { + type = either (enum ["none" "ordinal" "buffer_id" "both"]) luaInline; + default = lib.generators.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"; + }; + + close_command = mkOption { + type = either str luaInline; + default = lib.generators.mkLuaInline '' + function(bufnum) + require("bufdelete").bufdelete(bufnum, false) + end + ''; + description = "Command to run when closing a buffer"; + }; + + right_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = "vertical sbuffer %d"; + description = "Command to run when right clicking a buffer"; + }; + + middle_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = null; + description = "Command to run when middle clicking a buffer"; + }; + + indicator = { + icon = mkOption { + type = nullOr str; + default = null; + description = '' + The indicatotor icon to use for current buffer. + + ::: {.warning} + This **must** be ommitted while style is not `icon` + ::: + ''; + }; + + style = mkOption { + type = enum ["icon" "underline" "none"]; + default = "underline"; + description = "Style for indicator"; + }; + }; + + buffer_close_icon = mkOption { + type = str; + default = " 󰅖 "; + description = "Icon for close button"; + }; + + modified_icon = mkOption { + type = str; + default = "● "; + description = "Icon for modified buffer"; + }; + + close_icon = mkOption { + type = str; + default = "  "; + description = "Icon for close button"; + }; + + left_trunc_marker = mkOption { + type = str; + default = ""; + description = "Icon for left truncation"; + }; + + right_trunc_marker = mkOption { + type = str; + default = ""; + description = "Icon for right truncation"; + }; + + name_formatter = mkOption { + type = nullOr luaInline; + default = null; + description = '' + `name_formatter` can be used to change the buffer's label in the + bufferline. + + ::: {.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. + ::: + ''; + }; + + max_name_length = mkOption { + type = int; + default = 18; + description = "Max name length"; + }; + + max_prefix_length = mkOption { + type = int; + default = 15; + description = "Length of prefix used when a buffer is de-duplicated"; + }; + + truncate_names = mkOption { + type = bool; + default = true; + description = "Truncate names"; + }; + + diagnostics = mkOption { + type = enum [false "nvim_lsp" "coc"]; + default = "nvim_lsp"; + description = "Diagnostics provider to be used in buffer LSP indicators"; + }; + + diagnostics_update_in_insert = mkOption { + type = bool; + default = false; + description = '' + Whether to update diagnostics while in insert mode. + + 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 = lib.generators.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 + ''; + + 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 lib.generators.mkLuaInline '' + custom_filter = function(buf_number, buf_numbers) + -- filter out filetypes you don't want to see + if vim.bo[buf_number].filetype ~= "" then + return true + end + -- filter out by buffer name + if vim.fn.bufname(buf_number) ~= "" 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() == "" 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 + ''; + + description = '' + Custom filter function for filtering out buffers. + + ::: {.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. + ::: + ''; + }; + + color_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to add filetype icon highlights"; + }; + + show_buffer_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to show buffer icons"; + }; + + show_buffer_close_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to show buffer close icons"; + }; + + show_close_icon = mkOption { + type = bool; + default = true; + description = "Whether or not to show close icon"; + }; + + show_tab_indicators = mkOption { + type = bool; + default = true; + description = "Whether or not to show tab indicators"; + }; + + show_duplicate_prefix = mkOption { + type = bool; + default = true; + description = "Whether or not to show duplicate prefix"; + }; + + duplicates_across_groups = mkOption { + type = bool; + default = true; + description = "Whether to consider duplicate paths in different groups as duplicates"; + }; + + persist_buffer_sort = mkOption { + type = bool; + default = true; + description = "Whether or not custom sorted buffers should persist"; + }; + + move_wraps_at_ends = mkOption { + type = bool; + default = false; + description = "Whether or not the move command \"wraps\" at the first or last position"; + }; + + seperator_style = mkOption { + type = either (enum ["thick" "thin" "slope" "slant"]) (listOf str); + default = [" " " "]; + description = '' + Style of the buffer separator. + + Can be either one of the suspported values, or a list containing + **at most** two elements for `focused` and `unfocused` respectively. + ''; + }; + + enforce_regular_tabs = mkOption { + type = bool; + default = false; + description = "Whether to enforce regular tabs"; + }; + + always_show_bufferline = mkOption { + type = bool; + default = true; + description = "Whether to always show bufferline"; + }; + + auto_toggle_bufferline = mkOption { + type = bool; + default = false; + description = "Whether to auto toggle bufferline"; + }; + + 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"; + }; + }; + + 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 valuees, or an inline Lua value."; + }; + }; }; } From 506b29c726505ea7a503d22702b8cafddee32909 Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:25:44 -0400 Subject: [PATCH 02/12] lib: avoid filtering null values to be used as nil --- lib/lua.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/lua.nix b/lib/lua.nix index 749e9a3..c4685bb 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -79,7 +79,10 @@ in rec { then toLuaObject v else "[${toLuaObject n}] = " + (toLuaObject v)) (filterAttrs - (_: v: v != null) + ( + _: v: + (v != null) && (toLuaObject v != "{}") + ) args))) + "}" else if isList args From c96181e7397ffd2460df16d2bb061880a3ad947e Mon Sep 17 00:00:00 2001 From: diniamo Date: Fri, 14 Jun 2024 10:52:44 +0200 Subject: [PATCH 03/12] tabline/bufferline: add missing options --- .../nvim-bufferline/nvim-bufferline.nix | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index cc3f90f..9ddb994 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,6 +1,7 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) enum bool either nullOr str int listOf; + 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 { @@ -26,6 +27,13 @@ in { description = "Mode to use for bufferline"; }; + 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"; + }; + themable = mkOption { type = bool; default = true; @@ -38,7 +46,7 @@ in { numbers = mkOption { type = either (enum ["none" "ordinal" "buffer_id" "both"]) luaInline; - default = lib.generators.mkLuaInline '' + default = mkLuaInline '' function(opts) return string.format('%s·%s', opts.raise(opts.id), opts.lower(opts.ordinal)) end @@ -48,7 +56,7 @@ in { close_command = mkOption { type = either str luaInline; - default = lib.generators.mkLuaInline '' + default = mkLuaInline '' function(bufnum) require("bufdelete").bufdelete(bufnum, false) end @@ -62,6 +70,12 @@ in { description = "Command to run when right clicking a buffer"; }; + left_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = "buffer %d"; + description = "Command to run when left clicking a buffer"; + }; + middle_mouse_command = mkOption { type = nullOr (either str luaInline); default = null; @@ -151,6 +165,12 @@ in { description = "Truncate names"; }; + tab_size = mkOption { + type = int; + default = 18; + description = "The size of the tabs in bufferline"; + }; + diagnostics = mkOption { type = enum [false "nvim_lsp" "coc"]; default = "nvim_lsp"; @@ -171,7 +191,7 @@ in { diagnostics_indicator = mkOption { type = nullOr luaInline; - default = lib.generators.mkLuaInline '' + default = mkLuaInline '' function(count, level, diagnostics_dict, context) local s = " " for e, n in pairs(diagnostics_dict) do @@ -195,7 +215,7 @@ in { custom_filter = mkOption { type = nullOr luaInline; default = null; - example = literalExpression lib.generators.mkLuaInline '' + example = literalExpression '' custom_filter = function(buf_number, buf_numbers) -- filter out filetypes you don't want to see if vim.bo[buf_number].filetype ~= "" then @@ -228,12 +248,37 @@ in { ''; }; + 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`"; + }; + color_icons = mkOption { type = bool; default = true; description = "Whether or not to add filetype icon highlights"; }; + 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."; + }; + show_buffer_icons = mkOption { type = bool; default = true; From 83b76322973d3affc0495f6b49435d8c66ebcd88 Mon Sep 17 00:00:00 2001 From: diniamo Date: Fri, 14 Jun 2024 11:20:10 +0200 Subject: [PATCH 04/12] tabline/bufferline: add back bindings --- modules/plugins/tabline/nvim-bufferline/config.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/plugins/tabline/nvim-bufferline/config.nix b/modules/plugins/tabline/nvim-bufferline/config.nix index c52fb49..aaacd33 100644 --- a/modules/plugins/tabline/nvim-bufferline/config.nix +++ b/modules/plugins/tabline/nvim-bufferline/config.nix @@ -9,7 +9,6 @@ inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.tabline.nvimBufferline; - self = import ./nvim-bufferline.nix {inherit lib;}; inherit (self.options.vim.tabline.nvimBufferline) mappings; in { @@ -20,6 +19,19 @@ in { "bufdelete-nvim" ]; + maps.normal = mkMerge [ + (mkLuaBinding cfg.mappings.closeCurrent "require(\"bufdelete\").bufdelete" mappings.closeCurrent.description) + (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) + (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) + (mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev" mappings.cyclePrevious.description) + (mkBinding cfg.mappings.pick ":BufferLinePick" mappings.pick.description) + (mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension" mappings.sortByExtension.description) + (mkBinding cfg.mappings.sortByDirectory ":BufferLineSortByDirectory" mappings.sortByDirectory.description) + (mkLuaBinding cfg.mappings.sortById "function() require(\"bufferline\").sort_buffers_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end) end" mappings.sortById.description) + (mkBinding cfg.mappings.moveNext ":BufferLineMoveNext" mappings.moveNext.description) + (mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev" mappings.movePrevious.description) + ]; + binds.whichKey.register = pushDownDefault { "b" = "+Buffer"; "bm" = "BufferLineMove"; From 415954595e9c7c2989b14a9bbf7552b4423c0f21 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 16 Jun 2024 18:31:41 +0200 Subject: [PATCH 05/12] lib/lua: picked wrong conflict version --- lib/lua.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/lua.nix b/lib/lua.nix index c4685bb..749e9a3 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -79,10 +79,7 @@ in rec { then toLuaObject v else "[${toLuaObject n}] = " + (toLuaObject v)) (filterAttrs - ( - _: v: - (v != null) && (toLuaObject v != "{}") - ) + (_: v: v != null) args))) + "}" else if isList args From 187d924509fbc5f394b4e5b61cb1a9a752f9d76e Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 19:01:41 +0200 Subject: [PATCH 06/12] tabline/bufferline: fix default mode --- modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 9ddb994..677607b 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -23,7 +23,7 @@ in { setupOpts = mkPluginSetupOption "Bufferline-nvim" { mode = mkOption { type = enum ["tabs" "buffers"]; - default = "tabs"; + default = "buffers"; description = "Mode to use for bufferline"; }; From c66854fc7ffe662b2f03968ecb97d749091ec3fc Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 19:47:13 +0200 Subject: [PATCH 07/12] tabline/bufferline: add separator_style --- .../tabline/nvim-bufferline/nvim-bufferline.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 677607b..94236aa 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,6 +1,6 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) enum bool either nullOr str int listOf attrs; + inherit (lib.types) enum bool either nullOr str int listOf attrs list; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; @@ -338,6 +338,16 @@ in { ''; }; + separator_style = mkOption { + type = enum ["slant" "slope" "thick" "thin" list]; + default = "thin"; + description = '' + The type of separator used to separate buffers and tabs. + + Either one of the listed types, or a list of 2 characters for either side. + ''; + }; + enforce_regular_tabs = mkOption { type = bool; default = false; From 42447cd3bf0f505c93dfe2e9c659edd5184e61ab Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 19:56:31 +0200 Subject: [PATCH 08/12] tabline/bufferline: add highlights --- .../tabline/nvim-bufferline/config.nix | 2 +- .../nvim-bufferline/nvim-bufferline.nix | 710 +++++++++--------- 2 files changed, 362 insertions(+), 350 deletions(-) diff --git a/modules/plugins/tabline/nvim-bufferline/config.nix b/modules/plugins/tabline/nvim-bufferline/config.nix index aaacd33..59363f8 100644 --- a/modules/plugins/tabline/nvim-bufferline/config.nix +++ b/modules/plugins/tabline/nvim-bufferline/config.nix @@ -40,7 +40,7 @@ in { }; luaConfigRC.nvimBufferline = entryAnywhere '' - require("bufferline").setup({options = ${toLuaObject cfg.setupOpts}}) + require("bufferline").setup(${toLuaObject cfg.setupOpts}) ''; }; }; diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 94236aa..90ae482 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -21,370 +21,382 @@ in { }; setupOpts = mkPluginSetupOption "Bufferline-nvim" { - mode = mkOption { - type = enum ["tabs" "buffers"]; - default = "buffers"; - description = "Mode to use for bufferline"; - }; - - 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"; - }; - - themable = mkOption { - type = bool; - default = true; - description = '' - Whether or not highlight groups to be overriden. - - While false, bufferline.nvim sets highlights as default - ''; - }; - - 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"; - }; - - close_command = mkOption { - type = either str luaInline; - default = mkLuaInline '' - function(bufnum) - require("bufdelete").bufdelete(bufnum, false) - end - ''; - description = "Command to run when closing a buffer"; - }; - - right_mouse_command = mkOption { - type = nullOr (either str luaInline); - default = "vertical sbuffer %d"; - description = "Command to run when right clicking a buffer"; - }; - - left_mouse_command = mkOption { - type = nullOr (either str luaInline); - default = "buffer %d"; - description = "Command to run when left clicking a buffer"; - }; - - middle_mouse_command = mkOption { - type = nullOr (either str luaInline); + highlights = mkOption { + type = either attrs luaInline; default = null; - description = "Command to run when middle clicking a buffer"; + description = '' + Overrides the highlight groups of bufferline. + + See `:help bufferline-highlights`. + ''; }; - indicator = { - icon = mkOption { - type = nullOr str; + options = { + mode = mkOption { + type = enum ["tabs" "buffers"]; + default = "buffers"; + description = "Mode to use for bufferline"; + }; + + 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"; + }; + + themable = mkOption { + type = bool; + default = true; + description = '' + Whether or not highlight groups to be overriden. + + While false, bufferline.nvim sets highlights as default + ''; + }; + + 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"; + }; + + close_command = mkOption { + type = either str luaInline; + default = mkLuaInline '' + function(bufnum) + require("bufdelete").bufdelete(bufnum, false) + end + ''; + description = "Command to run when closing a buffer"; + }; + + right_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = "vertical sbuffer %d"; + description = "Command to run when right clicking a buffer"; + }; + + left_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = "buffer %d"; + description = "Command to run when left clicking a buffer"; + }; + + middle_mouse_command = mkOption { + type = nullOr (either str luaInline); + default = null; + description = "Command to run when middle clicking a buffer"; + }; + + indicator = { + icon = mkOption { + type = nullOr str; + default = null; + description = '' + The indicatotor icon to use for current buffer. + + ::: {.warning} + This **must** be ommitted while style is not `icon` + ::: + ''; + }; + + style = mkOption { + type = enum ["icon" "underline" "none"]; + default = "underline"; + description = "Style for indicator"; + }; + }; + + buffer_close_icon = mkOption { + type = str; + default = " 󰅖 "; + description = "Icon for close button"; + }; + + modified_icon = mkOption { + type = str; + default = "● "; + description = "Icon for modified buffer"; + }; + + close_icon = mkOption { + type = str; + default = "  "; + description = "Icon for close button"; + }; + + left_trunc_marker = mkOption { + type = str; + default = ""; + description = "Icon for left truncation"; + }; + + right_trunc_marker = mkOption { + type = str; + default = ""; + description = "Icon for right truncation"; + }; + + name_formatter = mkOption { + type = nullOr luaInline; default = null; description = '' - The indicatotor icon to use for current buffer. + `name_formatter` can be used to change the buffer's label in the + bufferline. - ::: {.warning} - This **must** be ommitted while style is not `icon` + ::: {.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. ::: ''; }; - style = mkOption { - type = enum ["icon" "underline" "none"]; - default = "underline"; - description = "Style for indicator"; - }; - }; - - buffer_close_icon = mkOption { - type = str; - default = " 󰅖 "; - description = "Icon for close button"; - }; - - modified_icon = mkOption { - type = str; - default = "● "; - description = "Icon for modified buffer"; - }; - - close_icon = mkOption { - type = str; - default = "  "; - description = "Icon for close button"; - }; - - left_trunc_marker = mkOption { - type = str; - default = ""; - description = "Icon for left truncation"; - }; - - right_trunc_marker = mkOption { - type = str; - default = ""; - description = "Icon for right truncation"; - }; - - name_formatter = mkOption { - type = nullOr luaInline; - default = null; - description = '' - `name_formatter` can be used to change the buffer's label in the - bufferline. - - ::: {.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. - ::: - ''; - }; - - max_name_length = mkOption { - type = int; - default = 18; - description = "Max name length"; - }; - - max_prefix_length = mkOption { - type = int; - default = 15; - description = "Length of prefix used when a buffer is de-duplicated"; - }; - - truncate_names = mkOption { - type = bool; - default = true; - description = "Truncate names"; - }; - - tab_size = mkOption { - type = int; - default = 18; - description = "The size of the tabs in bufferline"; - }; - - diagnostics = mkOption { - type = enum [false "nvim_lsp" "coc"]; - default = "nvim_lsp"; - description = "Diagnostics provider to be used in buffer LSP indicators"; - }; - - diagnostics_update_in_insert = mkOption { - type = bool; - default = false; - description = '' - Whether to update diagnostics while in insert mode. - - 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 - ''; - - 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 ~= "" then - return true - end - -- filter out by buffer name - if vim.fn.bufname(buf_number) ~= "" 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() == "" 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 - ''; - - description = '' - Custom filter function for filtering out buffers. - - ::: {.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. - ::: - ''; - }; - - 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`"; - }; - - color_icons = mkOption { - type = bool; - default = true; - description = "Whether or not to add filetype icon highlights"; - }; - - 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."; - }; - - show_buffer_icons = mkOption { - type = bool; - default = true; - description = "Whether or not to show buffer icons"; - }; - - show_buffer_close_icons = mkOption { - type = bool; - default = true; - description = "Whether or not to show buffer close icons"; - }; - - show_close_icon = mkOption { - type = bool; - default = true; - description = "Whether or not to show close icon"; - }; - - show_tab_indicators = mkOption { - type = bool; - default = true; - description = "Whether or not to show tab indicators"; - }; - - show_duplicate_prefix = mkOption { - type = bool; - default = true; - description = "Whether or not to show duplicate prefix"; - }; - - duplicates_across_groups = mkOption { - type = bool; - default = true; - description = "Whether to consider duplicate paths in different groups as duplicates"; - }; - - persist_buffer_sort = mkOption { - type = bool; - default = true; - description = "Whether or not custom sorted buffers should persist"; - }; - - move_wraps_at_ends = mkOption { - type = bool; - default = false; - description = "Whether or not the move command \"wraps\" at the first or last position"; - }; - - seperator_style = mkOption { - type = either (enum ["thick" "thin" "slope" "slant"]) (listOf str); - default = [" " " "]; - description = '' - Style of the buffer separator. - - Can be either one of the suspported values, or a list containing - **at most** two elements for `focused` and `unfocused` respectively. - ''; - }; - - separator_style = mkOption { - type = enum ["slant" "slope" "thick" "thin" list]; - default = "thin"; - description = '' - The type of separator used to separate buffers and tabs. - - Either one of the listed types, or a list of 2 characters for either side. - ''; - }; - - enforce_regular_tabs = mkOption { - type = bool; - default = false; - description = "Whether to enforce regular tabs"; - }; - - always_show_bufferline = mkOption { - type = bool; - default = true; - description = "Whether to always show bufferline"; - }; - - auto_toggle_bufferline = mkOption { - type = bool; - default = false; - description = "Whether to auto toggle bufferline"; - }; - - hover = { - enabled = mkEnableOption "hover" // {default = true;}; - delay = mkOption { + max_name_length = mkOption { type = int; - default = 200; - description = "Delay for hover, in ms"; + default = 18; + description = "Max name length"; }; - reveal = mkOption { - type = listOf str; - default = ["close"]; - description = "Reveal hover window"; + max_prefix_length = mkOption { + type = int; + default = 15; + description = "Length of prefix used when a buffer is de-duplicated"; }; - }; - 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 valuees, or an inline Lua value."; + truncate_names = mkOption { + type = bool; + default = true; + description = "Truncate names"; + }; + + tab_size = mkOption { + type = int; + default = 18; + description = "The size of the tabs in bufferline"; + }; + + diagnostics = mkOption { + type = enum [false "nvim_lsp" "coc"]; + default = "nvim_lsp"; + description = "Diagnostics provider to be used in buffer LSP indicators"; + }; + + diagnostics_update_in_insert = mkOption { + type = bool; + default = false; + description = '' + Whether to update diagnostics while in insert mode. + + 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 + ''; + + 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 ~= "" then + return true + end + -- filter out by buffer name + if vim.fn.bufname(buf_number) ~= "" 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() == "" 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 + ''; + + description = '' + Custom filter function for filtering out buffers. + + ::: {.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. + ::: + ''; + }; + + 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`"; + }; + + color_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to add filetype icon highlights"; + }; + + 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."; + }; + + show_buffer_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to show buffer icons"; + }; + + show_buffer_close_icons = mkOption { + type = bool; + default = true; + description = "Whether or not to show buffer close icons"; + }; + + show_close_icon = mkOption { + type = bool; + default = true; + description = "Whether or not to show close icon"; + }; + + show_tab_indicators = mkOption { + type = bool; + default = true; + description = "Whether or not to show tab indicators"; + }; + + show_duplicate_prefix = mkOption { + type = bool; + default = true; + description = "Whether or not to show duplicate prefix"; + }; + + duplicates_across_groups = mkOption { + type = bool; + default = true; + description = "Whether to consider duplicate paths in different groups as duplicates"; + }; + + persist_buffer_sort = mkOption { + type = bool; + default = true; + description = "Whether or not custom sorted buffers should persist"; + }; + + move_wraps_at_ends = mkOption { + type = bool; + default = false; + description = "Whether or not the move command \"wraps\" at the first or last position"; + }; + + seperator_style = mkOption { + type = either (enum ["thick" "thin" "slope" "slant"]) (listOf str); + default = [" " " "]; + description = '' + Style of the buffer separator. + + Can be either one of the suspported values, or a list containing + **at most** two elements for `focused` and `unfocused` respectively. + ''; + }; + + separator_style = mkOption { + type = enum ["slant" "slope" "thick" "thin" list]; + default = "thin"; + description = '' + The type of separator used to separate buffers and tabs. + + Either one of the listed types, or a list of 2 characters for either side. + ''; + }; + + enforce_regular_tabs = mkOption { + type = bool; + default = false; + description = "Whether to enforce regular tabs"; + }; + + always_show_bufferline = mkOption { + type = bool; + default = true; + description = "Whether to always show bufferline"; + }; + + auto_toggle_bufferline = mkOption { + type = bool; + default = false; + description = "Whether to auto toggle bufferline"; + }; + + 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"; + }; + }; + + 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 valuees, or an inline Lua value."; + }; }; }; }; From 71064e88653cff23486d0a899206249d914c533c Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 19:58:14 +0200 Subject: [PATCH 09/12] tabline/bufferline: enable auto_toggle_bufferline by default This is due because this function is also used to show the bar intially. --- modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 90ae482..da270a8 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -395,7 +395,7 @@ in { 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 valuees, or an inline Lua value."; + description = "Method to sort buffers by. Must be one of the supported values, or an inline Lua value."; }; }; }; From 7df75f5b55e823ffd3779c7ef760bc007b7a2512 Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 20:03:09 +0200 Subject: [PATCH 10/12] tabline/bufferline: fix grammar mistakes --- .../tabline/nvim-bufferline/nvim-bufferline.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index da270a8..b7c52f7 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -49,9 +49,9 @@ in { type = bool; default = true; description = '' - Whether or not highlight groups to be overriden. + Whether or not to allow highlight groups to be overriden. - While false, bufferline.nvim sets highlights as default + While false, bufferline.nvim sets highlights as default. ''; }; @@ -98,7 +98,7 @@ in { type = nullOr str; default = null; description = '' - The indicatotor icon to use for current buffer. + The indicatotor icon to use for the current buffer. ::: {.warning} This **must** be ommitted while style is not `icon` @@ -167,7 +167,7 @@ in { max_prefix_length = mkOption { type = int; default = 15; - description = "Length of prefix used when a buffer is de-duplicated"; + description = "Length of the prefix used when a buffer is de-duplicated"; }; truncate_names = mkOption { @@ -305,7 +305,7 @@ in { show_close_icon = mkOption { type = bool; default = true; - description = "Whether or not to show close icon"; + description = "Whether or not to show the close icon"; }; show_tab_indicators = mkOption { @@ -317,7 +317,7 @@ in { show_duplicate_prefix = mkOption { type = bool; default = true; - description = "Whether or not to show duplicate prefix"; + description = "Whether or not to show duplicate buffer prefixes"; }; duplicates_across_groups = mkOption { @@ -373,7 +373,7 @@ in { auto_toggle_bufferline = mkOption { type = bool; - default = false; + default = true; description = "Whether to auto toggle bufferline"; }; From d9a62eff17f3c0a953dd7a65666def0cda608414 Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 20:19:47 +0200 Subject: [PATCH 11/12] fixup! tabline/bufferline: add separator_style --- modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index b7c52f7..785f150 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,6 +1,6 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) enum bool either nullOr str int listOf attrs list; + 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; @@ -350,7 +350,7 @@ in { }; separator_style = mkOption { - type = enum ["slant" "slope" "thick" "thin" list]; + type = nullOr (either (enum ["slant" "slope" "thick" "thin"]) (listOf str)); default = "thin"; description = '' The type of separator used to separate buffers and tabs. From dde2b5cac4ff6f12992fe21b574f349070464b60 Mon Sep 17 00:00:00 2001 From: diniamo Date: Sun, 16 Jun 2024 21:45:54 +0200 Subject: [PATCH 12/12] tabline/bufferline: add missing separator_style variations --- modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 785f150..e0f771d 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -350,7 +350,7 @@ in { }; separator_style = mkOption { - type = nullOr (either (enum ["slant" "slope" "thick" "thin"]) (listOf str)); + type = nullOr (either (enum ["slant" "padded_slant" "slope" "padded_slope" "thick" "thin"]) (listOf str)); default = "thin"; description = '' The type of separator used to separate buffers and tabs.