Skip to content

Commit 2b03933

Browse files
committed
plugins/clipboard-image: migrate to mkneovimplugin
1 parent 3aabd32 commit 2b03933

File tree

3 files changed

+139
-140
lines changed

3 files changed

+139
-140
lines changed
Lines changed: 86 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,117 @@
11
{
22
lib,
3-
helpers,
4-
config,
53
pkgs,
64
...
75
}:
8-
with lib;
96
let
10-
cfg = config.plugins.clipboard-image;
11-
12-
pluginOptions = {
13-
imgDir =
14-
helpers.defaultNullOpts.mkNullable
15-
(
16-
with lib.types;
17-
oneOf [
18-
str
19-
(listOf str)
20-
rawLua
21-
]
22-
)
23-
"img"
24-
''
25-
Dir name where the image will be pasted to.
26-
27-
Note: If you want to create nested dir, it is better to use table since windows and unix
28-
have different path separator.
29-
'';
30-
31-
imgDirTxt = helpers.defaultNullOpts.mkNullable (
32-
with lib.types;
33-
oneOf [
34-
str
35-
(listOf str)
36-
rawLua
37-
]
38-
) "img" "Dir that will be inserted into text/buffer.";
39-
40-
imgName = helpers.defaultNullOpts.mkStr {
41-
__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
42-
} "Image's name.";
43-
44-
imgHandler = helpers.defaultNullOpts.mkLuaFn "function(img) end" ''
45-
Function that will handle image after pasted.
46-
47-
Note: `img` is a table that contain pasted image's `{name}` and `{path}`.
48-
'';
49-
50-
affix = helpers.mkNullOrStr ''
51-
String that sandwiched the image's path.
52-
53-
Default:
54-
- `default`: `"{img_path}"`
55-
- `markdown`: `"![]({img_path})"`
56-
57-
Note:
58-
Affix can be multi lines, like this:
59-
60-
```nix
61-
# You can use line break escape sequence
62-
affix = "<\n %s\n>";
63-
```
64-
65-
```nix
66-
# Or lua's double square brackets
67-
affix.__raw = \'\'
68-
[[<
69-
%s
70-
>]]
71-
\'\'
72-
```
73-
'';
74-
};
75-
76-
processPluginOptions =
77-
opts: with opts; {
78-
img_dir = imgDir;
79-
img_dir_txt = imgDirTxt;
80-
img_name = imgName;
81-
img_handler = imgHandler;
82-
inherit affix;
83-
};
7+
inherit (lib.nixvim) defaultNullOpts;
8+
inherit (lib) types;
849
in
85-
{
86-
meta.maintainers = [ maintainers.GaetanLepage ];
10+
lib.nixvim.plugins.mkNeovimPlugin {
11+
name = "clipboard-image";
12+
packPathName = "clipboard-image.nvim";
13+
package = "clipboard-image-nvim";
8714

88-
options.plugins.clipboard-image = lib.nixvim.plugins.neovim.extraOptionsOptions // {
89-
enable = mkEnableOption "clipboard-image.nvim";
15+
maintainers = [ lib.maintainers.GaetanLepage ];
9016

91-
package = lib.mkPackageOption pkgs "clipboard-image.nvim" {
92-
default = [
93-
"vimPlugins"
94-
"clipboard-image-nvim"
95-
];
96-
};
17+
description = ''
18+
Plugin to paste images from clipboard into Neovim.
19+
'';
9720

98-
clipboardPackage = lib.mkPackageOption pkgs "clipboard privider" {
21+
extraOptions = {
22+
clipboardPackage = lib.mkPackageOption pkgs "clipboard provider" {
9923
nullable = true;
10024
default = null;
10125
example = [ "wl-clipboard" ];
10226
extraDescription = ''
10327
${"\n\n"}
104-
10528
Recommended:
10629
- X11: `pkgs.xclip`
10730
- Wayland: `pkgs.wl-clipboard`
10831
- MacOS: `pkgs.pngpaste`
10932
'';
11033
};
34+
};
11135

112-
default = pluginOptions;
113-
114-
filetypes = mkOption {
115-
type =
116-
with types;
117-
attrsOf (submodule {
118-
options = pluginOptions;
119-
});
120-
apply = mapAttrs (_: processPluginOptions);
121-
default = { };
122-
description = "Override certain options for specific filetypes.";
123-
example = {
124-
markdown = {
125-
imgDir = [
126-
"src"
127-
"assets"
128-
"img"
129-
];
130-
imgDirTxt = "/assets/img";
131-
imgHandler = ''
132-
function(img)
133-
local script = string.format('./image_compressor.sh "%s"', img.path)
134-
os.execute(script)
135-
end
36+
settingsOptions = {
37+
default = {
38+
img_dir =
39+
defaultNullOpts.mkNullable
40+
(types.oneOf [
41+
types.str
42+
(types.listOf types.str)
43+
types.rawLua
44+
])
45+
"img"
46+
''
47+
Directory name where the image will be pasted to.
48+
49+
> [!Note]
50+
> If you want to create nested dir, it is better to use table since windows and unix have different path separator.
13651
'';
137-
};
52+
53+
img_dir_txt = defaultNullOpts.mkNullable (types.oneOf [
54+
types.str
55+
(types.listOf types.str)
56+
types.rawLua
57+
]) "img" "Directory that will be inserted into text/buffer.";
58+
59+
img_name = defaultNullOpts.mkStr {
60+
__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
61+
} "Image's name.";
62+
63+
img_handler = defaultNullOpts.mkLuaFn "function(img) end" ''
64+
Function that will handle image after pasted.
65+
66+
> [!Note]
67+
> `img` is a table that contain pasted image's `{name}` and `{path}`.
68+
'';
69+
70+
affix = defaultNullOpts.mkStr' {
71+
pluginDefault = lib.literalMD ''
72+
`default`: `"{img_path}"`
73+
`markdown`: `"![]({img_path})"`
74+
'';
75+
description = "String that sandwiches the image's path.";
76+
example = lib.literalExpression ''
77+
> [!Note]
78+
79+
> ```nix
80+
> # You can use line break escape sequence
81+
> affix = "<\n %s\n>";
82+
> ```
83+
84+
> ```nix
85+
> # Or lua's double square brackets
86+
> affix.__raw = \'\'
87+
> [[<
88+
> %s
89+
> >]]
90+
> \'\'
91+
> ```
92+
'';
13893
};
13994
};
14095
};
14196

142-
config = mkIf cfg.enable {
143-
extraPlugins = [ cfg.package ];
97+
settingsExample = {
98+
settings = {
99+
img_dir = "img";
100+
img_dir_txt = "img";
101+
img_name.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
102+
img_handler.__raw = "function(img) end";
103+
affix = "![]({img_path})";
104+
};
105+
};
144106

107+
extraConfig = cfg: {
145108
extraPackages = [ cfg.clipboardPackage ];
146-
147-
extraConfigLua =
148-
let
149-
setupOptions =
150-
{
151-
default = processPluginOptions cfg.default;
152-
}
153-
// cfg.filetypes
154-
// cfg.extraOptions;
155-
in
156-
''
157-
require('clipboard-image').setup(${lib.nixvim.toLuaObject setupOptions})
158-
'';
159109
};
110+
111+
# TODO: Deprecated in 2025-02-01
112+
inherit (import ./deprecations.nix { inherit lib; })
113+
imports
114+
deprecateExtraOptions
115+
optionsRenamedToSettings
116+
;
160117
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{ lib }:
2+
{
3+
imports = [
4+
(lib.mkRemovedOptionModule
5+
[
6+
"plugins"
7+
"clipboard-image"
8+
"filetypes"
9+
]
10+
''
11+
Please use `plugins.clipboard-image.settings` for each filetype configuration instead.
12+
The attribute key is the name of the filetype and contains the same options as the default key.
13+
14+
Note that nested options will now be snake_case, as well, to match upstream plugin configuration.
15+
''
16+
)
17+
];
18+
19+
deprecateExtraOptions = true;
20+
optionsRenamedToSettings = [
21+
[
22+
"default"
23+
"imgDir"
24+
]
25+
[
26+
"default"
27+
"imgDirTxt"
28+
]
29+
[
30+
"default"
31+
"imgName"
32+
]
33+
[
34+
"default"
35+
"imgHandler"
36+
]
37+
[
38+
"default"
39+
"affix"
40+
]
41+
];
42+
}

tests/test-sources/plugins/by-name/clipboard-image/default.nix

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
enable = true;
1313

1414
clipboardPackage = pkgs.wl-clipboard;
15-
default = {
16-
imgDir = "img";
17-
imgDirTxt = "img";
18-
imgName.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
19-
imgHandler = "function(img) end";
20-
affix = "{img_path}";
21-
};
22-
filetypes = {
15+
settings = {
16+
default = {
17+
img_dir = "img";
18+
img_dir_txt = "img";
19+
img_name.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
20+
img_handler.__raw = "function(img) end";
21+
affix = "![]({img_path})";
22+
};
2323
markdown = {
24-
imgDir = [
24+
img_dir = [
2525
"src"
2626
"assets"
2727
"img"
2828
];
29-
imgDirTxt = "/assets/img";
30-
imgHandler = ''
29+
img_dir_txt = "/assets/img";
30+
img_handler.__raw = ''
3131
function(img) -- New feature from PR #22
3232
local script = string.format('./image_compressor.sh "%s"', img.path)
3333
os.execute(script)

0 commit comments

Comments
 (0)