plugins/telescope.extensions.undo: init + (#654)

* new plugin

* add content

* add content

* Update plugins/telescope/undo.nix

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>

* Update plugins/telescope/undo.nix

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>

* add test

* Update plugins/telescope/undo.nix

Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>

* fix per pr comments

* fix per pr comments

* fix per pr comments

---------

Co-authored-by: Haseeb Majid <haseeb.majid@imaginecurve.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
This commit is contained in:
Haseeb Majid 2023-10-25 22:08:23 +01:00 committed by GitHub
parent 0c5dcb56d1
commit 520a59668d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 172 additions and 0 deletions

View file

@ -15,6 +15,7 @@ in {
./fzy-native.nix
./media-files.nix
./project-nvim.nix
./undo.nix
];
# TODO:add support for aditional filetypes. This requires autocommands!

137
plugins/telescope/undo.nix Normal file
View file

@ -0,0 +1,137 @@
{
pkgs,
config,
lib,
...
}:
with lib; let
cfg = config.plugins.telescope.extensions.undo;
helpers = import ../helpers.nix {inherit lib;};
in {
options.plugins.telescope.extensions.undo = {
enable = mkEnableOption "undo";
package = helpers.mkPackageOption "telescope extension undo" pkgs.vimPlugins.telescope-undo-nvim;
useDelta = mkOption {
type = types.nullOr types.bool;
description = ''
When set to true, [delta](https://github.com/dandavison/delta) is used for fancy diffs in the preview section.
If set to false, `telescope-undo` will not use `delta` even when available and fall back to a plain diff with
treesitter highlights.
'';
default = true;
};
useCustomCommand = mkOption {
type = types.nullOr (types.listOf types.str);
description = ''
should be in this format: [ "bash" "-c" "echo '$DIFF' | delta" ]
'';
default = null;
};
sideBySide = mkOption {
type = types.nullOr types.bool;
description = ''
If set to true tells `delta` to render diffs side-by-side. Thus, requires `delta` to be
used. Be aware that `delta` always uses its own configuration, so it might be that you're getting
the side-by-side view even if this is set to false.
'';
default = false;
};
diffContextLines = mkOption {
type = with types;
either ints.unsigned str;
description = ''Defaults to the scrolloff'';
default = "vim.o.scrolloff";
};
entryFormat = mkOption {
type = types.nullOr types.str;
description = ''The format to show on telescope for the different versions of the file.'';
default = "state #$ID, $STAT, $TIME";
};
timeFormat = mkOption {
type = types.nullOr types.str;
description = ''
Can be set to a [Lua date format string](https://www.lua.org/pil/22.1.html).
'';
default = "";
};
mappings = {
i =
helpers.defaultNullOpts.mkNullable
(
with types;
attrsOf str
)
''
{
"<cr>" = "yank_additions";
"<s-cr>" = "yank_deletions";
"<c-cr>" = "restore";
}
''
"Keymaps in insert mode";
n =
helpers.defaultNullOpts.mkNullable
(
with types;
attrsOf str
)
''
{
"y" = "yank_additions";
"Y" = "yank_deletions";
"u" = "restore";
}
''
"Keymaps in normal mode";
};
};
config = let
configuration = with cfg; {
use_delta = useDelta;
use_custom_command = useCustomCommand;
side_by_side = sideBySide;
diff_context_lines =
if isInt diffContextLines
then helpers.mkRaw "diffContextLines"
else diffContextLines;
entry_format = entryFormat;
time_format = timeFormat;
mappings = with mappings; {
i =
helpers.ifNonNull' i
(
mapAttrs
(key: action:
helpers.mkRaw "require('telescope-undo.actions').${action}")
i
);
n =
helpers.ifNonNull' n
(
mapAttrs
(key: action:
helpers.mkRaw "require('telescope-undo.actions').${action}")
n
);
};
};
in
mkIf
cfg.enable
{
extraPlugins = [cfg.package];
plugins.telescope.enabledExtensions = ["undo"];
plugins.telescope.extensionConfig."undo" = configuration;
};
}

View file

@ -0,0 +1,34 @@
{
empty = {
plugins.telescope.enable = true;
};
example = {
plugins.telescope = {
enable = true;
extensions.undo = {
enable = true;
useDelta = true;
useCustomCommand = ["bash" "-c" "echo '$DIFF' | delta"];
sideBySide = true;
diffContextLines = 8;
entryFormat = "state #$ID";
timeFormat = "!%Y-%m-%dT%TZ";
mappings = {
i = {
"<cr>" = "yank_additions";
"<s-cr>" = "yank_deletions";
"<c-cr>" = "restore";
};
n = {
"y" = "yank_additions";
"Y" = "yank_deletions";
"u" = "restore";
};
};
};
};
};
}