|
1 | 1 | {
|
2 | 2 | lib,
|
3 |
| - helpers, |
4 |
| - config, |
5 | 3 | pkgs,
|
6 | 4 | ...
|
7 | 5 | }:
|
8 |
| -with lib; |
9 | 6 | 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`: `""` |
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; |
84 | 9 | 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"; |
87 | 14 |
|
88 |
| - options.plugins.clipboard-image = lib.nixvim.plugins.neovim.extraOptionsOptions // { |
89 |
| - enable = mkEnableOption "clipboard-image.nvim"; |
| 15 | + maintainers = [ lib.maintainers.GaetanLepage ]; |
90 | 16 |
|
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 | + ''; |
97 | 20 |
|
98 |
| - clipboardPackage = lib.mkPackageOption pkgs "clipboard privider" { |
| 21 | + extraOptions = { |
| 22 | + clipboardPackage = lib.mkPackageOption pkgs "clipboard provider" { |
99 | 23 | nullable = true;
|
100 | 24 | default = null;
|
101 | 25 | example = [ "wl-clipboard" ];
|
102 | 26 | extraDescription = ''
|
103 | 27 | ${"\n\n"}
|
104 |
| -
|
105 | 28 | Recommended:
|
106 | 29 | - X11: `pkgs.xclip`
|
107 | 30 | - Wayland: `pkgs.wl-clipboard`
|
108 | 31 | - MacOS: `pkgs.pngpaste`
|
109 | 32 | '';
|
110 | 33 | };
|
| 34 | + }; |
111 | 35 |
|
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. |
136 | 51 | '';
|
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`: `""` |
| 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 | + ''; |
138 | 93 | };
|
139 | 94 | };
|
140 | 95 | };
|
141 | 96 |
|
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 = ""; |
| 104 | + }; |
| 105 | + }; |
144 | 106 |
|
| 107 | + extraConfig = cfg: { |
145 | 108 | 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 |
| - ''; |
159 | 109 | };
|
| 110 | + |
| 111 | + # TODO: Deprecated in 2025-02-01 |
| 112 | + inherit (import ./deprecations.nix { inherit lib; }) |
| 113 | + imports |
| 114 | + deprecateExtraOptions |
| 115 | + optionsRenamedToSettings |
| 116 | + ; |
160 | 117 | }
|
0 commit comments