From e08f03ec12f520384bcc1c20be51938364c582b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Tue, 28 Feb 2023 15:27:20 +0100 Subject: [PATCH] plugins/utils/nvim-bqf: add plugin nvim-bqf (#208) --- plugins/default.nix | 1 + plugins/utils/nvim-bqf.nix | 160 +++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 plugins/utils/nvim-bqf.nix diff --git a/plugins/default.nix b/plugins/default.nix index 3fceda77..7e12d5d5 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -66,6 +66,7 @@ ./utils/neorg.nix ./utils/notify.nix ./utils/nvim-autopairs.nix + ./utils/nvim-bqf.nix ./utils/nvim-colorizer.nix ./utils/nvim-tree.nix ./utils/project-nvim.nix diff --git a/plugins/utils/nvim-bqf.nix b/plugins/utils/nvim-bqf.nix new file mode 100644 index 00000000..231a3a65 --- /dev/null +++ b/plugins/utils/nvim-bqf.nix @@ -0,0 +1,160 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; let + cfg = config.plugins.nvim-bqf; + helpers = import ../helpers.nix {inherit lib;}; +in { + options.plugins.nvim-bqf = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "nvim-bqf"; + + package = helpers.mkPackageOption "nvim-bqf" pkgs.vimPlugins.nvim-bqf; + + autoEnable = helpers.defaultNullOpts.mkBool true '' + Enable nvim-bqf in quickfix window automatically. + ''; + + magicWindow = helpers.defaultNullOpts.mkBool true '' + Give the window magic, when the window is splited horizontally, keep the distance between the + current line and the top/bottom border of neovim unchanged. + It's a bit like a floating window, but the window is indeed a normal window, without any + floating attributes. + ''; + + autoResizeHeight = helpers.defaultNullOpts.mkBool false '' + Resize quickfix window height automatically. + Shrink higher height to size of list in quickfix window, otherwise extend height to size of + list or to default height (10). + ''; + + preview = { + autoPreview = helpers.defaultNullOpts.mkBool true '' + Enable preview in quickfix window automatically. + ''; + + borderChars = + helpers.defaultNullOpts.mkNullable (types.listOf types.str) + "[ \"│\" \"│\" \"─\" \"─\" \"╭\" \"╮\" \"╰\" \"╯\" \"█\" ]" + '' + Border and scroll bar chars, they respectively represent: + vline, vline, hline, hline, ulcorner, urcorner, blcorner, brcorner, sbar + ''; + + showTitle = helpers.defaultNullOpts.mkBool true '' + Show the window title. + ''; + + delaySyntax = helpers.defaultNullOpts.mkInt 50 '' + Delay time, to do syntax for previewed buffer, unit is millisecond. + ''; + + winHeight = helpers.defaultNullOpts.mkInt 15 '' + The height of preview window for horizontal layout. + Large value (like 999) perform preview window as a "full" mode. + ''; + + winVheight = helpers.defaultNullOpts.mkInt 15 '' + The height of preview window for vertical layout. + ''; + + wrap = helpers.defaultNullOpts.mkBool false '' + Wrap the line, `:h wrap` for detail. + ''; + + bufLabel = helpers.defaultNullOpts.mkBool true '' + Add label of current item buffer at the end of the item line. + ''; + + shouldPreviewCb = helpers.mkNullOrOption types.str '' + A callback function to decide whether to preview while switching buffer, with + (bufnr: number, qwinid: number) parameters. + ''; + }; + + funcMap = helpers.mkNullOrOption (types.attrsOf types.str) '' + The table for {function = key}. + + Example (some default values): + funcMap = { + open = ""; + tab = "t"; + sclear = "z"; + }; + ''; + + filter = { + fzf = { + actionFor = { + "ctrl-t" = helpers.defaultNullOpts.mkStr "tabedit" '' + Press ctrl-t to open up the item in a new tab. + ''; + + "ctrl-v" = helpers.defaultNullOpts.mkStr "vsplit" '' + Press ctrl-v to open up the item in a new vertical split. + ''; + + "ctrl-x" = helpers.defaultNullOpts.mkStr "split" '' + Press ctrl-x to open up the item in a new horizontal split. + ''; + + "ctrl-q" = helpers.defaultNullOpts.mkStr "signtoggle" '' + Press ctrl-q to toggle sign for the selected items. + ''; + + "ctrl-c" = helpers.defaultNullOpts.mkStr "closeall" '' + Press ctrl-c to close quickfix window and abort fzf. + ''; + }; + + extraOpts = + helpers.defaultNullOpts.mkNullable + (types.listOf types.str) + "[ \"--bind\" \"ctrl-o:toggle-all\" ]" + "Extra options for fzf."; + }; + }; + }; + + config = let + options = + { + auto_enable = cfg.autoEnable; + magic_window = cfg.magicWindow; + auto_resize_height = cfg.autoResizeHeight; + preview = with cfg.preview; { + auto_preview = autoPreview; + border_chars = borderChars; + show_title = showTitle; + delay_syntax = delaySyntax; + win_height = winHeight; + win_vheight = winVheight; + inherit wrap; + buf_label = bufLabel; + should_preview_cb = + if isNull shouldPreviewCb + then null + else helpers.mkRaw shouldPreviewCb; + }; + func_map = cfg.funcMap; + filter = { + fzf = with cfg.filter.fzf; { + action_for = actionFor; + extra_opts = extraOpts; + }; + }; + } + // cfg.extraOptions; + in + mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = '' + require('bqf').setup(${helpers.toLuaObject options}) + ''; + }; +}