From e80f2c92803c53472479794b3e06eb0bfb41f180 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 12 Mar 2024 03:47:41 +0300 Subject: [PATCH] modules/tabline: switch to explicit lib calls --- modules/tabline/default.nix | 2 +- modules/tabline/nvim-bufferline/config.nix | 159 +++++++++--------- modules/tabline/nvim-bufferline/default.nix | 2 +- .../nvim-bufferline/nvim-bufferline.nix | 5 +- 4 files changed, 86 insertions(+), 82 deletions(-) diff --git a/modules/tabline/default.nix b/modules/tabline/default.nix index 539302e..5730dba 100644 --- a/modules/tabline/default.nix +++ b/modules/tabline/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-bufferline ]; diff --git a/modules/tabline/nvim-bufferline/config.nix b/modules/tabline/nvim-bufferline/config.nix index befafcd..93b0f58 100644 --- a/modules/tabline/nvim-bufferline/config.nix +++ b/modules/tabline/nvim-bufferline/config.nix @@ -3,13 +3,14 @@ lib, ... }: let - inherit (lib) mkIf mkMerge mkLuaBinding mkBinding nvim pushDownDefault; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.binds) mkLuaBinding mkBinding pushDownDefault; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.tabline.nvimBufferline; - self = import ./nvim-bufferline.nix { - inherit lib; - }; - mappings = self.options.vim.tabline.nvimBufferline.mappings; + + self = import ./nvim-bufferline.nix {inherit lib;}; + inherit (self.options.vim.tabline.nvimBufferline) mappings; in { config = mkIf cfg.enable ( let @@ -22,82 +23,84 @@ in { ''; }; in { - vim.startPlugins = [ - (assert config.vim.visuals.nvimWebDevicons.enable == true; "nvim-bufferline-lua") - "bufdelete-nvim" - ]; + vim = { + startPlugins = [ + (assert config.vim.visuals.nvimWebDevicons.enable; "nvim-bufferline-lua") + "bufdelete-nvim" + ]; - vim.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) - ]; + 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) + ]; - vim.binds.whichKey.register = pushDownDefault { - "b" = "+Buffer"; - "bm" = "BufferLineMove"; - "bs" = "BufferLineSort"; - "bsi" = "BufferLineSortById"; + 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, + } + } + ''; }; - - vim.luaConfigRC.nvimBufferline = nvim.dag.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, - } - } - ''; } ); } diff --git a/modules/tabline/nvim-bufferline/default.nix b/modules/tabline/nvim-bufferline/default.nix index 8fe4868..9f31874 100644 --- a/modules/tabline/nvim-bufferline/default.nix +++ b/modules/tabline/nvim-bufferline/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-bufferline.nix ./config.nix diff --git a/modules/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/tabline/nvim-bufferline/nvim-bufferline.nix index 1ca3ff0..6e2b87e 100644 --- a/modules/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,8 +1,9 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.tabline.nvimBufferline = { - enable = mkEnableOption "nvim-bufferline-lua as a bufferline"; + enable = mkEnableOption "neovim bufferline"; mappings = { closeCurrent = mkMappingOption "Close buffer" null;