Skip to content

Commit

Permalink
plugins/marks: init
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 16, 2024
1 parent 9e04eb3 commit e6f1af2
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
./utils/leap.nix
./utils/magma-nvim.nix
./utils/mark-radar.nix
./utils/marks.nix
./utils/mini.nix
./utils/mkdnflow.nix
./utils/molten.nix
Expand Down
186 changes: 186 additions & 0 deletions plugins/utils/marks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.plugins.marks;
in {
meta.maintainers = [maintainers.GaetanLepage];

options.plugins.marks =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "marks.nvim";

package = helpers.mkPackageOption "marks.nvim" pkgs.vimPlugins.marks-nvim;

builtinMarks = helpers.defaultNullOpts.mkListOf (types.enum ["'" "^" "." "<" ">"]) "[]" ''
Which builtin marks to track and show. If set, these marks will also show up in the
signcolumn and will update on `|CursorMoved|`.
'';

defaultMappings = helpers.defaultNullOpts.mkBool true ''
Whether to use the default plugin mappings or not.
See `|marks-mappings|` for more.
'';

signs = helpers.defaultNullOpts.mkBool true ''
Whether to show marks in the signcolumn or not.
If set to true, its recommended to also set `|signcolumn|` to "auto", for cases where
multiple marks are placed on the same line.
'';

cyclic = helpers.defaultNullOpts.mkBool true ''
Whether forward/backwards movement should cycle back to the beginning/end of buffer.
'';

forceWriteShada = helpers.defaultNullOpts.mkBool false ''
If true, then deleting global (uppercase) marks will also update the `|shada|` file
accordingly and force deletion of the mark permanently.
This option can be destructive and should be set only after reading more about the shada
file.
'';

refreshInterval = helpers.defaultNullOpts.mkUnsignedInt 150 ''
How often (in ms) `marks.nvim` should update the marks list and recompute mark
positions/redraw signs.
Lower values means that mark positions and signs will refresh much quicker, but may incur a
higher performance penalty, whereas higher values may result in better performance, but may
also cause noticable lag in signs updating.
'';

signPriority =
helpers.defaultNullOpts.mkNullable
(
with types;
either
ints.unsigned
(submodule {
freeformType = attrs;
options =
mapAttrs
(
name: desc:
helpers.mkNullOrOption ints.unsigned "Sign priority for ${desc}."
)
{
lower = "lowercase marks";
upper = "uppercase marks";
builtin = "builtin marks";
bookmark = "bookmarks";
};
})
) "10"
''
The sign priority to be used for marks.
Can either be a number, in which case the priority applies to all types of marks, or a
table with some or all of the following keys:
- lower: sign priority for lowercase marks
- upper: sign priority for uppercase marks
- builtin: sign priority for builtin marks
- bookmark: sign priority for bookmarks
'';

excludedFiletypes = helpers.defaultNullOpts.mkListOf types.str "[]" ''
Which filetypes to ignore.
If a buffer with this filetype is opened, then `marks.nvim` will not track any marks set in
this buffer, and will not display any signs.
Setting and moving to marks with ` or ' will still work, but movement commands like "m]" or
"m[" will not.
'';

excludedBuftypes = helpers.defaultNullOpts.mkListOf types.str "[]" ''
Which buftypes to ignore.
If a buffer with this buftype is opened, then `marks.nvim` will not track any marks set in
this buffer, and will not display any signs.
Setting and moving to marks with ` or ' will still work, but movement commands like "m]" or
"m[" will not.
'';

bookmarks = mkOption {
description = "Configuration table for each bookmark group (see `|marks-bookmarks|`).";
type = with types;
attrsOf (
submodule {
options = {
sign = helpers.mkNullOrOption (either str (enum [false])) ''
The character to use in the signcolumn for this bookmark group.
Defaults to "!@#$%^&*()" - in order from group 1 to 10.
Set to `false` to turn off signs for this bookmark.
'';

virtText = helpers.mkNullOrOption str ''
Virtual text annotations to place at the eol of a bookmark.
Defaults to `null`, meaning no virtual text.
'';

annotate = helpers.defaultNullOpts.mkBool false ''
When true, explicitly prompts the user for an annotation that will be displayed
above the bookmark.
'';
};
}
);
default = {};
apply = mapAttrs (_: v:
with v; {
inherit sign;
virt_text = virtText;
inherit annotate;
});
};

mappings = helpers.defaultNullOpts.mkAttrsOf (with types; either str (enum [false])) "{}" ''
Custom mappings.
Set a mapping to `false` to disable it.
'';
};

config = mkIf cfg.enable {
extraPlugins = [cfg.package];

assertions = [
{
assertion = all (n: elem n (range 0 9)) (attrNames cfg.bookmarks);
message = ''
Nixvim (plugins.marks): The keys of the `bookmarks` option should be integers between 0 and 9.
'';
}
];

extraConfigLua = let
bookmarks =
mapAttrs'
(
bookmarkNumber: bookmarkOptions:
nameValuePair "bookmark_${bookmarkNumber}" bookmarkOptions
)
cfg.bookmarks;

setupOptions = with cfg;
{
builtin_marks = builtinMarks;
default_mappings = defaultMappings;
inherit
signs
cyclic
;
force_write_shada = forceWriteShada;
refresh_interval = refreshInterval;
sign_priority = signPriority;
excluded_filetypes = excludedFiletypes;
excluded_buftypes = excludedBuftypes;
inherit mappings;
}
// bookmarks
// cfg.extraOptions;
in ''
require('marks').setup(${helpers.toLuaObject setupOptions})
'';
};
}
23 changes: 23 additions & 0 deletions tests/test-sources/plugins/utils/marks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
empty = {
plugins.marks.enable = true;
};

defaults = {
plugins.marks = {
enable = true;

builtinMarks = [];
defaultMappings = true;
signs = true;
cyclic = true;
forceWriteShada = false;
refreshInterval = 150;
signPriority = 10;
excludedFiletypes = [];
excludedBuftypes = [];
bookmarks = {};
mappings = {};
};
};
}

0 comments on commit e6f1af2

Please sign in to comment.