Compare commits

...

12 commits

Author SHA1 Message Date
NotAShelf
1ce62335e1
Merge 852c862f05 into 57b5585372 2024-04-28 12:08:13 +02:00
57b5585372
Merge pull request #268 from jacekpoz/v0.6
fix: repair logo path in README
2024-04-27 17:53:24 +00:00
jacekpoz
293b290f2c
fix: repair logo path in README 2024-04-27 19:39:28 +02:00
8ad6233c41
Merge pull request #266 from horriblename/no-apply-lua-inline
Do not auto apply mkLuaInline
2024-04-27 15:48:24 +00:00
cc0617b4d6
Merge pull request #267 from horriblename/disable-neocord
Disable neocord by default
2024-04-27 15:47:27 +00:00
Ching Pei Yang
053ca39e10
docs: fix typo 2024-04-27 17:09:18 +02:00
Ching Pei Yang
a5594fd7a2 config: disable neocord 2024-04-27 17:00:30 +02:00
Ching Pei Yang
f0631c2d26 fidget: do not apply mkLuaInline to str opts 2024-04-27 16:09:27 +02:00
Ching Pei Yang
0c4f7a544d lib: fix crash on non-attrset arg 2024-04-27 16:09:27 +02:00
Ching Pei Yang
c220da2af9 fidget: remove ineffectful option
whether you set clear_on_detach to true or false you still get the
default behaviour
2024-04-27 16:09:27 +02:00
Frothy
852c862f05
lib: avoid filtering null values to be used as nil 2024-04-27 03:32:21 +03:00
3bd0243744
tabline/bufferline: convert to setupOpts
this is pretty much WIP and contains a bunch of bugs that I haven't tackled yet.
2024-04-27 03:31:37 +03:00
7 changed files with 360 additions and 140 deletions

2
.github/README.md vendored
View file

@ -1,5 +1,5 @@
<div align="center">
<img src=".github/assets/nvf-logo-work.svg" alt="nvf Logo" width="200">
<img src="assets/nvf-logo-work.svg" alt="nvf Logo" width="200">
</div>
<h1 align="center">❄️ nvf</h1>
<div align="center">

View file

@ -246,7 +246,7 @@ inputs: let
};
presence = {
neocord.enable = true;
neocord.enable = false;
};
};
};

View file

@ -18,7 +18,7 @@ should be documented with [Nixpkgs-flavoured Markdown](https://nixos.org/manual/
albeit with exceptions.
::: {.note}
As of **v0.5**, **vf** is itself documented using full markdown in both module
As of **v0.5**, **nvf** is itself documented using full markdown in both module
options and the manual. With **v0.6**, this manual has also been converted to
markdown in full.
:::

View file

@ -58,7 +58,7 @@ in rec {
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
luaTable = items: ''{${concatStringsSep "," items}}'';
isLuaInline = {_type ? null, ...}: _type == "lua-inline";
isLuaInline = object: (object._type or null) == "lua-inline";
toLuaObject = args:
if isAttrs args
@ -77,8 +77,7 @@ in rec {
else "[${toLuaObject n}] = " + (toLuaObject v))
(filterAttrs
(
_: v:
(v != null) && (toLuaObject v != "{}")
_: v: (toLuaObject v != "{}")
)
args)))
+ "}"

View file

@ -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 {
"<leader>b" = "+Buffer";
"<leader>bm" = "BufferLineMove";
"<leader>bs" = "BufferLineSort";
"<leader>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<CR>" mappings.cycleNext.description)
(mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext<CR>" mappings.cycleNext.description)
(mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev<CR>" mappings.cyclePrevious.description)
(mkBinding cfg.mappings.pick ":BufferLinePick<CR>" mappings.pick.description)
(mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension<CR>" mappings.sortByExtension.description)
(mkBinding cfg.mappings.sortByDirectory ":BufferLineSortByDirectory<CR>" 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<CR>" mappings.moveNext.description)
(mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev<CR>" mappings.movePrevious.description)
];
binds.whichKey.register = pushDownDefault {
"<leader>b" = "+Buffer";
"<leader>bm" = "BufferLineMove";
"<leader>bs" = "BufferLineSort";
"<leader>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}})
'';
};
};
}

View file

@ -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" "<leader>bmn";
movePrevious = mkMappingOption "Move previous buffer" "<leader>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 ~= "<i-dont-want-to-see-this>" then
return true
end
-- filter out by buffer name
if vim.fn.bufname(buf_number) ~= "<buffer-name-I-dont-want>" 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() == "<work-repo>" 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.";
};
};
};
}

View file

@ -7,8 +7,8 @@
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.attrsets) mapAttrs;
inherit (lib.strings) toUpper;
inherit (lib.types) int float bool str enum listOf attrsOf;
inherit (lib.nvim.types) mkPluginSetupOption;
inherit (lib.types) int float bool str enum listOf attrsOf anything;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.generators) mkLuaInline;
in {
imports = [
@ -42,30 +42,14 @@ in {
type = bool;
default = false;
};
clear_on_detach = mkOption {
description = "Clear notification group when LSP server detaches";
type = bool;
default = true;
apply = clear:
if clear
then
mkLuaInline ''
function(client_id)
local client = vim.lsp.get_client_by_id(client_id)
return client and client.name or nil
end
''
else null;
};
notification_group = mkOption {
description = "How to get a progress message's notification group key";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
function(msg)
return msg.lsp_client.name
end
'';
apply = mkLuaInline;
};
ignore = mkOption {
description = "Ignore LSP servers by name";
@ -172,33 +156,29 @@ in {
};
format_message = mkOption {
description = "How to format a progress message";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
require("fidget.progress.display").default_format_message
'';
apply = mkLuaInline;
};
format_annote = mkOption {
description = "How to format a progress annotation";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
function(msg) return msg.title end
'';
apply = mkLuaInline;
};
format_group_name = mkOption {
description = "How to format a progress notification group's name";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
function(group) return tostring(group) end
'';
apply = mkLuaInline;
};
overrides = mkOption {
description = "Override options from the default notification config";
type = attrsOf str;
default = {rust_analyzer = "{ name = 'rust-analyzer' }";};
apply = mapAttrs (key: lua: mkLuaInline lua);
type = attrsOf (attrsOf anything);
default = {rust_analyzer = {name = "rust-analyzer";};};
};
};
@ -240,21 +220,19 @@ in {
};
configs = mkOption {
description = "How to configure notification groups when instantiated";
type = attrsOf str;
default = {default = "require('fidget.notification').default_config";};
apply = mapAttrs (key: lua: mkLuaInline lua);
type = attrsOf luaInline;
default = {default = mkLuaInline "require('fidget.notification').default_config";};
};
redirect = mkOption {
description = "Conditionally redirect notifications to another backend";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
function(msg, level, opts)
if opts and opts.on_open then
return require("fidget.integration.nvim-notify").delegate(msg, level, opts)
end
end
'';
apply = mkLuaInline;
};
view = {
@ -280,13 +258,12 @@ in {
};
render_message = mkOption {
description = "How to render notification messages";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
function(msg, cnt)
return cnt == 1 and msg or string.format("(%dx) %s", cnt, msg)
end
'';
apply = mkLuaInline;
};
};
@ -386,11 +363,10 @@ in {
};
path = mkOption {
description = "Where Fidget writes its logs to";
type = str;
default = ''
type = luaInline;
default = mkLuaInline ''
string.format("%s/fidget.nvim.log", vim.fn.stdpath("cache"))
'';
apply = mkLuaInline;
};
};
};