plugins/floaterm: move to mkVimPlugin

This commit is contained in:
Gaetan Lepage 2024-12-15 19:18:18 +01:00
parent c179d47d3d
commit 76e9d89d96
3 changed files with 277 additions and 209 deletions

View file

@ -69,7 +69,6 @@ KNOWN_PATHS: dict[
"plugins/by-name/chadtree/default.nix": (State.OLD, Kind.NEOVIM, False), "plugins/by-name/chadtree/default.nix": (State.OLD, Kind.NEOVIM, False),
"plugins/by-name/coq-thirdparty/default.nix": (State.OLD, Kind.NEOVIM, False), "plugins/by-name/coq-thirdparty/default.nix": (State.OLD, Kind.NEOVIM, False),
"plugins/by-name/dap/default.nix": (State.OLD, Kind.NEOVIM, False), "plugins/by-name/dap/default.nix": (State.OLD, Kind.NEOVIM, False),
"plugins/by-name/floaterm/default.nix": (State.OLD, Kind.VIM, False),
"plugins/by-name/gitgutter/default.nix": (State.OLD, Kind.VIM, False), "plugins/by-name/gitgutter/default.nix": (State.OLD, Kind.VIM, False),
"plugins/by-name/gitmessenger/default.nix": (State.OLD, Kind.VIM, False), "plugins/by-name/gitmessenger/default.nix": (State.OLD, Kind.VIM, False),
"plugins/by-name/intellitab/default.nix": ( "plugins/by-name/intellitab/default.nix": (

View file

@ -1,235 +1,240 @@
{ {
lib, lib,
helpers,
config,
pkgs,
... ...
}: }:
with lib;
let let
cfg = config.plugins.floaterm; inherit (lib.nixvim) defaultNullOpts mkNullOrStr;
inherit (lib) types;
in
lib.nixvim.vim-plugin.mkVimPlugin {
name = "floaterm";
packPathName = "vim-floaterm";
package = "vim-floaterm";
globalPrefix = "floaterm_";
settings = { maintainers = [ lib.maintainers.GaetanLepage ];
shell = {
type = types.str;
description = "";
};
title = { # TODO: Added 2024-12-16; remove after 25.05
type = types.str; optionsRenamedToSettings =
description = '' [
Show floaterm info (e.g., 'floaterm: 1/3' implies there are 3 floaterms in total and the "autoclose"
current is the first one) at the top left corner of floaterm window. "autohide"
"autoinsert"
Default: 'floaterm: $1/$2'($1 and $2 will be substituted by 'the index of the current "borderchars"
floaterm' and 'the count of all floaterms' respectively) "giteditor"
"height"
Example: 'floaterm($1|$2)' "opener"
''; "position"
}; "rootmarkers"
"shell"
wintype = { "title"
type = types.enum [ "width"
"float" "wintype"
"split" ]
"vsplit" ++ map
(name: {
old = [
"keymaps"
name
];
new = "keymap_${name}";
})
[
"first"
"hide"
"kill"
"last"
"new"
"next"
"prev"
"show"
"toggle"
]; ];
settingsOptions = {
shell = mkNullOrStr ''
Which shell should floaterm use.
Default value is the same as your `shell` option.
'';
title = defaultNullOpts.mkStr "floaterm: $1/$2" ''
Title format in the floating/popup terminal window.
If empty, the title won't be show.
'';
wintype = defaultNullOpts.mkStr "float" ''
Set it to `"split"` or `"vsplit"` if you don't want to use floating or popup window.
'';
width =
defaultNullOpts.mkNullable (with types; either ints.unsigned (numbers.between 0.0 1.0)) 0.6
''
Width of the floaterm window.
It can be either an integer (number of columns) or a float between `0.0` and `1.0`.
In this case, the width is relative to `columns`.
'';
height =
defaultNullOpts.mkNullable (with types; either ints.unsigned (numbers.between 0.0 1.0)) 0.6
''
Width of the floaterm window.
It can be either an integer (number of lines) or a float between `0.0` and `1.0`.
In this case, the width is relative to `lines`.
'';
position = mkNullOrStr ''
The position of the floaterm window.
It's recommended to have a look at those options meanings, e.g. `:help :leftabove`.
- If `wintype` is `"split"` or `"vsplit"`:
- `"leftabove"`
- `"aboveleft"`
- `"rightbelow"`
- `"belowright"`
- `"topleft"`
- `"botright"` (default)
- If `wintype` is `"float"`:
- `"top"`
- `"bottom"`
- `"left"`
- `"right"`
- `"topleft"`
- `"topright"`
- `"bottomleft"`
- `"bottomright"`
- `"center"` (default)
- `"auto"` (at the cursor place)
'';
borderchars = defaultNullOpts.mkStr "" ''
8 characters of the floating window border (top, right, bottom, left, topleft, topright,
botright, botleft).
'';
rootmarkers =
defaultNullOpts.mkListOf types.str
[
".project"
".git"
".hg"
".svn"
".root"
]
''
Markers used to detect the project root directory when running.
```
:FloatermNew --cwd=<root>
```
'';
opener = defaultNullOpts.mkStr "split" ''
Command used for opening a file in the outside nvim from within `:terminal`.
Available: `"edit"`, `"split"`, `"vsplit"`, `"tabe"`, `"drop"` or user-defined commands.
'';
autoclose = defaultNullOpts.mkEnum [ 0 1 2 ] 1 ''
Whether to close floaterm window once a job gets finished.
- `0` - Always do NOT close floaterm window.
- `1` - Close window only if the job exits normally
- `2` - Always close floaterm window.
'';
autohide = defaultNullOpts.mkEnum [ 0 1 2 ] 1 ''
Whether to hide previous floaterms before switching to or opening a another
one.
- `0` - Always do NOT hide previous floaterm windows
- `1` - Only hide those whose position (`b:floaterm_position`) is identical to that of the
floaterm which will be opened
- `2` - Always hide them
'';
autoinsert = defaultNullOpts.mkBool true ''
Whether to enter `|Terminal-mode|` after opening a floaterm.
'';
titleposition = defaultNullOpts.mkEnumFirstDefault [ "left" "center" "right" ] ''
The position of the floaterm title.
'';
giteditor = defaultNullOpts.mkBool true ''
Whether to override $GIT_EDITOR in floaterm terminals so git commands can open open an
editor in the same neovim instance.
'';
keymap_new = defaultNullOpts.mkStr' {
pluginDefault = "";
description = '' description = ''
'float'(nvim's floating or vim's popup) by default. Keyboard shortcut to open the floaterm window.
Set it to 'split' or 'vsplit' if you don't want to use floating or popup window.
''; '';
example = "<F7>";
}; };
width = { keymap_prev = defaultNullOpts.mkStr' {
type = types.either types.int types.float; pluginDefault = "";
description = '' description = ''
Int (number of columns) or float (between 0 and 1). Keyboard shortcut to navigate to the previous terminal.
if float, the width is relative to &columns.
Default: 0.6
''; '';
example = "<F8>";
}; };
height = { keymap_next = defaultNullOpts.mkStr' {
type = types.either types.int types.float; pluginDefault = "";
description = '' description = ''
Int (number of columns) or float (between 0 and 1). Keyboard shortcut to navigate to the next terminal.
if float, the height is relative to &lines.
Default: 0.6
''; '';
example = "<F9>";
}; };
position = { keymap_first = defaultNullOpts.mkStr "" ''
type = types.str; Keyboard shortcut to navigate to the first terminal.
'';
keymap_last = defaultNullOpts.mkStr "" ''
Keyboard shortcut to navigate to the last terminal.
'';
keymap_hide = defaultNullOpts.mkStr "" ''
Keyboard shortcut to hide the floaterm window.
'';
keymap_show = defaultNullOpts.mkStr "" ''
Keyboard shortcut to show the floaterm window.
'';
keymap_kill = defaultNullOpts.mkStr "" ''
Keyboard shortcut to kill the floaterm window.
'';
keymap_toggle = defaultNullOpts.mkStr' {
pluginDefault = "";
description = '' description = ''
The position of the floating window. Keyboard shortcut to toggle the floaterm window.
Available values:
- If wintype is `split`/`vsplit`: 'leftabove', 'aboveleft', 'rightbelow', 'belowright', 'topleft', 'botright'.
Default: 'botright'.
- If wintype is float: 'top', 'bottom', 'left', 'right', 'topleft', 'topright', 'bottomleft', 'bottomright', 'center', 'auto' (at the cursor place).
Default: 'center'
In addition, there is another option 'random' which allows to pick a random position from
above when (re)opening a floaterm window.
'';
};
borderchars = {
type = types.str;
description = ''
The position of the floating window.
8 characters of the floating window border (top, right, bottom, left, topleft, topright, botright, botleft).
Default: ""
'';
};
rootmarkers = {
type = types.listOf types.str;
description = ''
Markers used to detect the project root directory for --cwd=<root>
Default: [".project" ".git" ".hg" ".svn" ".root"]
'';
};
giteditor = {
type = types.bool;
description = ''
Whether to override $GIT_EDITOR in floaterm terminals so git commands can open open an
editor in the same neovim instance.
Default: true
'';
};
opener = {
type = types.enum [
"edit"
"split"
"vsplit"
"tabe"
"drop"
];
description = ''
Command used for opening a file in the outside nvim from within `:terminal`.
Default: 'split'
'';
};
autoclose = {
type = types.enum [
0
1
2
];
description = ''
Whether to close floaterm window once the job gets finished.
- 0: Always do NOT close floaterm window
- 1: Close window if the job exits normally, otherwise stay it with messages like [Process exited 101]
- 2: Always close floaterm window
Default: 1
'';
};
autohide = {
type = types.enum [
0
1
2
];
description = ''
Whether to hide previous floaterms before switching to or opening a another one.
- 0: Always do NOT hide previous floaterm windows
- 1: Only hide those whose position (b:floaterm_position) is identical to that of the floaterm which will be opened
- 2: Always hide them
Default: 1
'';
};
autoinsert = {
type = types.bool;
description = ''
Whether to enter Terminal-mode after opening a floaterm.
Default: true
''; '';
example = "<F12>";
}; };
}; };
in
{
options.plugins.floaterm =
let
# Misc options
# `OPTION = VALUE`
# which will translate to `globals.floaterm_OPTION = VALUE;`
miscOptions = mapAttrs (name: value: helpers.mkNullOrOption value.type value.description) settings;
# Keymaps options settingsExample = {
# `keymaps.ACTION = KEY` width = 0.9;
# which will translate to `globals.floaterm_keymap_ACTION = KEY;` height = 0.9;
keymapOptions = listToAttrs ( opener = "edit ";
map title = "";
(name: { rootmarkers = [
inherit name; "build/CMakeFiles"
value = helpers.mkNullOrOption types.str "Key to map to ${name}"; ".project"
}) ".git"
[ ".hg"
"new" ".svn"
"prev" ".root"
"next" ];
"first" keymap_new = "<Leader>ft";
"last" keymap_prev = "<Leader>fp";
"hide" keymap_next = "<Leader>fn";
"show" keymap_toggle = "<Leader>t";
"kill" keymap_kill = "<Leader>fk";
"toggle"
]
);
in
{
enable = mkEnableOption "floaterm";
package = lib.mkPackageOption pkgs "floaterm" {
default = [
"vimPlugins"
"vim-floaterm"
];
};
keymaps = keymapOptions;
}
// miscOptions;
config = mkIf cfg.enable {
extraPlugins = [ cfg.package ];
globals =
let
# misc options
optionGlobals = listToAttrs (
map (optionName: {
name = "floaterm_${optionName}";
value = cfg.${optionName};
}) (attrNames settings)
);
# keymaps options
keymapGlobals = mapAttrs' (name: key: {
name = "floaterm_keymap_${name}";
value = key;
}) cfg.keymaps;
in
optionGlobals // keymapGlobals;
}; };
} }

View file

@ -2,4 +2,68 @@
empty = { empty = {
plugins.floaterm.enable = true; plugins.floaterm.enable = true;
}; };
defaults = {
plugins.floaterm = {
enable = true;
settings = {
shell = null;
title = "floaterm: $1/$2";
wintype = "float";
width = 0.6;
height = 0.6;
position = "center";
borderchars = "";
rootmarkers = [
".project"
".git"
".hg"
".svn"
".root"
];
opener = "split";
autoclose = 1;
autohide = 1;
autoinsert = true;
titleposition = "left";
giteditor = true;
keymap_new = "";
keymap_prev = "";
keymap_next = "";
keymap_first = "";
keymap_last = "";
keymap_hide = "";
keymap_show = "";
keymap_kill = "";
keymap_toggle = "";
};
};
};
example = {
plugins.floaterm = {
enable = true;
settings = {
width = 0.9;
height = 0.9;
opener = "edit ";
title = "";
rootmarkers = [
"build/CMakeFiles"
".project"
".git"
".hg"
".svn"
".root"
];
keymap_new = "<Leader>ft";
keymap_prev = "<Leader>fp";
keymap_next = "<Leader>fn";
keymap_toggle = "<Leader>t";
keymap_kill = "<Leader>fk";
};
};
};
} }