Skip to content

Commit

Permalink
plugins/harpoon: fix keymaps + test
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Oct 4, 2023
1 parent 418bf5d commit 73f21c0
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 23 deletions.
63 changes: 40 additions & 23 deletions plugins/utils/harpoon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ with lib; let

projectConfigModule = types.submodule {
options = {
termCommands = helpers.mkNullOrOption (types.listOf types.str) ''
termCommands = helpers.mkNullOrOption (with types; listOf str) ''
List of predefined terminal commands for this project.
'';

marks = helpers.mkNullOrOption (types.listOf types.str) ''
marks = helpers.mkNullOrOption (with types; listOf str) ''
List of predefined marks (filenames) for this project.
'';
};
Expand Down Expand Up @@ -42,7 +42,7 @@ in {
Keymap for toggling the quick menu.";
'';

navFile = helpers.mkNullOrOption (types.attrsOf types.str) ''
navFile = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to marks.
Examples:
Expand All @@ -62,7 +62,7 @@ in {
Keymap for navigating to previous mark.";
'';

gotoTerminal = helpers.mkNullOrOption (types.attrsOf types.str) ''
gotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to terminals.
Examples:
Expand All @@ -78,7 +78,7 @@ in {
Keymap for toggling the cmd quick menu.
'';

tmuxGotoTerminal = helpers.mkNullOrOption (types.attrsOf types.str) ''
tmuxGotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to tmux windows/panes.
Attributes can either be tmux window ids or pane identifiers.
Expand Down Expand Up @@ -107,9 +107,11 @@ in {
Closes any tmux windows harpoon that harpoon creates when you close Neovim.
'';

excludedFiletypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "['harpoon']" ''
Filetypes that you want to prevent from adding to the harpoon list menu.
'';
excludedFiletypes =
helpers.defaultNullOpts.mkNullable
(with types; listOf str)
''["harpoon"]''
"Filetypes that you want to prevent from adding to the harpoon list menu.";

markBranch = helpers.defaultNullOpts.mkBool false ''
Set marks specific to each git branch inside git repository.
Expand All @@ -124,7 +126,7 @@ in {
example = ''
projects = {
"$HOME/personal/vim-with-me/server" = {
term.cmds = [
termCommands = [
"./env && npx ts-node src/index.ts"
];
};
Expand All @@ -143,8 +145,9 @@ in {
'';

borderChars =
helpers.defaultNullOpts.mkNullable (types.listOf types.str)
"[ \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" ]"
helpers.defaultNullOpts.mkNullable
(with types; listOf str)
''["─" "│" "─" "│" "╭" "╮" "╯" "╰"]''
"Border characters";
};
};
Expand All @@ -155,27 +158,41 @@ in {
(
name: value: {
term.cmds = value.termCommands;
mark.marks = map (mark: {filename = mark;}) value.marks;
mark.marks =
helpers.ifNonNull' value.marks
(
map
(
mark: {
filename = mark;
}
)
value.marks
);
}
)
cfg.projects;

options =
setupOptions = with cfg;
{
global_settings = {
save_on_toggle = cfg.saveOnToggle;
save_on_change = cfg.saveOnChange;
enter_on_sendcmd = cfg.enterOnSendcmd;
tmux_autoclose_windows = cfg.tmuxAutocloseWindows;
excluded_filetypes = cfg.excludedFiletypes;
mark_branch = cfg.markBranch;
save_on_toggle = saveOnToggle;
save_on_change = saveOnChange;
enter_on_sendcmd = enterOnSendcmd;
tmux_autoclose_windows = tmuxAutocloseWindows;
excluded_filetypes = excludedFiletypes;
mark_branch = markBranch;
};

inherit projects;

menu = {
inherit (cfg.menu) width height;
borderchars = cfg.menu.borderChars;
inherit
(menu)
width
height
;
borderchars = menu.borderChars;
};
}
// cfg.extraOptions;
Expand All @@ -184,7 +201,7 @@ in {
extraPlugins = [cfg.package];

extraConfigLua = ''
require('harpoon').setup(${helpers.toLuaObject options})
require('harpoon').setup(${helpers.toLuaObject setupOptions})
'';

keymaps = let
Expand Down Expand Up @@ -247,7 +264,7 @@ in {
(id: "function() require('harpoon.tmux').gotoTerminal(${id}) end")
);
in
helpers.mkKeymaps
helpers.keymaps.mkKeymaps
{
mode = "n";
lua = true;
Expand Down
62 changes: 62 additions & 0 deletions tests/test-sources/plugins/utils/harpoon.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
empty = {
# Harpoon expects to access `~/.local/share/nvim/harpoon.json` which is not available in the
# test environment
tests.dontRun = true;

plugins.harpoon.enable = true;
};

example = {
# Harpoon expects to access `~/.local/share/nvim/harpoon.json` which is not available in the
# test environment
tests.dontRun = true;

plugins.harpoon = {
enable = true;

keymapsSilent = true;
keymaps = {
addFile = "<leader>a";
navFile = {
"1" = "<C-j>";
"2" = "<C-k>";
"3" = "<C-l>";
"4" = "<C-m>";
};
navNext = "<leader>b";
navPrev = "<leader>c";
gotoTerminal = {
"1" = "J";
"2" = "K";
"3" = "L";
"4" = "M";
};
cmdToggleQuickMenu = "<leader>d";
tmuxGotoTerminal = {
"1" = "<C-1>";
"2" = "<C-2>";
"{down-of}" = "<leader>g";
};
};
saveOnToggle = false;
saveOnChange = true;
enterOnSendcmd = false;
tmuxAutocloseWindows = false;
excludedFiletypes = ["harpoon"];
markBranch = false;
projects = {
"$HOME/personal/vim-with-me/server" = {
termCommands = [
"./env && npx ts-node src/index.ts"
];
};
};
menu = {
width = 60;
height = 10;
borderChars = ["─" "│" "─" "│" "╭" "╮" "╯" "╰"];
};
};
};
}

0 comments on commit 73f21c0

Please sign in to comment.