|
1 | 1 | {
|
2 | 2 | lib,
|
3 |
| - helpers, |
4 | 3 | config,
|
5 |
| - pkgs, |
6 | 4 | ...
|
7 | 5 | }:
|
8 |
| -with lib; |
9 | 6 | let
|
10 |
| - cfg = config.plugins.harpoon; |
11 |
| - |
12 |
| - projectConfigModule = types.submodule { |
13 |
| - options = { |
14 |
| - termCommands = helpers.mkNullOrOption (with types; listOf str) '' |
15 |
| - List of predefined terminal commands for this project. |
16 |
| - ''; |
17 |
| - |
18 |
| - marks = helpers.mkNullOrOption (with types; listOf str) '' |
19 |
| - List of predefined marks (filenames) for this project. |
20 |
| - ''; |
21 |
| - }; |
22 |
| - }; |
| 7 | + inherit (lib) mkEnableOption; |
23 | 8 | in
|
24 |
| -{ |
25 |
| - options.plugins.harpoon = lib.nixvim.plugins.neovim.extraOptionsOptions // { |
26 |
| - enable = mkEnableOption "harpoon"; |
27 |
| - |
28 |
| - package = lib.mkPackageOption pkgs "harpoon" { |
29 |
| - default = [ |
30 |
| - "vimPlugins" |
31 |
| - "harpoon" |
32 |
| - ]; |
33 |
| - }; |
34 |
| - |
35 |
| - enableTelescope = mkEnableOption "telescope integration"; |
36 |
| - |
37 |
| - keymapsSilent = mkOption { |
38 |
| - type = types.bool; |
39 |
| - description = "Whether harpoon keymaps should be silent."; |
40 |
| - default = false; |
41 |
| - }; |
42 |
| - |
43 |
| - keymaps = { |
44 |
| - addFile = helpers.mkNullOrOption types.str '' |
45 |
| - Keymap for marking the current file."; |
46 |
| - ''; |
47 |
| - |
48 |
| - toggleQuickMenu = helpers.mkNullOrOption types.str '' |
49 |
| - Keymap for toggling the quick menu."; |
50 |
| - ''; |
51 |
| - |
52 |
| - navFile = helpers.mkNullOrOption (with types; attrsOf str) '' |
53 |
| - Keymaps for navigating to marks. |
54 |
| -
|
55 |
| - Examples: |
56 |
| - navFile = { |
57 |
| - "1" = "<C-j>"; |
58 |
| - "2" = "<C-k>"; |
59 |
| - "3" = "<C-l>"; |
60 |
| - "4" = "<C-m>"; |
61 |
| - }; |
62 |
| - ''; |
| 9 | +lib.nixvim.plugins.mkNeovimPlugin { |
| 10 | + name = "harpoon"; |
| 11 | + package = "harpoon2"; |
63 | 12 |
|
64 |
| - navNext = helpers.mkNullOrOption types.str '' |
65 |
| - Keymap for navigating to next mark."; |
66 |
| - ''; |
| 13 | + maintainers = [ lib.maintainers.GaetanLepage ]; |
67 | 14 |
|
68 |
| - navPrev = helpers.mkNullOrOption types.str '' |
69 |
| - Keymap for navigating to previous mark."; |
70 |
| - ''; |
| 15 | + setup = ":setup"; |
71 | 16 |
|
72 |
| - gotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) '' |
73 |
| - Keymaps for navigating to terminals. |
| 17 | + # TODO: introduced 2025-04-03: remove after 25.11 |
| 18 | + imports = [ |
| 19 | + ./deprecations.nix |
| 20 | + ]; |
74 | 21 |
|
75 |
| - Examples: |
76 |
| - gotoTerminal = { |
77 |
| - "1" = "<C-j>"; |
78 |
| - "2" = "<C-k>"; |
79 |
| - "3" = "<C-l>"; |
80 |
| - "4" = "<C-m>"; |
81 |
| - }; |
82 |
| - ''; |
83 |
| - |
84 |
| - cmdToggleQuickMenu = helpers.mkNullOrOption types.str '' |
85 |
| - Keymap for toggling the cmd quick menu. |
86 |
| - ''; |
87 |
| - |
88 |
| - tmuxGotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) '' |
89 |
| - Keymaps for navigating to tmux windows/panes. |
90 |
| - Attributes can either be tmux window ids or pane identifiers. |
| 22 | + extraOptions = { |
| 23 | + enableTelescope = mkEnableOption "telescope integration"; |
| 24 | + }; |
91 | 25 |
|
92 |
| - Examples: |
93 |
| - tmuxGotoTerminal = { |
94 |
| - "1" = "<C-1>"; |
95 |
| - "2" = "<C-2>"; |
96 |
| - "{down-of}" = "<leader>g"; |
97 |
| - }; |
98 |
| - ''; |
| 26 | + settingsExample = { |
| 27 | + settings = { |
| 28 | + save_on_toggle = true; |
| 29 | + sync_on_ui_close = false; |
99 | 30 | };
|
| 31 | + }; |
100 | 32 |
|
101 |
| - saveOnToggle = helpers.defaultNullOpts.mkBool false '' |
102 |
| - Sets the marks upon calling `toggle` on the ui, instead of require `:w`. |
103 |
| - ''; |
104 |
| - |
105 |
| - saveOnChange = helpers.defaultNullOpts.mkBool true '' |
106 |
| - Saves the harpoon file upon every change. disabling is unrecommended. |
107 |
| - ''; |
108 |
| - |
109 |
| - enterOnSendcmd = helpers.defaultNullOpts.mkBool false '' |
110 |
| - Sets harpoon to run the command immediately as it's passed to the terminal when calling `sendCommand`. |
111 |
| - ''; |
112 |
| - |
113 |
| - tmuxAutocloseWindows = helpers.defaultNullOpts.mkBool false '' |
114 |
| - Closes any tmux windows harpoon that harpoon creates when you close Neovim. |
115 |
| - ''; |
116 |
| - |
117 |
| - excludedFiletypes = helpers.defaultNullOpts.mkListOf types.str [ "harpoon" ] '' |
118 |
| - Filetypes that you want to prevent from adding to the harpoon list menu. |
119 |
| - ''; |
120 |
| - |
121 |
| - markBranch = helpers.defaultNullOpts.mkBool false '' |
122 |
| - Set marks specific to each git branch inside git repository. |
123 |
| - ''; |
124 |
| - |
125 |
| - projects = mkOption { |
126 |
| - default = { }; |
127 |
| - description = '' |
128 |
| - Predefined projetcs. The keys of this attrs should be the path to the project. |
129 |
| - $HOME is working. |
130 |
| - ''; |
131 |
| - example = '' |
132 |
| - projects = { |
133 |
| - "$HOME/personal/vim-with-me/server" = { |
134 |
| - termCommands = [ |
135 |
| - "./env && npx ts-node src/index.ts" |
136 |
| - ]; |
137 |
| - }; |
138 |
| - }; |
139 |
| - ''; |
140 |
| - type = types.attrsOf projectConfigModule; |
| 33 | + extraConfig = cfg: { |
| 34 | + assertions = lib.nixvim.mkAssertions "plugins.harpoon" { |
| 35 | + assertion = cfg.enableTelescope -> config.plugins.telescope.enable; |
| 36 | + message = "The harpoon telescope integration needs telescope to function as intended."; |
141 | 37 | };
|
142 | 38 |
|
143 |
| - menu = { |
144 |
| - width = helpers.defaultNullOpts.mkInt 60 '' |
145 |
| - Menu window width |
146 |
| - ''; |
147 |
| - |
148 |
| - height = helpers.defaultNullOpts.mkInt 10 '' |
149 |
| - Menu window height |
150 |
| - ''; |
151 |
| - |
152 |
| - borderChars = helpers.defaultNullOpts.mkListOf types.str [ |
153 |
| - "─" |
154 |
| - "│" |
155 |
| - "─" |
156 |
| - "│" |
157 |
| - "╭" |
158 |
| - "╮" |
159 |
| - "╯" |
160 |
| - "╰" |
161 |
| - ] "Border characters"; |
162 |
| - }; |
| 39 | + plugins.telescope.enabledExtensions = lib.mkIf cfg.enableTelescope [ "harpoon" ]; |
163 | 40 | };
|
164 |
| - |
165 |
| - config = |
166 |
| - let |
167 |
| - projects = builtins.mapAttrs (name: value: { |
168 |
| - term.cmds = value.termCommands; |
169 |
| - mark.marks = helpers.ifNonNull' value.marks (map (mark: { filename = mark; }) value.marks); |
170 |
| - }) cfg.projects; |
171 |
| - |
172 |
| - setupOptions = |
173 |
| - with cfg; |
174 |
| - { |
175 |
| - global_settings = { |
176 |
| - save_on_toggle = saveOnToggle; |
177 |
| - save_on_change = saveOnChange; |
178 |
| - enter_on_sendcmd = enterOnSendcmd; |
179 |
| - tmux_autoclose_windows = tmuxAutocloseWindows; |
180 |
| - excluded_filetypes = excludedFiletypes; |
181 |
| - mark_branch = markBranch; |
182 |
| - }; |
183 |
| - |
184 |
| - inherit projects; |
185 |
| - |
186 |
| - menu = { |
187 |
| - inherit (menu) width height; |
188 |
| - borderchars = menu.borderChars; |
189 |
| - }; |
190 |
| - } |
191 |
| - // cfg.extraOptions; |
192 |
| - in |
193 |
| - mkIf cfg.enable { |
194 |
| - assertions = lib.nixvim.mkAssertions "plugins.harpoon" [ |
195 |
| - { |
196 |
| - assertion = cfg.enableTelescope -> config.plugins.telescope.enable; |
197 |
| - message = "The harpoon telescope integration needs telescope to function as intended."; |
198 |
| - } |
199 |
| - ]; |
200 |
| - |
201 |
| - extraPlugins = [ cfg.package ]; |
202 |
| - |
203 |
| - extraConfigLua = |
204 |
| - let |
205 |
| - telescopeCfg = ''require("telescope").load_extension("harpoon")''; |
206 |
| - in |
207 |
| - '' |
208 |
| - require('harpoon').setup(${lib.nixvim.toLuaObject setupOptions}) |
209 |
| - ${if cfg.enableTelescope then telescopeCfg else ""} |
210 |
| - ''; |
211 |
| - |
212 |
| - keymaps = |
213 |
| - let |
214 |
| - km = cfg.keymaps; |
215 |
| - |
216 |
| - simpleMappings = flatten ( |
217 |
| - mapAttrsToList |
218 |
| - ( |
219 |
| - optionName: luaFunc: |
220 |
| - let |
221 |
| - key = km.${optionName}; |
222 |
| - in |
223 |
| - optional (key != null) { |
224 |
| - inherit key; |
225 |
| - action.__raw = luaFunc; |
226 |
| - } |
227 |
| - ) |
228 |
| - { |
229 |
| - addFile = "require('harpoon.mark').add_file"; |
230 |
| - toggleQuickMenu = "require('harpoon.ui').toggle_quick_menu"; |
231 |
| - navNext = "require('harpoon.ui').nav_next"; |
232 |
| - navPrev = "require('harpoon.ui').nav_prev"; |
233 |
| - cmdToggleQuickMenu = "require('harpoon.cmd-ui').toggle_quick_menu"; |
234 |
| - } |
235 |
| - ); |
236 |
| - |
237 |
| - mkNavMappings = |
238 |
| - name: genLuaFunc: |
239 |
| - let |
240 |
| - mappingsAttrs = km.${name}; |
241 |
| - in |
242 |
| - flatten ( |
243 |
| - optionals (mappingsAttrs != null) ( |
244 |
| - mapAttrsToList (id: key: { |
245 |
| - inherit key; |
246 |
| - action.__raw = genLuaFunc id; |
247 |
| - }) mappingsAttrs |
248 |
| - ) |
249 |
| - ); |
250 |
| - |
251 |
| - allMappings = |
252 |
| - simpleMappings |
253 |
| - ++ (mkNavMappings "navFile" (id: "function() require('harpoon.ui').nav_file(${id}) end")) |
254 |
| - ++ (mkNavMappings "gotoTerminal" (id: "function() require('harpoon.term').gotoTerminal(${id}) end")) |
255 |
| - ++ (mkNavMappings "tmuxGotoTerminal" ( |
256 |
| - id: "function() require('harpoon.tmux').gotoTerminal(${id}) end" |
257 |
| - )); |
258 |
| - in |
259 |
| - helpers.keymaps.mkKeymaps { |
260 |
| - mode = "n"; |
261 |
| - options.silent = cfg.keymapsSilent; |
262 |
| - } allMappings; |
263 |
| - }; |
264 | 41 | }
|
0 commit comments