diff --git a/flake.lock b/flake.lock index 4abfca6..c5a1462 100644 --- a/flake.lock +++ b/flake.lock @@ -1021,6 +1021,22 @@ "type": "github" } }, + "plugin-nvim-cokeline": { + "flake": false, + "locked": { + "lastModified": 1715991329, + "narHash": "sha256-FXXh+a5hld9e1nW53S7vgumW4AD3bbMuewxmZyN+WvI=", + "owner": "willothy", + "repo": "nvim-cokeline", + "rev": "8145048ae68e05f31979c13b0adf7aa99f04f4c0", + "type": "github" + }, + "original": { + "owner": "willothy", + "repo": "nvim-cokeline", + "type": "github" + } + }, "plugin-nvim-colorizer-lua": { "flake": false, "locked": { @@ -1804,6 +1820,7 @@ "plugin-nvim-bufferline-lua": "plugin-nvim-bufferline-lua", "plugin-nvim-cmp": "plugin-nvim-cmp", "plugin-nvim-code-action-menu": "plugin-nvim-code-action-menu", + "plugin-nvim-cokeline": "plugin-nvim-cokeline", "plugin-nvim-colorizer-lua": "plugin-nvim-colorizer-lua", "plugin-nvim-cursorline": "plugin-nvim-cursorline", "plugin-nvim-dap": "plugin-nvim-dap", diff --git a/flake.nix b/flake.nix index 43fa890..62d2368 100644 --- a/flake.nix +++ b/flake.nix @@ -223,6 +223,12 @@ flake = false; }; + # Cokeline + plugin-nvim-cokeline = { + url = "github:willothy/nvim-cokeline"; + flake = false; + }; + # Statuslines plugin-lualine = { url = "github:hoob3rt/lualine.nvim"; diff --git a/modules/plugins/tabline/cokeline/cokeline.nix b/modules/plugins/tabline/cokeline/cokeline.nix new file mode 100644 index 0000000..f4e1a21 --- /dev/null +++ b/modules/plugins/tabline/cokeline/cokeline.nix @@ -0,0 +1,223 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.types) int bool str enum listOf nullOr; + inherit (lib.generators) mkLuaInline; +in { + options.vim.tabline.cokeline = { + enable = mkEnableOption "cokeline"; + + mappings = { + cycleNext = mkMappingOption "Next buffer" ""; + cyclePrevious = mkMappingOption "Previous buffer" ""; + pick = mkMappingOption "Pick buffer" "bc"; + switchNext = mkMappingOption "Switch with next buffer" "bmn"; + switchPrevious = mkMappingOption "Move previous buffer" "bmp"; + closeByLetter = mkMappingOption "Close buffer by letter" "bd"; + }; + + setupOpts = mkPluginSetupOption "Cokeline" { + show_if_buffers_are_at_least = mkOption { + description = "Only show the bufferline when there are at least this many visible buffers"; + type = int; + default = 0; + }; + + buffers = { + filter_valid = mkOption { + description = "Only show valid buffers in the bufferline"; + type = bool; + default = false; + }; + filter_visible = mkOption { + description = "Only show visible buffers in the bufferline"; + type = bool; + default = false; + }; + focus_on_delete = mkOption { + description = "Focus on buffer deletion"; + type = enum ["prev" "next"]; + default = "next"; + }; + new_buffers_position = mkOption { + description = "Position of new buffers"; + type = enum ["last" "next" "directory" "number"]; + default = "last"; + }; + delete_on_right_click = mkOption { + description = "Delete buffer on right click"; + type = bool; + default = true; + }; + }; + + mappings = { + cycle_prev_next = mkOption { + description = "If true, the last (first) buffer gets focused/switched, if false, nothing happens"; + type = bool; + default = true; + }; + disable_mouse = mkOption { + description = "Disable mouse mappings"; + type = bool; + default = false; + }; + }; + + history = { + enable = mkOption { + description = "Enable a history of focused buffers using a ringbuffer"; + type = bool; + default = true; + }; + size = mkOption { + description = "The maximum number of items to keep in the history"; + type = int; + default = 2; + }; + }; + + rendering = { + max_buffer_width = mkOption { + description = "The maximum number of characters a rendered buffer is allowed to take up. The buffer will be truncated if its width is bigger than this value."; + type = int; + default = 999; + }; + }; + + pick = { + use_filename = mkOption { + description = "Whether to use the filename's first letter first before picking a letter from the valid letters list in order."; + type = bool; + default = true; + }; + letters = mkOption { + description = "The list of letters that are valid as pick letters. Sorted by keyboard reachability by default, but may require tweaking for non-QWERTY keyboard layouts."; + type = str; + default = "asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERTYQP"; + }; + }; + + default_hl = { + fg = mkOption { + description = "The default foreground color for buffers"; + type = luaInline; + default = mkLuaInline '' + function(buffer) + return + buffer.is_focused + and vim.api.nvim_get_hl_by_name('Normal', true).foreground + or vim.api.nvim_get_hl_by_name('Comment', true).foreground + end + ''; + }; + bg = mkOption { + description = "The default background color for buffers"; + type = luaInline; + default = mkLuaInline '' + function(buffer) + return vim.api.nvim_get_hl_by_name('ColorColumn', true).background + end + ''; + }; + sp = mkOption { + description = "The default special key color for buffers"; + type = nullOr luaInline; + default = null; + }; + bold = mkOption { + description = "The default bold attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + italic = mkOption { + description = "The default italic attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + underline = mkOption { + description = "The default underline attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + undercurl = mkOption { + description = "The default undercurl attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + strikethrough = mkOption { + description = "The default strikethrough attribute for buffers"; + type = nullOr luaInline; + default = null; + }; + }; + + fill_hl = mkOption { + description = "The highlight group used to fill the tabline space"; + type = str; + default = "TabLineFill"; + }; + + tabs = { + placement = mkOption { + description = "The position of the tabline"; + type = enum ["left" "right"]; + default = "left"; + }; + }; + + sidebar = { + filetype = mkOption { + description = "The filetype of the sidebar"; + type = listOf str; + default = ["NvimTree" "neo-tree" "SidebarNvim"]; + }; + }; + + # components = mkOption { + # description = "The components to use in the tabline"; + # type = luaInline; + # default = mkLuaInline '' + # { + # { + # text = ' ', + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # }, + # { + # text = '', + # fg = vim.api.nvim_get_hl_by_name('ColorColumn', true).background, + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # }, + # { + # text = function(buffer) + # return buffer.devicon.icon + # end, + # fg = function(buffer) + # return buffer.devicon.color + # end, + # }, + # { + # text = ' ', + # }, + # { + # text = function(buffer) return buffer.filename .. ' ' end, + # style = function(buffer) + # return buffer.is_focused and 'bold' or nil + # end, + # }, + # { + # text = '', + # delete_buffer_on_left_click = true, + # }, + # { + # text = '', + # fg = vim.api.nvim_get_hl_by_name('ColorColumn', true).background, + # bg = vim.api.nvim_get_hl_by_name('Normal', true).background, + # } + # } + # ''; + # }; + }; + }; +} diff --git a/modules/plugins/tabline/cokeline/config.nix b/modules/plugins/tabline/cokeline/config.nix new file mode 100644 index 0000000..821a9f2 --- /dev/null +++ b/modules/plugins/tabline/cokeline/config.nix @@ -0,0 +1,46 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.binds) mkBinding pushDownDefault; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryAnywhere; + + cfg = config.vim.tabline.cokeline; + + self = import ./cokeline.nix {inherit lib;}; + inherit (self.options.vim.tabline.cokeline) mappings; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = [ + (assert config.vim.visuals.nvimWebDevicons.enable; "nvim-cokeline") + "bufdelete-nvim" + ]; + + maps.normal = mkMerge [ + (mkBinding cfg.mappings.cycleNext "(cokeline-focus-next)" mappings.cycleNext.description) + (mkBinding cfg.mappings.cyclePrevious "(cokeline-focus-prev)" mappings.cyclePrevious.description) + (mkBinding cfg.mappings.switchNext "(cokeline-switch-next)" mappings.switchNext.description) + (mkBinding cfg.mappings.switchPrevious "(cokeline-switch-prev)" mappings.switchPrevious.description) + # this does not work + # (mkBinding cfg.mappings.pick "(cokeline-pick-focus)" mappings.pick.description) + # (mkLuaBinding cfg.mappings.pick "function() require('cokeline.mappings').pick(\"focus\") end" mappings.pick.description) + # (mkBinding cfg.mappings.closeByLetter "(cokeline-pick-close)" mappings.closeByLetter.description) + ]; + + binds.whichKey.register = pushDownDefault { + "b" = "+Buffer"; + "bm" = "BufferLineMove"; + }; + + luaConfigRC = { + cokeline = entryAnywhere '' + require('cokeline').setup(${toLuaObject cfg.setupOpts}) + ''; + }; + }; + }; +} diff --git a/modules/plugins/tabline/cokeline/default.nix b/modules/plugins/tabline/cokeline/default.nix new file mode 100644 index 0000000..ab19972 --- /dev/null +++ b/modules/plugins/tabline/cokeline/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./cokeline.nix + ./config.nix + ]; +} diff --git a/modules/plugins/tabline/default.nix b/modules/plugins/tabline/default.nix index 5730dba..6290096 100644 --- a/modules/plugins/tabline/default.nix +++ b/modules/plugins/tabline/default.nix @@ -1,5 +1,6 @@ { imports = [ ./nvim-bufferline + ./cokeline ]; } diff --git a/modules/plugins/tabline/nvim-bufferline/config.nix b/modules/plugins/tabline/nvim-bufferline/config.nix index 93b0f58..4206130 100644 --- a/modules/plugins/tabline/nvim-bufferline/config.nix +++ b/modules/plugins/tabline/nvim-bufferline/config.nix @@ -32,7 +32,6 @@ in { 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)