retrovim 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/.conda/retrovim.yaml +259 -0
  2. package/.conda/terax.icns +0 -0
  3. package/.conda/terax.ico +0 -0
  4. package/.conda/terax.png +0 -0
  5. package/.github/workflows/release.yml +95 -0
  6. package/.gitmodules +3 -0
  7. package/.npm/kanata_touchcursor.js +28 -0
  8. package/.npm/nvim.js +26 -0
  9. package/.npm/yazi.js +26 -0
  10. package/.npm/zsh.js +17 -0
  11. package/.pip/kanata_touchcursor/__init__.py +28 -0
  12. package/.pip/nvim/__init__.py +31 -0
  13. package/.pip/yazi/__init__.py +31 -0
  14. package/.pip/zsh/__init__.py +22 -0
  15. package/CHANGELOG.md +26 -0
  16. package/LICENSE +674 -0
  17. package/README.md +336 -0
  18. package/kanata/touchcursor.kbd +164 -0
  19. package/nvim/init.lua +813 -0
  20. package/nvim/plugins/mini.nvim/.github/DISCUSSION_TEMPLATE/q-a.yml +72 -0
  21. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/bug-report.yml +136 -0
  22. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/config.yml +5 -0
  23. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/feature-request.yml +75 -0
  24. package/nvim/plugins/mini.nvim/.github/PULL_REQUEST_TEMPLATE.md +2 -0
  25. package/nvim/plugins/mini.nvim/.github/workflows/quality-control.yml +150 -0
  26. package/nvim/plugins/mini.nvim/.pre-commit-config.yaml +20 -0
  27. package/nvim/plugins/mini.nvim/.stylua.toml +7 -0
  28. package/nvim/plugins/mini.nvim/.styluaignore +1 -0
  29. package/nvim/plugins/mini.nvim/CHANGELOG.md +1894 -0
  30. package/nvim/plugins/mini.nvim/CODE_OF_CONDUCT.md +132 -0
  31. package/nvim/plugins/mini.nvim/CONTRIBUTING.md +331 -0
  32. package/nvim/plugins/mini.nvim/LICENSE +21 -0
  33. package/nvim/plugins/mini.nvim/MAINTAINING.md +330 -0
  34. package/nvim/plugins/mini.nvim/Makefile +51 -0
  35. package/nvim/plugins/mini.nvim/README.md +261 -0
  36. package/nvim/plugins/mini.nvim/TESTING.md +1011 -0
  37. package/nvim/plugins/mini.nvim/benchmarks/starter/README.md +35 -0
  38. package/nvim/plugins/mini.nvim/benchmarks/starter/benchmark.sh +56 -0
  39. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-alpha.lua +21 -0
  40. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-original.lua +17 -0
  41. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-starter.lua +18 -0
  42. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_empty.lua +4 -0
  43. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_starter-default.lua +7 -0
  44. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-alpha.lua +10 -0
  45. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-original.lua +7 -0
  46. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-starter.lua +20 -0
  47. package/nvim/plugins/mini.nvim/benchmarks/starter/install.sh +10 -0
  48. package/nvim/plugins/mini.nvim/benchmarks/starter/make_summary.py +68 -0
  49. package/nvim/plugins/mini.nvim/benchmarks/starter/startup-summary.md +10 -0
  50. package/nvim/plugins/mini.nvim/colors/miniautumn.lua +55 -0
  51. package/nvim/plugins/mini.nvim/colors/minicyan.lua +95 -0
  52. package/nvim/plugins/mini.nvim/colors/minischeme.lua +95 -0
  53. package/nvim/plugins/mini.nvim/colors/minispring.lua +53 -0
  54. package/nvim/plugins/mini.nvim/colors/minisummer.lua +49 -0
  55. package/nvim/plugins/mini.nvim/colors/miniwinter.lua +51 -0
  56. package/nvim/plugins/mini.nvim/colors/randomhue.lua +16 -0
  57. package/nvim/plugins/mini.nvim/doc/mini-ai.txt +889 -0
  58. package/nvim/plugins/mini.nvim/doc/mini-align.txt +923 -0
  59. package/nvim/plugins/mini.nvim/doc/mini-animate.txt +937 -0
  60. package/nvim/plugins/mini.nvim/doc/mini-base16.txt +285 -0
  61. package/nvim/plugins/mini.nvim/doc/mini-basics.txt +359 -0
  62. package/nvim/plugins/mini.nvim/doc/mini-bracketed.txt +622 -0
  63. package/nvim/plugins/mini.nvim/doc/mini-bufremove.txt +123 -0
  64. package/nvim/plugins/mini.nvim/doc/mini-clue.txt +760 -0
  65. package/nvim/plugins/mini.nvim/doc/mini-cmdline.txt +392 -0
  66. package/nvim/plugins/mini.nvim/doc/mini-colors.txt +880 -0
  67. package/nvim/plugins/mini.nvim/doc/mini-comment.txt +230 -0
  68. package/nvim/plugins/mini.nvim/doc/mini-completion.txt +477 -0
  69. package/nvim/plugins/mini.nvim/doc/mini-cursorword.txt +105 -0
  70. package/nvim/plugins/mini.nvim/doc/mini-deps.txt +590 -0
  71. package/nvim/plugins/mini.nvim/doc/mini-diff.txt +661 -0
  72. package/nvim/plugins/mini.nvim/doc/mini-doc.txt +434 -0
  73. package/nvim/plugins/mini.nvim/doc/mini-extra.txt +856 -0
  74. package/nvim/plugins/mini.nvim/doc/mini-files.txt +1018 -0
  75. package/nvim/plugins/mini.nvim/doc/mini-fuzzy.txt +160 -0
  76. package/nvim/plugins/mini.nvim/doc/mini-git.txt +425 -0
  77. package/nvim/plugins/mini.nvim/doc/mini-hipatterns.txt +489 -0
  78. package/nvim/plugins/mini.nvim/doc/mini-hues.txt +420 -0
  79. package/nvim/plugins/mini.nvim/doc/mini-icons.txt +508 -0
  80. package/nvim/plugins/mini.nvim/doc/mini-indentscope.txt +485 -0
  81. package/nvim/plugins/mini.nvim/doc/mini-input.txt +932 -0
  82. package/nvim/plugins/mini.nvim/doc/mini-jump.txt +202 -0
  83. package/nvim/plugins/mini.nvim/doc/mini-jump2d.txt +525 -0
  84. package/nvim/plugins/mini.nvim/doc/mini-keymap.txt +449 -0
  85. package/nvim/plugins/mini.nvim/doc/mini-map.txt +717 -0
  86. package/nvim/plugins/mini.nvim/doc/mini-misc.txt +431 -0
  87. package/nvim/plugins/mini.nvim/doc/mini-move.txt +181 -0
  88. package/nvim/plugins/mini.nvim/doc/mini-notify.txt +434 -0
  89. package/nvim/plugins/mini.nvim/doc/mini-nvim.txt +431 -0
  90. package/nvim/plugins/mini.nvim/doc/mini-operators.txt +472 -0
  91. package/nvim/plugins/mini.nvim/doc/mini-pairs.txt +346 -0
  92. package/nvim/plugins/mini.nvim/doc/mini-pick.txt +1535 -0
  93. package/nvim/plugins/mini.nvim/doc/mini-sessions.txt +239 -0
  94. package/nvim/plugins/mini.nvim/doc/mini-snippets.txt +1291 -0
  95. package/nvim/plugins/mini.nvim/doc/mini-splitjoin.txt +536 -0
  96. package/nvim/plugins/mini.nvim/doc/mini-starter.txt +618 -0
  97. package/nvim/plugins/mini.nvim/doc/mini-statusline.txt +361 -0
  98. package/nvim/plugins/mini.nvim/doc/mini-surround.txt +863 -0
  99. package/nvim/plugins/mini.nvim/doc/mini-tabline.txt +151 -0
  100. package/nvim/plugins/mini.nvim/doc/mini-test.txt +966 -0
  101. package/nvim/plugins/mini.nvim/doc/mini-trailspace.txt +91 -0
  102. package/nvim/plugins/mini.nvim/doc/mini-visits.txt +937 -0
  103. package/nvim/plugins/mini.nvim/logo.png +0 -0
  104. package/nvim/plugins/mini.nvim/lua/mini/ai.lua +2244 -0
  105. package/nvim/plugins/mini.nvim/lua/mini/align.lua +2076 -0
  106. package/nvim/plugins/mini.nvim/lua/mini/animate.lua +2127 -0
  107. package/nvim/plugins/mini.nvim/lua/mini/base16.lua +1752 -0
  108. package/nvim/plugins/mini.nvim/lua/mini/basics.lua +772 -0
  109. package/nvim/plugins/mini.nvim/lua/mini/bracketed.lua +2013 -0
  110. package/nvim/plugins/mini.nvim/lua/mini/bufremove.lua +283 -0
  111. package/nvim/plugins/mini.nvim/lua/mini/clue.lua +2096 -0
  112. package/nvim/plugins/mini.nvim/lua/mini/cmdline.lua +1182 -0
  113. package/nvim/plugins/mini.nvim/lua/mini/colors.lua +2483 -0
  114. package/nvim/plugins/mini.nvim/lua/mini/comment.lua +586 -0
  115. package/nvim/plugins/mini.nvim/lua/mini/completion.lua +2094 -0
  116. package/nvim/plugins/mini.nvim/lua/mini/cursorword.lua +311 -0
  117. package/nvim/plugins/mini.nvim/lua/mini/deps.lua +1660 -0
  118. package/nvim/plugins/mini.nvim/lua/mini/diff.lua +1938 -0
  119. package/nvim/plugins/mini.nvim/lua/mini/doc.lua +1371 -0
  120. package/nvim/plugins/mini.nvim/lua/mini/extra.lua +2290 -0
  121. package/nvim/plugins/mini.nvim/lua/mini/files.lua +3145 -0
  122. package/nvim/plugins/mini.nvim/lua/mini/fuzzy.lua +356 -0
  123. package/nvim/plugins/mini.nvim/lua/mini/git.lua +1737 -0
  124. package/nvim/plugins/mini.nvim/lua/mini/hipatterns.lua +1042 -0
  125. package/nvim/plugins/mini.nvim/lua/mini/hues.lua +2088 -0
  126. package/nvim/plugins/mini.nvim/lua/mini/icons.lua +2254 -0
  127. package/nvim/plugins/mini.nvim/lua/mini/indentscope.lua +1158 -0
  128. package/nvim/plugins/mini.nvim/lua/mini/init.lua +427 -0
  129. package/nvim/plugins/mini.nvim/lua/mini/input.lua +2183 -0
  130. package/nvim/plugins/mini.nvim/lua/mini/jump.lua +609 -0
  131. package/nvim/plugins/mini.nvim/lua/mini/jump2d.lua +1244 -0
  132. package/nvim/plugins/mini.nvim/lua/mini/keymap.lua +880 -0
  133. package/nvim/plugins/mini.nvim/lua/mini/map.lua +1709 -0
  134. package/nvim/plugins/mini.nvim/lua/mini/misc.lua +969 -0
  135. package/nvim/plugins/mini.nvim/lua/mini/move.lua +509 -0
  136. package/nvim/plugins/mini.nvim/lua/mini/notify.lua +938 -0
  137. package/nvim/plugins/mini.nvim/lua/mini/operators.lua +1349 -0
  138. package/nvim/plugins/mini.nvim/lua/mini/pairs.lua +657 -0
  139. package/nvim/plugins/mini.nvim/lua/mini/pick.lua +3876 -0
  140. package/nvim/plugins/mini.nvim/lua/mini/sessions.lua +689 -0
  141. package/nvim/plugins/mini.nvim/lua/mini/snippets.lua +2828 -0
  142. package/nvim/plugins/mini.nvim/lua/mini/splitjoin.lua +1132 -0
  143. package/nvim/plugins/mini.nvim/lua/mini/starter.lua +1599 -0
  144. package/nvim/plugins/mini.nvim/lua/mini/statusline.lua +686 -0
  145. package/nvim/plugins/mini.nvim/lua/mini/surround.lua +2388 -0
  146. package/nvim/plugins/mini.nvim/lua/mini/tabline.lua +564 -0
  147. package/nvim/plugins/mini.nvim/lua/mini/test.lua +2516 -0
  148. package/nvim/plugins/mini.nvim/lua/mini/trailspace.lua +215 -0
  149. package/nvim/plugins/mini.nvim/lua/mini/visits.lua +1577 -0
  150. package/nvim/plugins/mini.nvim/readmes/mini-ai.md +190 -0
  151. package/nvim/plugins/mini.nvim/readmes/mini-align.md +203 -0
  152. package/nvim/plugins/mini.nvim/readmes/mini-animate.md +214 -0
  153. package/nvim/plugins/mini.nvim/readmes/mini-base16.md +198 -0
  154. package/nvim/plugins/mini.nvim/readmes/mini-basics.md +184 -0
  155. package/nvim/plugins/mini.nvim/readmes/mini-bracketed.md +193 -0
  156. package/nvim/plugins/mini.nvim/readmes/mini-bufremove.md +139 -0
  157. package/nvim/plugins/mini.nvim/readmes/mini-clue.md +260 -0
  158. package/nvim/plugins/mini.nvim/readmes/mini-cmdline.md +183 -0
  159. package/nvim/plugins/mini.nvim/readmes/mini-colors.md +169 -0
  160. package/nvim/plugins/mini.nvim/readmes/mini-comment.md +183 -0
  161. package/nvim/plugins/mini.nvim/readmes/mini-completion.md +217 -0
  162. package/nvim/plugins/mini.nvim/readmes/mini-cursorword.md +137 -0
  163. package/nvim/plugins/mini.nvim/readmes/mini-deps.md +271 -0
  164. package/nvim/plugins/mini.nvim/readmes/mini-diff.md +289 -0
  165. package/nvim/plugins/mini.nvim/readmes/mini-doc.md +198 -0
  166. package/nvim/plugins/mini.nvim/readmes/mini-extra.md +158 -0
  167. package/nvim/plugins/mini.nvim/readmes/mini-files.md +247 -0
  168. package/nvim/plugins/mini.nvim/readmes/mini-fuzzy.md +134 -0
  169. package/nvim/plugins/mini.nvim/readmes/mini-git.md +168 -0
  170. package/nvim/plugins/mini.nvim/readmes/mini-hipatterns.md +176 -0
  171. package/nvim/plugins/mini.nvim/readmes/mini-hues.md +285 -0
  172. package/nvim/plugins/mini.nvim/readmes/mini-icons.md +183 -0
  173. package/nvim/plugins/mini.nvim/readmes/mini-indentscope.md +191 -0
  174. package/nvim/plugins/mini.nvim/readmes/mini-input.md +163 -0
  175. package/nvim/plugins/mini.nvim/readmes/mini-jump.md +161 -0
  176. package/nvim/plugins/mini.nvim/readmes/mini-jump2d.md +197 -0
  177. package/nvim/plugins/mini.nvim/readmes/mini-keymap.md +205 -0
  178. package/nvim/plugins/mini.nvim/readmes/mini-map.md +191 -0
  179. package/nvim/plugins/mini.nvim/readmes/mini-misc.md +145 -0
  180. package/nvim/plugins/mini.nvim/readmes/mini-move.md +163 -0
  181. package/nvim/plugins/mini.nvim/readmes/mini-notify.md +175 -0
  182. package/nvim/plugins/mini.nvim/readmes/mini-operators.md +193 -0
  183. package/nvim/plugins/mini.nvim/readmes/mini-pairs.md +158 -0
  184. package/nvim/plugins/mini.nvim/readmes/mini-pick.md +340 -0
  185. package/nvim/plugins/mini.nvim/readmes/mini-sessions.md +164 -0
  186. package/nvim/plugins/mini.nvim/readmes/mini-snippets.md +373 -0
  187. package/nvim/plugins/mini.nvim/readmes/mini-splitjoin.md +194 -0
  188. package/nvim/plugins/mini.nvim/readmes/mini-starter.md +176 -0
  189. package/nvim/plugins/mini.nvim/readmes/mini-statusline.md +155 -0
  190. package/nvim/plugins/mini.nvim/readmes/mini-surround.md +190 -0
  191. package/nvim/plugins/mini.nvim/readmes/mini-tabline.md +156 -0
  192. package/nvim/plugins/mini.nvim/readmes/mini-test.md +175 -0
  193. package/nvim/plugins/mini.nvim/readmes/mini-trailspace.md +137 -0
  194. package/nvim/plugins/mini.nvim/readmes/mini-visits.md +243 -0
  195. package/nvim/plugins/mini.nvim/scripts/dual_log.sh +13 -0
  196. package/nvim/plugins/mini.nvim/scripts/dual_push.sh +15 -0
  197. package/nvim/plugins/mini.nvim/scripts/dual_release.sh +102 -0
  198. package/nvim/plugins/mini.nvim/scripts/dual_sync.sh +115 -0
  199. package/nvim/plugins/mini.nvim/scripts/init-deps-example.lua +59 -0
  200. package/nvim/plugins/mini.nvim/scripts/lint-filename-length.sh +16 -0
  201. package/nvim/plugins/mini.nvim/scripts/lintcommit-ci.sh +18 -0
  202. package/nvim/plugins/mini.nvim/scripts/lintcommit.lua +393 -0
  203. package/nvim/plugins/mini.nvim/scripts/minidoc.lua +57 -0
  204. package/nvim/plugins/mini.nvim/scripts/minimal_init.lua +28 -0
  205. package/nvim/plugins/mini.nvim/scripts/minitest.lua +4 -0
  206. package/package.json +16 -0
  207. package/pyproject.toml +43 -0
  208. package/yazi/init.lua +12 -0
  209. package/yazi/keymap.toml +114 -0
  210. package/yazi/lesskey +5 -0
  211. package/yazi/plugins/bookmarks.yazi/main.lua +86 -0
  212. package/yazi/plugins/cd-git-root.yazi/main.lua +31 -0
  213. package/yazi/plugins/smart-enter.yazi/main.lua +11 -0
  214. package/yazi/theme.toml +26 -0
  215. package/yazi/yazi.toml +15 -0
  216. package/zsh/.zshrc +145 -0
  217. package/zsh/starship.toml +20 -0
  218. package/zsh/zsh-patina.toml +2 -0
@@ -0,0 +1,657 @@
1
+ --- *mini.pairs* Autopairs
2
+ ---
3
+ --- MIT License Copyright (c) 2021 Evgeni Chasnovski
4
+
5
+ --- Features:
6
+ --- - Functionality to work with two "paired" characters conditional on cursor's
7
+ --- neighborhood (character to its left and character to its right).
8
+ ---
9
+ --- - Usage should be through making appropriate mappings using |MiniPairs.map()|
10
+ --- or in |MiniPairs.setup()| (for global mapping), |MiniPairs.map_buf()| (for
11
+ --- buffer mapping).
12
+ ---
13
+ --- - Pairs get automatically registered for special <BS> (all configured modes)
14
+ --- and <CR> (only Insert mode) mappings. Pressing the key inside pair will
15
+ --- delete whole pair and insert extra blank line inside pair respectively.
16
+ --- Note: these mappings are autocreated if they do not override existing ones.
17
+ ---
18
+ --- What it doesn't do:
19
+ --- - Provide smart behavior, like based on bracket balance. The default behavior
20
+ --- is to almost always perform an action (insert pair, jump over). Manually
21
+ --- press |i_CTRL-V| before a character to explicitly insert it (and only it).
22
+ ---
23
+ --- - It doesn't support multiple characters as "open" and "close" symbols. Use
24
+ --- snippets for that.
25
+ ---
26
+ --- - It doesn't support dependency on filetype. Use |i_CTRL-V| to insert
27
+ --- single symbol or `autocmd` command or `after/ftplugin` approach to:
28
+ --- - `:lua MiniPairs.map_buf(0, 'i', <*>, <pair_info>)` - make new mapping
29
+ --- for `<*>` in current buffer.
30
+ --- - `:lua MiniPairs.unmap_buf(0, 'i', <*>, <pair>)` - unmap key `<*>` while
31
+ --- unregistering `<pair>` pair in current buffer. Note: this reverts
32
+ --- mapping done by |MiniPairs.map_buf()|. If mapping was done with
33
+ --- |MiniPairs.map()|, unmap for buffer in usual Neovim manner:
34
+ --- `inoremap <buffer> <*> <*>` (this maps `<*>` key to do the same it
35
+ --- does by default).
36
+ --- - Disable module for buffer (see `# Disabling` section).
37
+ ---
38
+ --- # Setup ~
39
+ ---
40
+ --- This module needs a setup with `require('mini.pairs').setup({})`
41
+ --- (replace `{}` with your `config` table). It will create global Lua table
42
+ --- `MiniPairs` which you can use for scripting or manually (with
43
+ --- `:lua MiniPairs.*`).
44
+ ---
45
+ --- See |MiniPairs.config| for `config` structure and default values.
46
+ ---
47
+ --- This module doesn't have runtime options, so using `vim.b.minipairs_config`
48
+ --- will have no effect here.
49
+ ---
50
+ --- # Example mappings ~
51
+ --- >lua
52
+ --- -- Register quotes inside `config` of `MiniPairs.setup()`
53
+ --- mappings = {
54
+ --- ['"'] = { register = { cr = true } },
55
+ --- ["'"] = { register = { cr = true } },
56
+ --- }
57
+ ---
58
+ --- -- Insert `<>` pair if `<` is typed at line start, don't register for <CR>
59
+ --- local lt_opts = {
60
+ --- action = 'open',
61
+ --- pair = '<>',
62
+ --- neigh_pattern = '\r.',
63
+ --- register = { cr = false },
64
+ --- }
65
+ --- MiniPairs.map('i', '<', lt_opts)
66
+ ---
67
+ --- local gt_opts = { action = 'close', pair = '<>', register = { cr = false } }
68
+ --- MiniPairs.map('i', '>', gt_opts)
69
+ ---
70
+ --- -- Create symmetrical `$$` pair only in Tex files
71
+ --- local map_tex = function()
72
+ --- MiniPairs.map_buf(0, 'i', '$', { action = 'closeopen', pair = '$$' })
73
+ --- end
74
+ --- vim.api.nvim_create_autocmd(
75
+ --- 'FileType',
76
+ --- { pattern = 'tex', callback = map_tex }
77
+ --- )
78
+ --- <
79
+ --- # Notes ~
80
+ ---
81
+ --- - Make sure to make proper mapping of <CR> in order to support completion
82
+ --- plugin of your choice:
83
+ --- - For |mini.completion| see its `# Helpful mappings` section.
84
+ --- - For current implementation of "hrsh7th/nvim-cmp" there is no need to
85
+ --- make custom mapping. You can use default setup, which will confirm
86
+ --- completion selection if popup is visible and expand pair otherwise.
87
+ --- - Having mapping in terminal mode can conflict with:
88
+ --- - Autopairing capabilities of interpretators (`ipython`, `radian`).
89
+ --- - Vim mode of terminal itself.
90
+ ---
91
+ --- # Disabling ~
92
+ ---
93
+ --- To disable, set `vim.g.minipairs_disable` (globally) or `vim.b.minipairs_disable`
94
+ --- (for a buffer) to `true`. Considering high number of different scenarios
95
+ --- and customization intentions, writing exact rules for disabling module's
96
+ --- functionality is left to user. See |mini.nvim-disabling-recipes| for common
97
+ --- recipes.
98
+ ---@tag MiniPairs
99
+
100
+ ---@alias __pairs_neigh_pattern string|nil Pattern for two neighborhood characters.
101
+ --- Character "\r" indicates line start, "\n" - line end.
102
+ ---@alias __pairs_pair string String with two characters representing pair.
103
+ ---@alias __pairs_unregistered_pair string Pair which should be unregistered from both <BS> and <CR>.
104
+ --- Should be explicitly supplied to avoid confusion.
105
+ --- Supply `''` to not unregister pair.
106
+
107
+ -- Module definition ==========================================================
108
+ local MiniPairs = {}
109
+ local H = {}
110
+
111
+ --- Module setup
112
+ ---
113
+ ---@param config table|nil Module config table. See |MiniPairs.config|.
114
+ ---
115
+ ---@usage >lua
116
+ --- require('mini.pairs').setup() -- use default config
117
+ --- -- OR
118
+ --- require('mini.pairs').setup({}) -- replace {} with your config table
119
+ --- <
120
+ MiniPairs.setup = function(config)
121
+ -- TODO: Remove after Neovim=0.9 support is dropped
122
+ if vim.fn.has('nvim-0.10') == 0 then
123
+ vim.notify(
124
+ '(mini.pairs) Neovim<0.10 is soft deprecated (module works but is not supported).'
125
+ .. " It will be deprecated after the next 'mini.nvim' release (module might not work)."
126
+ .. ' Please update your Neovim version.'
127
+ )
128
+ end
129
+
130
+ -- Export module
131
+ _G.MiniPairs = MiniPairs
132
+
133
+ -- Setup config
134
+ config = H.setup_config(config)
135
+
136
+ -- Apply config
137
+ H.apply_config(config)
138
+
139
+ -- Define behavior
140
+ H.create_autocommands()
141
+ end
142
+
143
+ --stylua: ignore
144
+ --- Defaults ~
145
+ ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
146
+ MiniPairs.config = {
147
+ -- In which modes mappings from this `config` should be created
148
+ modes = { insert = true, command = false, terminal = false },
149
+
150
+ -- Global mappings. Each right hand side should be a pair information, a
151
+ -- table with at least these fields (see more in |MiniPairs.map()|):
152
+ -- - <action> - one of "open", "close", "closeopen".
153
+ -- - <pair> - two character string for pair to be used.
154
+ -- By default pair is not inserted after `\`, quotes are not recognized by
155
+ -- <CR>, `'` does not insert the pair after a letter.
156
+ -- Only parts of tables can be tweaked (others will use these defaults).
157
+ -- Supply `false` instead of table to not map particular key.
158
+ mappings = {
159
+ ['('] = { action = 'open', pair = '()', neigh_pattern = '^[^\\]' },
160
+ ['['] = { action = 'open', pair = '[]', neigh_pattern = '^[^\\]' },
161
+ ['{'] = { action = 'open', pair = '{}', neigh_pattern = '^[^\\]' },
162
+
163
+ [')'] = { action = 'close', pair = '()', neigh_pattern = '^[^\\]' },
164
+ [']'] = { action = 'close', pair = '[]', neigh_pattern = '^[^\\]' },
165
+ ['}'] = { action = 'close', pair = '{}', neigh_pattern = '^[^\\]' },
166
+
167
+ ['"'] = { action = 'closeopen', pair = '""', neigh_pattern = '^[^\\]', register = { cr = false } },
168
+ ["'"] = { action = 'closeopen', pair = "''", neigh_pattern = '^[^%a\\]', register = { cr = false } },
169
+ ['`'] = { action = 'closeopen', pair = '``', neigh_pattern = '^[^\\]', register = { cr = false } },
170
+ },
171
+ }
172
+ --minidoc_afterlines_end
173
+
174
+ -- Module functionality =======================================================
175
+ --- Make global mapping
176
+ ---
177
+ --- This is a wrapper for |nvim_set_keymap()| but instead of right hand side of
178
+ --- mapping (as string) it expects table with pair information.
179
+ ---
180
+ --- Using this function instead of |nvim_set_keymap()| allows automatic
181
+ --- registration of pairs which will be recognized by <BS> and <CR>.
182
+ --- It also infers mapping description from `pair_info`.
183
+ ---
184
+ ---@param mode string `mode` for |nvim_set_keymap()|.
185
+ ---@param lhs string `lhs` for |nvim_set_keymap()|.
186
+ ---@param pair_info table Table with pair information. Fields:
187
+ --- - <action> - one of "open" for |MiniPairs.open()|,
188
+ --- "close" for |MiniPairs.close()|, or "closeopen" for |MiniPairs.closeopen()|.
189
+ --- - <pair> - two character string to be passed to an action function.
190
+ --- Can contain multibyte characters.
191
+ --- - <neigh_pattern> - optional neighborhood pattern to be passed to an action
192
+ --- function. Will be matched against two character neighborhood (might
193
+ --- contain multibyte characters).
194
+ --- Default: `'..'` (no restriction from neighborhood).
195
+ --- - <register> - optional table with information about whether this pair will
196
+ --- be recognized by <BS> (in |MiniPairs.bs()|) and/or <CR> (in |MiniPairs.cr()|).
197
+ --- Should have boolean fields <bs> and <cr> (both `true` by default).
198
+ ---@param opts table|nil Optional table `opts` for |nvim_set_keymap()|. Elements
199
+ --- `expr` and `noremap` won't be recognized (`true` by default).
200
+ MiniPairs.map = function(mode, lhs, pair_info, opts)
201
+ pair_info = H.validate_pair_info(pair_info)
202
+ opts = vim.tbl_deep_extend('force', opts or {}, { expr = true, noremap = true })
203
+ opts.desc = H.infer_mapping_description(pair_info)
204
+
205
+ vim.api.nvim_set_keymap(mode, lhs, H.pair_info_to_map_rhs(pair_info), opts)
206
+ H.register_pair(pair_info, mode, 'all')
207
+
208
+ -- Ensure that <BS> and <CR> are mapped for input mode
209
+ H.ensure_cr_bs(mode)
210
+ end
211
+
212
+ --- Make buffer mapping
213
+ ---
214
+ --- This is a wrapper for |nvim_buf_set_keymap()| but instead of string right
215
+ --- hand side of mapping it expects table with pair information similar to one
216
+ --- in |MiniPairs.map()|.
217
+ ---
218
+ --- Using this function instead of |nvim_buf_set_keymap()| allows automatic
219
+ --- registration of pairs which will be recognized by <BS> and <CR>.
220
+ --- It also infers mapping description from `pair_info`.
221
+ ---
222
+ ---@param buffer number `buffer` for |nvim_buf_set_keymap()|.
223
+ ---@param mode string `mode` for |nvim_buf_set_keymap()|.
224
+ ---@param lhs string `lhs` for |nvim_buf_set_keymap()|.
225
+ ---@param pair_info table Table with pair information.
226
+ ---@param opts table|nil Optional table `opts` for |nvim_buf_set_keymap()|.
227
+ --- Elements `expr` and `noremap` won't be recognized (`true` by default).
228
+ MiniPairs.map_buf = function(buffer, mode, lhs, pair_info, opts)
229
+ pair_info = H.validate_pair_info(pair_info)
230
+ opts = vim.tbl_deep_extend('force', opts or {}, { expr = true, noremap = true })
231
+ opts.desc = H.infer_mapping_description(pair_info)
232
+
233
+ vim.api.nvim_buf_set_keymap(buffer, mode, lhs, H.pair_info_to_map_rhs(pair_info), opts)
234
+ H.register_pair(pair_info, mode, buffer == 0 and vim.api.nvim_get_current_buf() or buffer)
235
+
236
+ -- Ensure that <BS> and <CR> are mapped for input mode
237
+ H.ensure_cr_bs(mode)
238
+ end
239
+
240
+ --- Remove global mapping
241
+ ---
242
+ --- A wrapper for |nvim_del_keymap()| which registers supplied `pair`.
243
+ ---
244
+ ---@param mode string `mode` for |nvim_del_keymap()|.
245
+ ---@param lhs string `lhs` for |nvim_del_keymap()|.
246
+ ---@param pair __pairs_unregistered_pair
247
+ MiniPairs.unmap = function(mode, lhs, pair)
248
+ -- `pair` should be supplied explicitly
249
+ H.check_type('pair', pair, 'string')
250
+
251
+ -- Use `pcall` to allow 'deleting' already deleted mapping
252
+ pcall(vim.api.nvim_del_keymap, mode, lhs)
253
+ if pair == '' then return end
254
+ H.unregister_pair(pair, mode, 'all')
255
+ end
256
+
257
+ --- Remove buffer mapping
258
+ ---
259
+ --- Wrapper for |nvim_buf_del_keymap()| which also unregisters supplied `pair`.
260
+ ---
261
+ --- Note: this only reverts mapping done by |MiniPairs.map_buf()|. If mapping was
262
+ --- done with |MiniPairs.map()|, revert to default behavior for buffer: >lua
263
+ ---
264
+ --- -- Map `X` key to do the same it does by default
265
+ --- vim.keymap.set('i', 'X', 'X', { buffer = true })
266
+ --- <
267
+ ---@param buffer number `buffer` for |nvim_buf_del_keymap()|.
268
+ ---@param mode string `mode` for |nvim_buf_del_keymap()|.
269
+ ---@param lhs string `lhs` for |nvim_buf_del_keymap()|.
270
+ ---@param pair __pairs_unregistered_pair
271
+ MiniPairs.unmap_buf = function(buffer, mode, lhs, pair)
272
+ -- `pair` should be supplied explicitly
273
+ H.check_type('pair', pair, 'string')
274
+
275
+ -- Use `pcall` to allow 'deleting' already deleted mapping
276
+ pcall(vim.api.nvim_buf_del_keymap, buffer, mode, lhs)
277
+ if pair == '' then return end
278
+ H.unregister_pair(pair, mode, buffer == 0 and vim.api.nvim_get_current_buf() or buffer)
279
+ end
280
+
281
+ --- Process "open" symbols
282
+ ---
283
+ --- Used as |:map-<expr>| mapping for "open" symbols in asymmetric pair (`(`, `[`,
284
+ --- etc.). If neighborhood doesn't match supplied pattern, function results
285
+ --- into "open" symbol. Otherwise, it pastes whole pair and moves inside pair
286
+ --- with |<Left>|.
287
+ ---
288
+ --- Used inside |MiniPairs.map()| and |MiniPairs.map_buf()| for an actual mapping.
289
+ ---
290
+ ---@param pair __pairs_pair
291
+ ---@param neigh_pattern __pairs_neigh_pattern
292
+ ---
293
+ ---@return string Keys performing "open" action.
294
+ MiniPairs.open = function(pair, neigh_pattern)
295
+ if H.is_disabled() or not H.neigh_match(neigh_pattern) then return H.get_open_char(pair) end
296
+
297
+ -- Temporarily redraw lazily for no cursor flicker due to `<Left>`.
298
+ -- This can happen in a big file with tree-sitter highlighting enabled.
299
+ H.with_temp_option('lazyredraw', true)
300
+
301
+ -- NOTE: Do not ensure no wildmenu because by the time arrow is executed
302
+ -- wildmenu should already (usually) be hidden due to inserting `pair`
303
+ return pair .. H.get_arrow_key('left')
304
+ end
305
+
306
+ --- Process "close" symbols
307
+ ---
308
+ --- Used as |:map-<expr>| mapping for "close" symbols in asymmetric pair (`)`, `]`,
309
+ --- etc.). If neighborhood doesn't match supplied pattern, function results into
310
+ --- "close" symbol. Otherwise it jumps over symbol to the right of cursor
311
+ --- (with |<Right>|) if it is equal to "close" one and inserts it otherwise.
312
+ ---
313
+ --- Used inside |MiniPairs.map()| and |MiniPairs.map_buf()| for an actual mapping.
314
+ ---
315
+ ---@param pair __pairs_pair
316
+ ---@param neigh_pattern __pairs_neigh_pattern
317
+ ---
318
+ ---@return string Keys performing "close" action.
319
+ MiniPairs.close = function(pair, neigh_pattern)
320
+ local close = H.get_close_char(pair)
321
+ local move_right = not H.is_disabled() and H.neigh_match(neigh_pattern) and H.get_neigh('right') == close
322
+ return move_right and H.get_arrow_key('right', true) or close
323
+ end
324
+
325
+ --- Process "closeopen" symbols
326
+ ---
327
+ --- Used as |:map-<expr>| mapping for "symmetrical" symbols (like `"` and `'`)
328
+ --- It tries to perform "closeopen action": move over right character
329
+ --- (with |<Right>|) if it is equal to second character from pair or
330
+ --- conditionally paste pair otherwise (with |MiniPairs.open()|).
331
+ ---
332
+ --- Used inside |MiniPairs.map()| and |MiniPairs.map_buf()| for an actual mapping.
333
+ ---
334
+ ---@param pair __pairs_pair
335
+ ---@param neigh_pattern __pairs_neigh_pattern
336
+ ---
337
+ ---@return string Keys performing "closeopen" action.
338
+ MiniPairs.closeopen = function(pair, neigh_pattern)
339
+ local move_right = not H.is_disabled() and H.get_neigh('right') == H.get_close_char(pair)
340
+ return move_right and H.get_arrow_key('right', true) or MiniPairs.open(pair, neigh_pattern)
341
+ end
342
+
343
+ --- Process |<BS>|
344
+ ---
345
+ --- Used as |:map-<expr>| mapping for <BS> in Insert mode. It removes whole pair
346
+ --- (via executing <Del> after input key) if neighborhood is equal to a whole
347
+ --- pair recognized for current buffer. Pair is recognized for current buffer
348
+ --- if it is registered for global or current buffer mapping. Pair is
349
+ --- registered as a result of calling |MiniPairs.map()| or |MiniPairs.map_buf()|.
350
+ ---
351
+ --- Mapped by default inside |MiniPairs.setup()|.
352
+ ---
353
+ --- This can be used to modify other Insert mode keys to respect neighborhood
354
+ --- pair. Examples: >lua
355
+ ---
356
+ --- local map_bs = function(lhs, rhs)
357
+ --- vim.keymap.set('i', lhs, rhs, { expr = true, replace_keycodes = false })
358
+ --- end
359
+ ---
360
+ --- map_bs('<C-h>', 'v:lua.MiniPairs.bs()')
361
+ --- map_bs('<C-w>', 'v:lua.MiniPairs.bs("\23")')
362
+ --- map_bs('<C-u>', 'v:lua.MiniPairs.bs("\21")')
363
+ --- <
364
+ ---@param key string|nil Key to use. Default: `'<BS>'`.
365
+ ---
366
+ ---@return string Keys performing "backspace" action.
367
+ MiniPairs.bs = function(key)
368
+ local res, neigh = key or H.keys.bs, H.get_neigh('whole')
369
+ local do_extra = not H.is_disabled() and H.is_pair_registered(neigh, vim.fn.mode(), 'bs')
370
+ return do_extra and (res .. H.keys.del) or res
371
+ end
372
+
373
+ --- Process |i_<CR>|
374
+ ---
375
+ --- Used as |:map-<expr>| mapping for <CR> in insert mode. It puts "close"
376
+ --- symbol on next line (via `<CR><C-o>O`) if neighborhood is equal to a whole
377
+ --- pair recognized for current buffer. Pair is recognized for current buffer
378
+ --- if it is registered for global or current buffer mapping. Pair is
379
+ --- registered as a result of calling |MiniPairs.map()| or |MiniPairs.map_buf()|.
380
+ ---
381
+ --- Note: some relevant mode changing events are temporarily ignored
382
+ --- (with |'eventignore'|) to counter effect of using |i_CTRL-O|.
383
+ ---
384
+ --- Mapped by default inside |MiniPairs.setup()|.
385
+ ---
386
+ ---@param key string|nil Key to use. Default: `'<CR>'`.
387
+ ---
388
+ ---@return string Keys performing "new line" action.
389
+ MiniPairs.cr = function(key)
390
+ local res = key or H.keys.cr
391
+
392
+ local neigh = H.get_neigh('whole')
393
+ if H.is_disabled() or not H.is_pair_registered(neigh, vim.fn.mode(), 'cr') then return res end
394
+
395
+ -- Temporarily ignore mode change to not trigger some common expensive
396
+ -- autocommands (like diagnostic check, etc.)
397
+ H.with_temp_option('eventignore', 'InsertLeave,InsertLeavePre,InsertEnter,TextChanged,ModeChanged')
398
+
399
+ -- Temporarily redraw lazily for no cursor flicker due to `<C-o>O`.
400
+ -- This can happen in a big file with tree-sitter highlighting enabled.
401
+ H.with_temp_option('lazyredraw', true)
402
+
403
+ return res .. H.keys.above
404
+ end
405
+
406
+ -- Helper data ================================================================
407
+ -- Module default config
408
+ H.default_config = vim.deepcopy(MiniPairs.config)
409
+
410
+ -- Default value of `pair_info` for mapping functions
411
+ H.default_pair_info = { neigh_pattern = '..', register = { bs = true, cr = true } }
412
+
413
+ -- Pair sets registered *per mode-buffer-key*. Buffer `'all'` contains pairs
414
+ -- registered for all buffers.
415
+ H.registered_pairs = {
416
+ i = { all = { bs = {}, cr = {} } },
417
+ c = { all = { bs = {}, cr = {} } },
418
+ t = { all = { bs = {}, cr = {} } },
419
+ }
420
+
421
+ -- Precomputed keys to increase speed
422
+ -- stylua: ignore start
423
+ local function escape(s) return vim.api.nvim_replace_termcodes(s, true, true, true) end
424
+ H.keys = {
425
+ above = escape('<C-o>O'),
426
+ bs = escape('<BS>'),
427
+ cr = escape('<CR>'),
428
+ del = escape('<Del>'),
429
+ ctrl_y = escape('<C-y>'),
430
+ -- Using left/right keys in insert mode breaks undo sequence and, more
431
+ -- importantly, dot-repeat. To avoid this, use 'i_CTRL-G_U' mapping.
432
+ -- Use `H.get_arrow_key()` for keys instead of direct from this table.
433
+ left = escape('<Left>'),
434
+ right = escape('<Right>'),
435
+ left_undo = escape('<C-g>U<Left>'),
436
+ right_undo = escape('<C-g>U<Right>'),
437
+ }
438
+ -- stylua: ignore end
439
+
440
+ -- Cache for temporary set options
441
+ H.options_cache = {}
442
+
443
+ -- Helper functionality =======================================================
444
+ -- Settings -------------------------------------------------------------------
445
+ H.setup_config = function(config)
446
+ H.check_type('config', config, 'table', true)
447
+ config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})
448
+
449
+ H.check_type('modes', config.modes, 'table')
450
+ H.check_type('modes.insert', config.modes.insert, 'boolean')
451
+ H.check_type('modes.command', config.modes.command, 'boolean')
452
+ H.check_type('modes.terminal', config.modes.terminal, 'boolean')
453
+
454
+ H.check_type('mappings', config.mappings, 'table')
455
+
456
+ local validate_mapping = function(pair_info, prefix)
457
+ -- Allow `false` to not create mapping
458
+ if pair_info == false then return end
459
+ H.validate_pair_info(pair_info, prefix)
460
+ end
461
+
462
+ validate_mapping(config.mappings['('], "mappings['(']")
463
+ validate_mapping(config.mappings['['], "mappings['[']")
464
+ validate_mapping(config.mappings['{'], "mappings['{']")
465
+ validate_mapping(config.mappings[')'], "mappings[')']")
466
+ validate_mapping(config.mappings[']'], "mappings[']']")
467
+ validate_mapping(config.mappings['}'], "mappings['}']")
468
+ validate_mapping(config.mappings['"'], "mappings['\"']")
469
+ validate_mapping(config.mappings["'"], 'mappings["\'"]')
470
+ validate_mapping(config.mappings['`'], "mappings['`']")
471
+
472
+ return config
473
+ end
474
+
475
+ H.apply_config = function(config)
476
+ MiniPairs.config = config
477
+
478
+ -- Setup mappings in supplied modes
479
+ local mode_ids = { insert = 'i', command = 'c', terminal = 't' }
480
+ -- Compute in which modes mapping should be set up
481
+ local mode_array = {}
482
+ for name, to_set in pairs(config.modes) do
483
+ if to_set then table.insert(mode_array, mode_ids[name]) end
484
+ end
485
+
486
+ local map_conditionally = function(mode, key, pair_info)
487
+ -- Allow `false` to not create mapping
488
+ if pair_info == false then return end
489
+
490
+ -- This also should take care of mapping <BS> and <CR>
491
+ MiniPairs.map(mode, key, pair_info)
492
+ end
493
+
494
+ for _, mode in pairs(mode_array) do
495
+ for key, pair_info in pairs(config.mappings) do
496
+ map_conditionally(mode, key, pair_info)
497
+ end
498
+ end
499
+ end
500
+
501
+ H.create_autocommands = function()
502
+ local gr = vim.api.nvim_create_augroup('MiniPairs', {})
503
+
504
+ local au = function(event, pattern, callback, desc)
505
+ vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc })
506
+ end
507
+
508
+ au('FileType', { 'TelescopePrompt', 'fzf' }, function() vim.b.minipairs_disable = true end, 'Disable locally')
509
+ end
510
+
511
+ H.is_disabled = function() return vim.g.minipairs_disable == true or vim.b.minipairs_disable == true end
512
+
513
+ -- Pair registration ----------------------------------------------------------
514
+ H.register_pair = function(pair_info, mode, buffer)
515
+ -- Process new mode
516
+ H.registered_pairs[mode] = H.registered_pairs[mode] or { all = { bs = {}, cr = {} } }
517
+ local mode_pairs = H.registered_pairs[mode]
518
+
519
+ -- Process new buffer
520
+ local buf_pairs = mode_pairs[buffer] or { bs = {}, cr = {} }
521
+ mode_pairs[buffer] = buf_pairs
522
+
523
+ -- Register pair in a buffer or 'all'. NOTE: ensure to add entry only if
524
+ -- `register[key]` is `true` for a faster check in `is_pair_registered`.
525
+ local register, pair = pair_info.register, pair_info.pair
526
+ buf_pairs.bs[pair] = register.bs == true and true or nil
527
+ buf_pairs.cr[pair] = register.cr == true and true or nil
528
+ end
529
+
530
+ H.unregister_pair = function(pair, mode, buffer)
531
+ local mode_pairs = H.registered_pairs[mode]
532
+ if not (mode_pairs and mode_pairs[buffer]) then return end
533
+
534
+ local buf_pairs = mode_pairs[buffer]
535
+ buf_pairs.bs[pair], buf_pairs.cr[pair] = nil, nil
536
+ end
537
+
538
+ H.is_pair_registered = function(pair, mode, key)
539
+ local mode_pairs = H.registered_pairs[mode]
540
+ if not mode_pairs then return false end
541
+
542
+ if mode_pairs['all'][key][pair] then return true end
543
+
544
+ local buf_pairs = mode_pairs[vim.api.nvim_get_current_buf()]
545
+ if not buf_pairs then return false end
546
+
547
+ return buf_pairs[key][pair] == true
548
+ end
549
+
550
+ H.ensure_cr_bs = function(mode)
551
+ local has_any_cr_pair, has_any_bs_pair = false, false
552
+ for _, pair_tbl in pairs(H.registered_pairs[mode]) do
553
+ has_any_cr_pair = has_any_cr_pair or not vim.tbl_isempty(pair_tbl.cr)
554
+ has_any_bs_pair = has_any_bs_pair or not vim.tbl_isempty(pair_tbl.bs)
555
+ end
556
+
557
+ -- NOTE: this doesn't distinguish between global and buffer mappings. Both
558
+ -- <BS> and <CR> should work as normal even if no pairs are registered
559
+ -- NOTE: do not autocreate mappings if there is already one present. This
560
+ -- allows creating more complicated `<CR>`/`<BS>` mappings and not worry
561
+ -- about the initialization/setup order.
562
+ if has_any_bs_pair and vim.fn.maparg('<BS>', mode) == '' then
563
+ -- Use not `silent` in Command mode to make it redraw
564
+ local opts = { silent = mode ~= 'c', expr = true, replace_keycodes = false, desc = 'MiniPairs <BS>' }
565
+ H.map(mode, '<BS>', 'v:lua.MiniPairs.bs()', opts)
566
+ end
567
+ if mode == 'i' and has_any_cr_pair and vim.fn.maparg('<CR>', mode) == '' then
568
+ local opts = { expr = true, replace_keycodes = false, desc = 'MiniPairs <CR>' }
569
+ H.map(mode, '<CR>', 'v:lua.MiniPairs.cr()', opts)
570
+ end
571
+ end
572
+
573
+ -- Work with pair_info --------------------------------------------------------
574
+ H.validate_pair_info = function(x, prefix)
575
+ prefix = prefix or 'pair_info'
576
+ H.check_type(prefix, x, 'table')
577
+ x = vim.tbl_deep_extend('force', H.default_pair_info, x)
578
+
579
+ H.check_type(prefix .. '.action', x.action, 'string')
580
+ H.check_type(prefix .. '.pair', x.pair, 'string')
581
+ H.check_type(prefix .. '.neigh_pattern', x.neigh_pattern, 'string')
582
+ H.check_type(prefix .. '.register', x.register, 'table')
583
+
584
+ H.check_type(prefix .. '.register.bs', x.register.bs, 'boolean')
585
+ H.check_type(prefix .. '.register.cr', x.register.cr, 'boolean')
586
+
587
+ return x
588
+ end
589
+
590
+ H.pair_info_to_map_rhs = function(x)
591
+ return string.format('v:lua.MiniPairs.%s(%s, %s)', x.action, vim.inspect(x.pair), vim.inspect(x.neigh_pattern))
592
+ end
593
+
594
+ H.infer_mapping_description = function(x)
595
+ local action_name = x.action:sub(1, 1):upper() .. x.action:sub(2)
596
+ return string.format('%s action for %s pair', action_name, vim.inspect(x.pair))
597
+ end
598
+
599
+ -- Utilities ------------------------------------------------------------------
600
+ H.error = function(msg) error('(mini.pairs) ' .. msg, 0) end
601
+
602
+ H.check_type = function(name, val, ref, allow_nil)
603
+ if type(val) == ref or (ref == 'callable' and vim.is_callable(val)) or (allow_nil and val == nil) then return end
604
+ H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
605
+ end
606
+
607
+ H.get_neigh = function(neigh_type)
608
+ local is_command_mode = vim.fn.mode() == 'c'
609
+ -- Get line and add '\r' and '\n' to always return 2 characters
610
+ local line = is_command_mode and vim.fn.getcmdline() or vim.api.nvim_get_current_line()
611
+ line = '\r' .. line .. '\n'
612
+ -- Get start character index accounting for added '\r' at the start
613
+ local start = is_command_mode and vim.fn.charidx(line, vim.fn.getcmdpos()) or vim.fn.charcol('.')
614
+ start = start - 1
615
+
616
+ return vim.fn.strcharpart(line, start + (neigh_type == 'right' and 1 or 0), neigh_type == 'whole' and 2 or 1)
617
+ end
618
+
619
+ H.neigh_match = function(pattern) return H.get_neigh('whole'):find(pattern or '') ~= nil end
620
+
621
+ H.get_open_char = function(x) return vim.fn.strcharpart(x, 0, 1) end
622
+ H.get_close_char = function(x) return vim.fn.strcharpart(x, 1, 1) end
623
+
624
+ H.get_arrow_key = function(key, ensure_no_wildmenu)
625
+ if vim.fn.mode() == 'i' then
626
+ -- Take into account that `virtualedit=all` can go into inline virtual text
627
+ H.with_temp_option('virtualedit', 'none')
628
+ return key == 'right' and H.keys.right_undo or H.keys.left_undo
629
+ end
630
+ local prefix = ''
631
+ -- In Command-line mode <Left> / <Right> act like <C-p> / <C-n> if wildmenu
632
+ -- is shown. Make sure that arrow key moves cursor.
633
+ if vim.fn.mode() == 'c' and ensure_no_wildmenu then prefix = vim.fn.wildmenumode() == 1 and H.keys.ctrl_y or '' end
634
+ return prefix .. (key == 'right' and H.keys.right or H.keys.left)
635
+ end
636
+
637
+ H.map = function(mode, lhs, rhs, opts)
638
+ if lhs == '' then return end
639
+ opts = vim.tbl_deep_extend('force', { silent = true }, opts or {})
640
+ vim.keymap.set(mode, lhs, rhs, opts)
641
+ end
642
+
643
+ H.with_temp_option = function(name, value)
644
+ -- Cache option only once to not override it later with temporary set value
645
+ -- Like in case of `nvim_feedkeys('(\r(\r')`
646
+ if H.options_cache[name] == nil then H.options_cache[name] = vim.o[name] end
647
+ vim.o[name] = value
648
+ H.restore_option_later(name)
649
+ end
650
+
651
+ H.restore_option_later = vim.schedule_wrap(function(name)
652
+ if H.options_cache[name] == nil then return end
653
+ vim.o[name] = H.options_cache[name]
654
+ H.options_cache[name] = nil
655
+ end)
656
+
657
+ return MiniPairs