-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/openscad: migrate to mkVimPlugin
- Loading branch information
1 parent
17905de
commit 4f1fe40
Showing
5 changed files
with
188 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,93 @@ | ||
{ | ||
lib, | ||
helpers, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
with lib; | ||
let | ||
defaultFuzzyFinder = "skim"; | ||
inherit (lib) types; | ||
inherit (lib.nixvim) defaultNullOpts applyPrefixToAttrs; | ||
inherit (lib.nixvim.vim-plugin) mkSettingsOptionDescription; | ||
|
||
name = "openscad"; | ||
globalPrefix = "openscad_"; | ||
in | ||
{ | ||
options.plugins.openscad = { | ||
enable = mkEnableOption "openscad.nvim, a plugin to manage OpenSCAD files"; | ||
lib.nixvim.neovim-plugin.mkNeovimPlugin { | ||
inherit name; | ||
packPathName = "openscad.nvim"; | ||
package = "openscad-nvim"; | ||
|
||
maintainers = [ lib.maintainers.GaetanLepage ]; | ||
|
||
# TODO: Added 2024-12-17; remove after 25.05 | ||
optionsRenamedToSettings = import ./renamed-options.nix; | ||
|
||
package = lib.mkPackageOption pkgs "openscad.nvim" { | ||
default = [ | ||
"vimPlugins" | ||
"openscad-nvim" | ||
]; | ||
}; | ||
settingsOptions = { | ||
fuzzy_finder = defaultNullOpts.mkStr "skim" '' | ||
Fuzzy finder to find documentation. | ||
fuzzyFinder = helpers.defaultNullOpts.mkEnum [ | ||
"skim" | ||
"fzf" | ||
] defaultFuzzyFinder "fuzzy finder to find documentation"; | ||
If you set this option explicitly, Nixvim will install the relevant finder plugin. | ||
''; | ||
|
||
cheatsheetWindowBlend = helpers.defaultNullOpts.mkNullable (types.ints.between 0 100) 15 ""; | ||
cheatsheet_window_blend = defaultNullOpts.mkNullable (types.ints.between 0 100) 15 '' | ||
Transparency level of the cheatsheet window (in %). | ||
''; | ||
|
||
loadSnippets = helpers.defaultNullOpts.mkBool false ""; | ||
load_snippets = defaultNullOpts.mkBool false '' | ||
Whether to load predefined snippets for OpenSCAD. | ||
''; | ||
|
||
autoOpen = helpers.defaultNullOpts.mkBool false ""; | ||
auto_open = defaultNullOpts.mkBool false '' | ||
Whether the openscad project automatically be opened on startup. | ||
''; | ||
|
||
keymaps = { | ||
enable = mkEnableOption "keymaps for openscad"; | ||
default_mappings = defaultNullOpts.mkBool true '' | ||
Whether to enable the default mappings. | ||
''; | ||
|
||
cheatsheetToggle = helpers.defaultNullOpts.mkStr "<Enter>" "Toggle cheatsheet window"; | ||
cheatsheet_toggle_key = defaultNullOpts.mkStr "<Enter>" '' | ||
Keyboard shortcut for toggling the cheatsheet. | ||
''; | ||
|
||
helpTrigger = helpers.defaultNullOpts.mkStr "<A-h>" "Fuzzy find help resource"; | ||
help_trig_key = defaultNullOpts.mkStr "<A-h>" '' | ||
Keyboard shortcut for triggering the fuzzy-find help resource. | ||
''; | ||
|
||
helpManualTrigger = helpers.defaultNullOpts.mkStr "<A-m>" "Open offline openscad manual in pdf via zathura"; | ||
help_manual_trig_key = defaultNullOpts.mkStr "<A-m>" '' | ||
Keyboard shortcut for manually triggering the offline OpenSCAD manual. | ||
''; | ||
|
||
execOpenSCADTrigger = helpers.defaultNullOpts.mkStr "<A-o>" "Open file in OpenSCAD"; | ||
exec_openscad_trig_key = defaultNullOpts.mkStr "<A-o>" '' | ||
Keyboard shortcut for opening the current file in OpenSCAD. | ||
''; | ||
|
||
topToggle = helpers.defaultNullOpts.mkStr "<A-c>" "toggle htop filtered for openscad processes"; | ||
}; | ||
top_toggle = defaultNullOpts.mkStr "<A-c>" '' | ||
Keyboard shortcut for toggling `htop` filtered for OpenSCAD processes. | ||
''; | ||
}; | ||
|
||
config = | ||
let | ||
cfg = config.plugins.openscad; | ||
fuzzyFinder = if (cfg.fuzzyFinder == null) then defaultFuzzyFinder else cfg.fuzzyFinder; | ||
in | ||
mkIf cfg.enable { | ||
extraPlugins = | ||
with pkgs.vimPlugins; | ||
[ cfg.package ] | ||
++ (optional (fuzzyFinder == "skim") skim-vim) | ||
++ (optional (fuzzyFinder == "fzf") fzf-vim); | ||
|
||
extraConfigLua = '' | ||
require('openscad') | ||
''; | ||
|
||
globals = mkMerge [ | ||
{ | ||
openscad_fuzzy_finder = cfg.fuzzyFinder; | ||
openscad_cheatsheet_window_blend = cfg.cheatsheetWindowBlend; | ||
openscad_load_snippets = cfg.loadSnippets; | ||
} | ||
(mkIf cfg.keymaps.enable { | ||
openscad_default_mappings = true; | ||
openscad_cheatsheet_toggle_key = cfg.keymaps.cheatsheetToggle; | ||
openscad_help_trig_key = cfg.keymaps.helpTrigger; | ||
openscad_help_manual_trig_key = cfg.keymaps.helpManualTrigger; | ||
openscad_exec_openscad_trig_key = cfg.keymaps.execOpenSCADTrigger; | ||
openscad_top_toggle = cfg.keymaps.topToggle; | ||
}) | ||
]; | ||
}; | ||
settingsExample = { | ||
load_snippets = true; | ||
fuzzy_finder = "fzf"; | ||
cheatsheet_window_blend = 15; | ||
auto_open = true; | ||
}; | ||
|
||
settingsDescription = mkSettingsOptionDescription { inherit name globalPrefix; }; | ||
|
||
callSetup = false; | ||
|
||
extraOptions = { | ||
fuzzyFinderPlugin = import ./fuzzy-finder-plugin-option.nix { inherit lib config pkgs; }; | ||
}; | ||
|
||
extraConfig = cfg: { | ||
plugins.openscad.luaConfig.content = '' | ||
require('openscad') | ||
''; | ||
|
||
globals = applyPrefixToAttrs globalPrefix cfg.settings; | ||
|
||
extraPlugins = [ cfg.fuzzyFinderPlugin ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
}: | ||
let | ||
optionName = "`settings.fuzzy_finder`"; | ||
|
||
fuzzyFinder = config.plugins.openscad.settings.fuzzy_finder; | ||
|
||
defaultPluginName = | ||
{ | ||
skim = "skim-vim"; | ||
fzf = "fzf-vim"; | ||
} | ||
.${fuzzyFinder} or null; | ||
|
||
default = | ||
# If the user has not set `settings.fuzzy_finder`, do not pre-install a fuzzy-finder by default. | ||
if fuzzyFinder == null then | ||
null | ||
# Else, the value of `settings.fuzzy_finder` should be one of the supported options | ||
# (`skim` or `fzf`), else he has to provide a value (`null` or a package) to `fuzzyFinderPlugin`. | ||
else if defaultPluginName == null then | ||
throw '' | ||
We cannot automatically select a fuzzy finder plugin from the value given to `${optionName}`: "${fuzzyFinder}". | ||
Please, explicitly provide a value to the `plugins.openscad.fuzzyFinderPlugin`: | ||
- Either the package for the fuzzy finder plugin to be installed | ||
- or `null` if you do not want a plugin to be installed. | ||
'' | ||
# Case where we automatically select the default plugin to install. | ||
else | ||
[ | ||
"vimPlugins" | ||
defaultPluginName | ||
]; | ||
|
||
defaultText = lib.literalMD '' | ||
- `pkgs.vimPlugins.skim-vim` if ${optionName} is `"skim"` | ||
- `pkgs.vimPlugins.fzf-vim` if ${optionName} is `"fzf"` | ||
- `null` otherwise | ||
''; | ||
in | ||
lib.mkPackageOption pkgs "fuzzy finder" { | ||
nullable = true; | ||
inherit default; | ||
} | ||
// { | ||
inherit defaultText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[ | ||
"fuzzyFinder" | ||
"cheatsheetWindowBlend" | ||
"loadSnippets" | ||
"autoOpen" | ||
{ | ||
old = [ | ||
"keymaps" | ||
"enabled" | ||
]; | ||
new = "default_mappings"; | ||
} | ||
{ | ||
old = [ | ||
"keymaps" | ||
"cheatsheetToggle" | ||
]; | ||
new = "cheatsheet_toggle_key"; | ||
} | ||
{ | ||
old = [ | ||
"keymaps" | ||
"helpTrigger" | ||
]; | ||
new = "help_trig_key"; | ||
} | ||
{ | ||
old = [ | ||
"keymaps" | ||
"helpManualTrigger" | ||
]; | ||
new = "help_manual_trig_key"; | ||
} | ||
{ | ||
old = [ | ||
"keymaps" | ||
"execOpenSCADTrigger" | ||
]; | ||
new = "exec_openscad_trig_key"; | ||
} | ||
{ | ||
old = [ | ||
"keymaps" | ||
"topToggle" | ||
]; | ||
new = "top_toggle"; | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters