|
| 1 | +{ |
| 2 | + lib, |
| 3 | + ... |
| 4 | +}: |
| 5 | +let |
| 6 | + inherit (lib.nixvim) defaultNullOpts; |
| 7 | + inherit (lib) types; |
| 8 | +in |
| 9 | +lib.nixvim.neovim-plugin.mkNeovimPlugin { |
| 10 | + name = "nvim-surround"; |
| 11 | + originalName = "nvim-surround"; |
| 12 | + package = "nvim-surround"; |
| 13 | + |
| 14 | + maintainers = with lib.maintainers; [ |
| 15 | + khaneliman |
| 16 | + AndresBermeoMarinelli |
| 17 | + ]; |
| 18 | + |
| 19 | + settingsOptions = { |
| 20 | + keymaps = defaultNullOpts.mkAttrsOf types.str '' |
| 21 | + { |
| 22 | + insert = "<C-g>s"; |
| 23 | + insert_line = "<C-g>S"; |
| 24 | + normal = "ys"; |
| 25 | + normal_cur = "yss"; |
| 26 | + normal_line = "yS"; |
| 27 | + normal_cur_line = "ySS"; |
| 28 | + visual = "S"; |
| 29 | + visual_line = "gS"; |
| 30 | + delete = "ds"; |
| 31 | + change = "cs"; |
| 32 | + change_line = "cS"; |
| 33 | + } |
| 34 | + '' "Defines the keymaps used to perform surround actions."; |
| 35 | + |
| 36 | + aliases = defaultNullOpts.mkAttrsOf (with types; either str (listOf str)) '' |
| 37 | + { |
| 38 | + "a" = ">"; |
| 39 | + "b" = ")"; |
| 40 | + "B" = "}"; |
| 41 | + "r" = "]"; |
| 42 | + "q" = [ "\"" "'" "`" ]; |
| 43 | + "s" = [ "}" "]" ")" ">" "\"" "'" "`" ]; |
| 44 | + } |
| 45 | + '' "Maps characters to other characters, or lists of characters."; |
| 46 | + |
| 47 | + surrounds = |
| 48 | + let |
| 49 | + surroundType = types.submodule { |
| 50 | + options = { |
| 51 | + add = lib.mkOption { |
| 52 | + type = with types; either strLuaFn (listOf str); |
| 53 | + description = '' |
| 54 | + A function that returns the delimiter pair to be added to the buffer. |
| 55 | + For "static" delimiter pairs it can be a list of strings representing the value |
| 56 | + of the delimiter pair. |
| 57 | + ''; |
| 58 | + apply = v: if lib.isString v then lib.nixvim.mkRaw v else v; |
| 59 | + example = [ |
| 60 | + "( " |
| 61 | + " )" |
| 62 | + ]; |
| 63 | + }; |
| 64 | + find = lib.mkOption { |
| 65 | + type = with types; maybeRaw str; |
| 66 | + description = '' |
| 67 | + A function that returns the "parent selection" for a surrounding pair. |
| 68 | + It can also be string which is interpreted as a Lua pattern that represents the |
| 69 | + selection. |
| 70 | + ''; |
| 71 | + example.__raw = '' |
| 72 | + function() |
| 73 | + return M.get_selection({ motion = "a(" }) |
| 74 | + end |
| 75 | + ''; |
| 76 | + }; |
| 77 | + delete = lib.mkOption { |
| 78 | + type = with types; maybeRaw str; |
| 79 | + description = '' |
| 80 | + A function that returns the pair of selections to remove from the buffer when |
| 81 | + deleting the surrounding pair. |
| 82 | + It can also be string which is interpreted as a Lua pattern whose match groups |
| 83 | + represent the left/right delimiter pair. |
| 84 | + ''; |
| 85 | + example = "^(. ?)().-( ?.)()$"; |
| 86 | + }; |
| 87 | + |
| 88 | + change = lib.nixvim.mkNullOrOption (types.submodule { |
| 89 | + options = { |
| 90 | + target = lib.mkOption { |
| 91 | + type = with types; maybeRaw str; |
| 92 | + description = '' |
| 93 | + A function that returns the pair of selections to be replaced in the buffer |
| 94 | + when changing the surrounding pair. |
| 95 | + It can also be a string which is interpreted as a Lua pattern whose match |
| 96 | + groups represent the left/right delimiter pair. |
| 97 | + ''; |
| 98 | + example = "^<([^>]*)().-([^%/]*)()>$"; |
| 99 | + }; |
| 100 | + replacement = lib.mkOption { |
| 101 | + type = types.rawLua; |
| 102 | + description = '' |
| 103 | + A function that returns the surrounding pair to replace the target |
| 104 | + selections. |
| 105 | + ''; |
| 106 | + example.__raw = '' |
| 107 | + function() |
| 108 | + local result = M.get_input("Enter the function name: ") |
| 109 | + if result then |
| 110 | + return { { result }, { "" } } |
| 111 | + end |
| 112 | + end |
| 113 | + ''; |
| 114 | + }; |
| 115 | + }; |
| 116 | + }) "An attribute set with two keys: `target` and `replacement`."; |
| 117 | + }; |
| 118 | + }; |
| 119 | + in |
| 120 | + lib.nixvim.mkNullOrOption' { |
| 121 | + type = types.attrsOf surroundType; |
| 122 | + description = '' |
| 123 | + Associates each key with a "surround". The attribute set contains |
| 124 | + the 'add', 'find', 'delete', and 'change' keys. |
| 125 | + ''; |
| 126 | + pluginDefault = lib.literalMD "See [upstream default configuration](https://github.com/kylechui/nvim-surround/blob/main/lua/nvim-surround/config.lua)"; |
| 127 | + }; |
| 128 | + }; |
| 129 | +} |
0 commit comments